Compile and Install from Source on Ubuntu - A Guide

Compiling Software from Source on Linux
Linux distributions, including Ubuntu, offer vast package repositories designed to simplify software installation. These repositories generally eliminate the need for manual compilation. However, situations arise where you may need to compile an application from its source code.
This is often necessary when dealing with less common applications or when a desired version of a program isn't yet available through standard package managers.
The Basics of Source Compilation
Building software from source doesn't require advanced programming skills. A fundamental understanding of command-line operations is sufficient. The process can be mastered with a few key commands.
Successfully compiling from source allows users to install software tailored to their specific system configurations.
Steps Involved in Building from Source
- Obtain the Source Code: Typically, this involves downloading a compressed archive (like a .tar.gz or .tar.bz2 file) from the software's official website or a code repository.
- Extract the Archive: Use commands like
tar -xzvf filename.tar.gzortar -xjvf filename.tar.bz2to extract the contents. - Navigate to the Source Directory: Use the
cdcommand to enter the directory created after extraction. - Configure the Build: Run the
./configurescript. This script checks for dependencies and prepares the build environment. - Compile the Code: Execute the
makecommand to compile the source code into executable binaries. - Install the Software: Finally, use
sudo make installto install the compiled program to its appropriate location on your system.
Dependencies are crucial; the ./configure script will often report missing libraries or tools that need to be installed before compilation can proceed.
Remember to always check the software's documentation for specific build instructions, as these steps can vary slightly depending on the project.
Setting Up the Necessary Software
The build-essential package within Ubuntu’s software repositories facilitates the installation of fundamental tools required for compiling software directly from its source code. This includes the GCC compiler and a collection of related utilities.
Installation is achieved by executing the subsequent command within a terminal window:
sudo apt-get install build-essential
A confirmation prompt will appear during the process. Respond with 'Y' and press Enter to proceed with the installation.
This ensures that all the core components needed for compilation are readily available on your system.
Acquiring the Source Code Package
The initial step involves obtaining the source code for the application you wish to compile. These packages are commonly distributed as compressed archive files, typically utilizing the .tar.gz or .tar.bz2 extensions.
For demonstration purposes, let's consider the compilation of Pidgin from its source code. This might be necessary if a more recent version is available than what's currently packaged. Find the program’s .tar.gz or .tar.bz2 file and download it to your system.
A .tar.gz or .tar.bz2 archive functions similarly to a .zip file. Its contents must be extracted before they can be utilized.
To extract a .tar.gz file, employ the following command:
tar -xzvf file.tar.gz
Alternatively, to extract a .tar.bz2 file, use this command:
tar -xjvf file.tar.bz2
Following extraction, a new directory will be created, bearing the same name as the original source code package. Navigate into this directory using the cd command.
Addressing Software Dependencies
After navigating to the extracted application directory, execute the subsequent command:
./configure
It's important to note that not all applications utilize the ./configure script. Always consult the "README" or "INSTALL" file within the application's extracted folder for specific guidance.
The "./" prefix instructs the Bash shell to locate and execute the "configure" file within the current directory. Without it, Bash would search for "configure" in standard system directories such as /bin and /usr/bin.
The ./configure command performs a system check to identify the necessary software components required for building the program.
Typically, unless your system is already equipped with the required packages, you will encounter error messages. These messages indicate the need to install specific software dependencies.
For instance, the example shows an error related to missing intltool scripts. These can be installed using the following command:
sudo apt-get install intltool
Following the installation of the required software, re-run the ./configure command. Continue this iterative process – installing dependencies with sudo apt-get install – until ./configure completes without errors.
Be aware that the exact package names in error messages may not always directly correspond to the required packages. A web search using the error message can help determine the correct dependencies.
If the program you are attempting to compile is available in Ubuntu’s repositories, a shortcut is available. The sudo apt-get build-dep command can be used to automatically download and install all necessary dependencies.
For example, running sudo apt-get build-dep pidgin will install all packages needed to compile Pidgin. Observe that many of these packages will have a "-dev" suffix.
Once the ./configure command finishes successfully, you can proceed with compiling and installing the package.
Compilation and Installation Procedures
To compile the program, utilize the following command:
make
The duration of this process is contingent upon your system’s capabilities and the program’s size. Assuming the ./configure step was completed without errors, the 'make' command should execute seamlessly. Observe the scrolling text as the compilation progresses.

Upon completion of this command, the program will be successfully compiled. However, installation to the system is a separate step. Execute the following command to install the compiled program:
sudo make install
Typically, the installed files will reside within the /usr/local directory. Since /usr/local/bin is included in your system’s execution path, you can directly invoke the program – for example, pidgin – from the terminal without specifying its full path.

Should you wish to uninstall the program at a later time, and have retained the program’s directory, the following command can be used:
sudo make uninstall
Important Considerations
Software installed in this manner will not receive automatic updates through Ubuntu’s Update Manager, even if security vulnerabilities are discovered. Unless a specific application version is required that is unavailable through official Ubuntu repositories, utilizing the distribution’s packages is generally recommended.
Numerous advanced techniques exist beyond the scope of this guide. Nevertheless, it is hoped that the process of compiling software on Linux is now less daunting.
Linux Commands | ||
Files | tar · pv · cat · tac · chmod · grep · diff · sed · ar · man · pushd · popd · fsck · testdisk · seq · fd · pandoc · cd · $PATH · awk · join · jq · fold · uniq · journalctl · tail · stat · ls · fstab · echo · less · chgrp · chown · rev · look · strings · type · rename · zip · unzip · mount · umount · install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · vi · nano · mkdir · du · ln · patch · convert · rclone · shred · srm · scp · gzip · chattr · cut · find · umask · wc · tr | |
Processes | alias · screen · top · nice · renice · progress · strace · systemd · tmux · chsh · history · at · batch · free · which · dmesg · chfn · usermod · ps · chroot · xargs · tty · pinky · lsof · vmstat · timeout · wall · yes · kill · sleep · sudo · su · time · groupadd · usermod · groups · lshw · shutdown · reboot · halt · poweroff · passwd · lscpu · crontab · date · bg · fg · pidof · nohup · pmap | |
Networking | netstat · ping · traceroute · ip · ss · whois · fail2ban · bmon · dig · finger · nmap · ftp · curl · wget · who · whoami · w · iptables · ssh-keygen · ufw · arping · firewalld |
RELATED: Best Linux Laptops for Developers and Enthusiasts