Quick Links

Ubuntu and other Linux distributions have extensive package repositories to save you the trouble of compiling anything yourself. Still, sometimes you'll find an obscure application or a new version of a program that you'll have to compile from source.

You don't have to be a programmer to build a program from source and install it on your system; you only have to know the basics. With just a few commands, you can build from source like a pro.

Installing the Required Software

Installing the build-essential package in Ubuntu's package repositories automatically installs the basic software you'll need to compile from source, like the GCC compiler and other utilities. Install it by running the following command in a terminal:

sudo apt-get install build-essential

Type Y and press Enter to confirm installation when prompted.

Getting a Source Package

Now you'll need your desired application's source code. These packages are usually in compressed files with the .tar.gz or .tar.bz2 file extensions.

As an example, let's try compiling Pidgin from source -- maybe there's a newer version that hasn't been packaged yet and we want it now. Locate the program's .tar.gz or .tar.bz2 file and save it to your computer.

A .tar.gz or .tar.bz2 is like a .zip file. To use it, we'll have to extract its contents.

Use this command to extract a .tar.gz file:

tar -xzvf file.tar.gz

Or use this command to extract a .tar.bz2 file:

tar -xjvf file.tar.bz2

You'll end up with a directory with the same name as your source code package. Use the cd command to enter it.

Resolving Dependencies

Once you're in the extracted directory, run the following command:

./configure

(Note that some applications may not use ./configure. Check the "README" or "INSTALL" file in the application's extracted folder for more specific instructions.)

(The ./ part tells the Bash shell to look inside the current directory for the "configure" file and run it. If you omitted the ./, Bash would look for a program named "configure" in system directories like /bin and /usr/bin.)

The ./configure command checks your system for the required software needed to build the program.

Unless you're lucky (or already have a lot of required packages on your system), you'll receive error messages, indicating you'll need to install certain packages. Here, we see an error message saying the intltool scripts aren't present on their system. We can install them with the following command:

sudo apt-get install intltool

After installing the required software, run the ./configure command again. If you need to install additional software, repeat this process with the sudo apt-get install command until ./configure completes successfully. Not every required package will have the exact name you see in the error message -- you may need to Google the error message to determine the required packages.

If an older version of the program you're trying to compile is already in Ubuntu's software repositories, you can cheat with the sudo apt-get build-dep command. For example, if I run sudo apt-get build-dep pidgin, apt-get will automatically download and install all the dependencies I'll need to compile Pidgin. As you can see, many of the packages you'll need end in -dev.

Once ./configure completes successfully, you're ready to compile and install the package.

Compiling and Installing

Use the following command to compile the program:

make

This process may take some time, depending on your system and the size of the program. If ./configure completed successfully, make shouldn't have any problems. You'll see the lines of text scroll by as the program compiles.

After this command finishes, the program is successfully compiled -- but it's not installed. Use the following command to install it to your system:

sudo make install

It'll probably be stored under /usr/local on your system. /usr/local/bin is part of your system's path, which means we can just type "pidgin" into a terminal to launch Pidgin with no fuss.

Don't delete the program's directory if you want to install it later -- you can run the following command from the directory to uninstall the program from your system:

sudo make uninstall


Programs you install this way won't be automatically updated by Ubuntu's Update Manager, even if they contain security vulnerabilities. Unless you require a specific application or version that isn't in Ubuntu's software repositories, it's a good idea to stick with your distribution's official packages.

There are a lot of advanced tricks we haven't covered here -- but, hopefully, the process of compiling your own Linux software isn't as scary anymore.

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