
A Complete Guide to Compiling and Installing Software from Source on Ubuntu
While Ubuntu’s Software Center and APT package manager offer a vast library of applications, there are times when you need software that isn’t available in the official repositories. You might need the absolute latest version of a program, a custom-configured build, or a niche tool that isn’t packaged for Ubuntu. In these cases, the solution is to compile and install the software directly from its source code.
This process gives you ultimate control but can seem intimidating at first. This guide will walk you through the entire workflow, from preparing your system to compiling and installing applications safely and efficiently.
Why Compile Software from Source? The Pros and Cons
Installing from source is a powerful technique, but it’s important to understand when it’s the right choice.
Advantages:
- Access to the Latest Versions: You can install bleeding-edge software releases as soon as they are available from developers, without waiting for them to be packaged for Ubuntu.
- Customization: You can enable or disable specific features during the configuration step, creating a build tailored precisely to your needs.
- Optimization: Advanced users can compile software with flags that optimize performance for their specific hardware architecture.
Disadvantages:
- Complexity: The process is more involved than a simple
sudo apt install. - Dependency Management: You are responsible for manually finding and installing any required libraries (dependencies) the software needs to build.
- No Automatic Updates: The system’s package manager will not be aware of the software, so you must manually track and install updates.
Step 1: Preparing Your System for Compilation
Before you can compile anything, you need to install the necessary tools. Ubuntu provides a convenient meta-package called build-essential that contains the core components for building software, including:
- GCC (GNU Compiler Collection): The compiler that turns human-readable source code into a machine-executable program.
- make: A utility that automates the build process based on instructions in a
Makefile. - Development Libraries: Essential headers and libraries needed to build common software.
To install this package, open your terminal and run the following command:
sudo apt update && sudo apt install build-essential
It’s also highly recommended to install checkinstall, a tool that creates a Debian package (.deb) from your compiled source. This makes managing and uninstalling the software much easier later.
sudo apt install checkinstall
Step 2: The Classic configure, make, install Workflow
This three-step process is the traditional method for compiling software on Linux.
A. Download and Extract the Source Code
First, find the official website or repository for the software you want to install. Look for a “Download” section that provides a source code tarball, usually a file ending in .tar.gz or .tar.bz2.
Use the wget command to download it directly from your terminal. For example:
wget http://example.com/software-1.2.3.tar.gz
Once downloaded, extract the archive using the tar command:
tar -xvf software-1.2.3.tar.gz
This will create a new directory containing the source code. Navigate into it:
cd software-1.2.3
B. The ./configure Script
Inside the source directory, you’ll almost always find a script named configure. Its job is to scan your system for all the required dependencies (libraries, compilers, etc.) and create a custom Makefile tailored to your environment.
Run the script:
./configure
This is the step where most errors occur. If you are missing a required library, the script will fail and tell you what is needed. For example, if it reports error: "zlib not found", you would need to install the development package for zlib, which is typically named zlib1g-dev. You can find it with apt-cache search zlib and install it with sudo apt install zlib1g-dev.
C. The make Command
If the ./configure script completes successfully, a Makefile has been generated. Now, you can run the make command to begin the actual compilation.
make
This process can take anywhere from a few seconds to many minutes, depending on the size of the software and the speed of your computer. For multi-core processors, you can speed this up by running multiple jobs in parallel. To use all available cores, run:
make -j$(nproc)
D. The sudo make install Command
After make finishes without errors, the final step is to install the compiled program into the system directories (like /usr/local/bin). This requires administrator privileges.
sudo make install
Your software should now be installed and available to run from the terminal. However, this method has a major drawback: your system’s package manager has no idea this software exists, making it very difficult to uninstall cleanly.
A Smarter and Safer Installation: Using checkinstall
Instead of sudo make install, it is much better to use the checkinstall utility. This tool runs the installation process but intercepts the files being copied and packages them into a standard .deb file first. It then installs this package using the system’s package manager.
After a successful make command, run this instead of sudo make install:
sudo checkinstall
checkinstall will ask you a few questions to describe the package. You can generally accept the defaults.
The benefits of this approach are significant:
- Easy Uninstallation: Because the software was installed as a package, you can remove it cleanly at any time using
dpkgorapt. For example:sudo dpkg -r software. - System Awareness: Your package manager is aware of the software, helping to prevent file conflicts with other packages.
- Portability: You can take the generated
.debfile and easily install the same compiled program on another machine with an identical configuration.
Security and Best Practices
- Only use trusted sources. Always download source code directly from the official developer’s website or a reputable version control platform like GitHub. Malicious code can be hidden in unofficial downloads.
- Read the
READMEfile. Most source code packages include aREADMEorINSTALLfile. This is the first place you should look for specific build instructions or dependencies. - Prefer development packages. When the
./configurescript reports a missing library, always install the version ending in-dev. For example, iflibcurlis missing, you need to installlibcurl4-openssl-dev, not justlibcurl4. The-devpackages contain the header files required for compilation.
By following this guide, you can confidently step outside the official repositories and build the exact software you need, all while keeping your system clean and manageable.
Source: https://kifarunix.com/how-to-install-programs-from-source-on-ubuntu-18-04/


