Compiling software from source on Linux gives you the latest features, custom optimizations, and full control over your installation. This guide walks you through the entire process, from installing build tools to running the final install command, so you can confidently build packages on any major distribution.
What You’ll Need
- A Linux system with an internet connection
- A terminal (Ctrl+Alt+T on most desktops)
- Build tools:
gcc,make, andbuild-essential(Debian/Ubuntu) orbase-devel(Arch) orDevelopment Toolsgroup (Fedora/RHEL) - The source code archive (usually
.tar.gzor.tar.xz) of the software you want to compile - Dependencies: libraries and headers required by the software (often listed in the README or INSTALL file)
Step-by-Step
- Install build tools. For Debian/Ubuntu, run
sudo apt update && sudo apt install build-essential. For Fedora, usesudo dnf groupinstall "Development Tools". For Arch, runsudo pacman -S base-devel. These provide the compiler, linker, and make utility. - Download the source code. Go to the official website of the software or its repository (e.g., GitHub) and download the source tarball. You can also use
wgetorcurldirectly in the terminal. - Extract the archive. Use
tar -xzf package.tar.gzfor gzip archives ortar -xJf package.tar.xzfor xz archives. This creates a new directory with the source files. - Enter the source directory. Run
cd package-directoryto move into the extracted folder. Always check the contents first withlsto see what files are present. - Read the documentation. Look for
README,INSTALL, orBUILDfiles. These contain critical instructions specific to that software, such as additional dependencies or configuration options. - Run
./configure. This script checks your system for required libraries, compilers, and settings. It creates aMakefiletailored to your system. You can pass options like--prefix=/usr/localto set the installation directory. If it fails, read the error message—it usually tells you which dependency is missing. - Run
make. This command compiles the source code into binary executables. The process can take a few minutes to an hour, depending on the software and your hardware. Usemake -j$(nproc)to speed it up by using all CPU cores. - Run
make test(optional but recommended). Many packages include a test suite that verifies the build is correct. Runmake testormake checkto execute these tests. - Install the software. Run
sudo make install. This copies the compiled binaries, libraries, and documentation to the system directories (e.g.,/usr/local/bin). This step requires root privileges. - Update the library cache (if needed). If the software installs shared libraries, run
sudo ldconfigto refresh the dynamic linker cache. - Verify the installation. Run the command name in the terminal (e.g.,
package --version) to confirm it works. If you installed to a custom prefix, you may need to add that directory to your PATH.
Common Mistakes
- Missing dependencies: The most common failure is a missing library or header file. The configure script will usually say what is missing. Install it with your package manager (e.g.,
sudo apt install libfoo-dev). - Using
sudofor configure/make: Running./configureormakeas root is unnecessary and can cause permission issues. Onlymake installneeds root. - Ignoring the prefix: Installing to the default prefix (
/usr/local) is fine, but if you choose a custom prefix, remember to adjust your PATH and library paths. - Not running
make cleanafter a failed build: If you change configuration options, runmake cleanbefore recompiling to remove old object files. - Forgetting to install
-devpackages: On Debian-based systems, you need the-devversions of libraries (e.g.,libssl-dev) to compile against them.
Tips
- Use
checkinstall(Debian/Ubuntu) to create a.debpackage from your compiled source, making it easier to uninstall later. - Keep a log of the configure options you used, so you can reproduce the build later.
- For large projects, use
make -j$(nproc)to significantly speed up compilation. - If the software has a Git repository, you can clone it and build the latest development version, but be aware it may be less stable.
- Consider using a package manager that supports building from source, like
makepkgon Arch, which automates the process.
Troubleshooting
Configure fails with “No such file or directory” – This usually means the configure script is not present or not executable. Check if the file exists with ls -l configure. If not, you may need to run autoreconf -i to generate it (requires autoconf).
Make fails with “command not found” – You are missing a compiler or utility. Install build-essential (Debian) or the equivalent on your distro.
Make fails with “undefined reference” errors – This indicates a missing library. The error message will name the symbol and often the library. Install the corresponding -dev package.
Configure says “C compiler cannot create executables” – Your compiler is broken or missing. Reinstall gcc and libc6-dev.
Install fails with “Permission denied” – You forgot sudo before make install.
Binary runs but says “cannot find shared libraries” – The library path is not set. Run sudo ldconfig or set LD_LIBRARY_PATH to include the install directory.
Frequently Asked Questions
Why compile from source instead of using the package manager?
Compiling gives you the latest version, custom compile-time options, and optimizations for your CPU. Package managers often provide older, generic builds.
How do I uninstall software installed from source?
If you kept the source directory, run sudo make uninstall from it. If not, you may need to manually delete files listed in install_manifest.txt (if generated) or use checkinstall to create a package.
Do I need to compile as root?
No. Only make install requires root. Compiling as root can cause permission issues and is a security risk.
What is the difference between make and make install?
make compiles the code into binaries in the source directory. make install copies those binaries and other files to system directories like /usr/local/bin.
How long does compilation take?
It varies widely: small utilities take seconds, while a full web browser or LibreOffice can take over an hour. Using -j$(nproc) helps.
Can I compile on any Linux distribution?
Yes, the process is the same, but the package names for build tools differ. Use your distribution’s package manager to install the equivalent of build-essential.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix 0x80070422 on Windows Server (Step-by-Step)
- Google Chrome Helper: What It Is & How to Disable
- How to Troubleshoot a Malfunctioning Driver on Windows
- How to Create Folders in Microsoft Outlook
- Fix Status Range List Conflict 0xc0000282 in Windows
- Fix Software Not Uninstalling on Windows 10