How to Install Software from Source Code
In this article
Installing software from source code means compiling the program on your own machine instead of using a prebuilt package. This gives you control over compile-time options, lets you run newer or customized versions, and works on systems where no package exists. The trade-off is that you manage dependencies and updates yourself. This guide covers the standard Unix-like workflow (Linux, macOS, and similar) using the classic ./configure && make && make install pattern, plus notes for projects that use CMake or Meson.
What You'll Need
- A terminal and basic command-line comfort (cd, ls, tar).
- A C/C++ compiler toolchain: on Debian/Ubuntu install
build-essential; on Fedoragcc gcc-c++ make; on macOS install the Xcode Command Line Tools withxcode-select --install. - The source archive (usually .tar.gz or .tar.xz) or a Git repository URL.
- Development headers for the libraries the program depends on (e.g.,
libssl-dev,zlib1g-dev). - Optional:
pkg-configto help the build find libraries. - Patience: compiling can take minutes to hours depending on the project and your CPU.
Step-by-Step
- Download and verify the source. Get the archive from the project's official website or its official repository. If checksums or signatures are published, verify them (e.g.,
sha256sum file.tar.gz) before extracting. This confirms the download is intact and authentic. - Extract the archive. Use
tar -xf file.tar.gz(ortar -xf file.tar.xz). Change into the newly created directory withcd. If you cloned a Git repo, you are already in the source directory. - Read the README and INSTALL files. Projects document their exact build steps there. The generic steps below work for many projects, but the README overrides them if it says something different.
- Run the configure script. For autotools projects, run
./configure. Add options as needed:--prefix=/usr/localsets the install location (the default is usually/usr/local), and--helplists all options. Configure checks for compilers and libraries and stops with an error if something is missing. For CMake projects, create a build directory, enter it, and runcmake ..(add-DCMAKE_INSTALL_PREFIX=/usr/localto change the install path). For Meson, runmeson setup buildthenmeson compile -C build. - Compile. Run
make(orcmake --build .in the build directory, or the Meson command above). This is the long step. If it fails, read the last error lines: they usually name a missing header or library. - Run the test suite (recommended). Many projects support
make checkormake test. Running it catches problems before installation. - Install. Run
sudo make install(orsudo cmake --install .). This copies binaries, libraries, and data files to the prefix you chose. On systems without sudo, usesuor install to a prefix inside your home directory (e.g.,--prefix=$HOME/.local) and add itsbinfolder to your PATH. - Refresh the linker cache and verify. On Linux, run
sudo ldconfigso the system finds newly installed shared libraries. Then run the program (e.g.,myprogram --version) to confirm it works. - Keep track of what you installed. Note the version, prefix, and any configure options. To uninstall, return to the source directory and run
sudo make uninstallif the project provides it; otherwise remove the files manually from the prefix.
Common Mistakes
- Skipping dependency headers. Installing a runtime library is not enough; you need the
-devor-develpackage that contains headers. Configure errors like "header not found" point to this. - Installing to /usr/local without checking PATH. Most systems include
/usr/local/binin PATH, but custom prefixes often do not. Add the prefix'sbindirectory to PATH in your shell profile. - Ignoring the README. Some projects need extra steps (e.g., running
autoreconf -iwhen building from Git rather than a release tarball). - Building as root. Only the install step needs elevated privileges. Compiling as root can leave root-owned build files and is unnecessary.
- Forgetting
ldconfig. Programs may fail to start with "library not found" until the linker cache is updated. - Mixing prefixes. Installing different versions to different prefixes can cause confusion. Pick one and stick to it, or use a package manager for isolation.
Tips
- Use
make -j$(nproc)on Linux ormake -j$(sysctl -n hw.ncpu)on macOS to compile in parallel and cut build time. - Keep a build log:
./configure ... 2>&1 | tee configure.logand similarly for make. Logs make troubleshooting much easier. - If you need to rebuild, run
make cleanfirst to remove old object files. - Prefer release tarballs over Git checkouts unless you need the latest code; release tarballs usually include generated configure scripts.
- For repeated installs, consider a package manager or a container instead of manual source builds.
Troubleshooting
If ./configure fails, read the last 20 lines of output. It typically names a missing program or library. Install the corresponding development package and rerun configure. If it complains about a compiler, confirm the toolchain is installed and on PATH.
If make fails, the error often points to a missing header file. Search your package manager for the header's package (e.g., on Debian, apt-file search header.h after installing apt-file). Also check that you are in the correct directory and that the source is complete.
If make install fails with permission errors, use sudo or choose a prefix you own. If it fails because a file already exists, you may have a conflicting installation; remove the old files or install to a different prefix.
If the program runs but cannot find a shared library, run ldconfig (Linux) or set LD_LIBRARY_PATH temporarily to the library directory. On macOS, you may need to set DYLD_LIBRARY_PATH or use install_name_tool; prefer installing to a standard prefix to avoid this.
If the build succeeds but the program behaves oddly, check that you are running the newly installed binary and not an older one earlier in PATH. Use which myprogram and myprogram --version to confirm.
Frequently Asked Questions
Do I need root access to install from source?
Only if you install to a system-wide prefix like /usr/local. You can install to a directory you own (e.g., $HOME/.local) without root and add its bin folder to PATH.
What is the difference between make and make install?
make compiles the source into binaries in the build directory. make install copies those binaries and supporting files to the chosen prefix so the system can use them.
Can I uninstall software installed from source?
Only if the project provides a make uninstall target or an install manifest. Otherwise you must delete the installed files manually, which is why noting the prefix and file list matters.
Why does configure say a library is missing when it is installed?
You likely have the runtime library but not the development package with headers. Install the -dev or -devel variant. Also ensure pkg-config can find it.
Is installing from source safer than using a package manager?
Not inherently. Package managers handle dependencies and updates automatically. Source builds give control but require you to track security updates yourself. Use official sources and verify checksums.
How do I update software I installed from source?
Download the new source, build it with the same prefix and options, and install over the old version. Check the project's release notes for any changed build steps.