How To Compile Software Packages On Linux
One of the hardest adjustments for users who switch from Windows to Linux is the idea that not every bit of software you want to install is ready-made for you. Unlike Windows users, who (in most cases) get software pre-packaged in an EXE installer or ZIP file, Linux users often have to compile their own software packages.
If you want to know how to compile software packages on Linux, you’ll need to follow a few steps. You’ll need to download the source code, run the configure command, install any required dependency packages, then run the make command to begin compiling your package. Here’s how to do all of this on a Linux-based operating system.
Downloading Source Files
Before you begin building your new software packages, you need the source code. This could be from a package that you’ve developed yourself, in which case you should have access to the source code already.
It’s more likely, however, that you’re attempting to compile a software package on Linux from another developer. Popular code sharing sites like Github allow you to view and download the source code for packages, which you can then compile. You can use GIT, the popular version control system, to download the source files to your PC.
You can also download the source code from open-source projects like VLC directly. These usually come in a compressed file format like TAR.GZ, which you can extract at the terminal using the tar command. For instance, running the command tar -xzvf source.tar.gz would extract a tarball file named source.tar.gz.
Once you have the source code available and extracted on your Linux PC, you can move to the next stage of preparation before you begin compiling your package.
Installing Build-Essential On Linux
The tools and software contained in the build-essential package are required for any kind of software compiling on Linux operating systems, regardless of the programming language of your source code.
As an essential package, build-essential (or similarly named packages) should be available in the software repository for your Linux distribution. The equivalent of build-essential on Arch Linux-based distributions is called base-devel, which includes many of the same tools.
The installation instructions for build-essential will also vary, depending on your Linux distribution. For example, on Ubuntu and Debian-based operating systems, you can install build-essential by opening a terminal window and typing sudo apt install build-essential.
Installing build-essential will also install its dependencies, like the g++ package. Once this process is complete, you can move onto configuring your Linux source package before compiling it.
Run The Configure Command
The source code for major packages usually contains a configure script. Running this script will check your Linux distribution for the essential packages that your source code needs to be able to compile correctly.
To run the configure script, enter the folder for your extracted source code using the cd command. From there, type ./configure into the terminal, pressing enter to run it.
If the configure script detects a missing package, it will inform you of what to do at the end of the script. For example, before compiling the VLC media player, the configure script shown running above has detected that the Lua programming language is not installed.
In some cases, you can still compile and configure software packages, even if the configure script has detected a missing package or feature. The configure script for VLC (shown above) has offered a solution to the missing Lua programming language packages by suggesting you run it again with the –disable-lua flag to bypass it.
You’ll need to install any missing packages that the configure script has detected or use any suggested disable flags to bypass these errors before you can continue.
If the configure script has completed with no (or only minor) errors, the configured makefile for your package will be created. This creates the instructions to compile your package, allowing you to move to the final software compiling stage.
Install Missing Dependency Packages
The configure script helpfully identifies any packages that your Linux distribution requires to be able to compile and install your new software package correctly.
These may be clearly identified by your configure script error message or further back through the process of running that script. If the error message hasn’t made it clear, scroll back through your terminal history to try and identify the missing package.
Once you know what the missing package is, use the package installer for your Linux distribution to install it. For instance, on Ubuntu and Debian-based operating systems, running sudo apt install package-name will install a package.
Installing any missing dependencies is the final stage you need to complete before you can begin compiling and installing your new software package. Once you’ve completed this process, you’re ready to begin compiling.
How to Compile on Linux
The build-essential package contains make, the automatic tool used to begin compiling your source code into software that you can run on your PC. It uses the makefile file, configured and created by the earlier configure command, which contains the specific instructions needed to compile your package.
To begin compiling your source code, open a terminal and use the cd command to enter the correct folder. When you’re ready, type make to begin compiling your package.
This will take a little bit of time to complete, depending on the size of the package and your available system resources. If no errors appear after your software package has been compiled, you can then install your package.
To do this, type sudo make install in the terminal. The package will be installed on your Linux PC, ready for you to open and use like any other software.
Installing New Software On Linux
Knowing how to compile software packages on Linux can help you install less commonly-known software. Major operating systems like Ubuntu and Devian have large software repositories available to users, so if you don’t want to compile your software, try finding and installing new software using the package manager instead.
If you’re moving from Windows, you can also install Windows software on Linux to keep using your favorite Windows-only apps.
Ben Stockton is a freelance technology writer based in the United Kingdom. In a past life, Ben was a college lecturer in the UK, training teens and adults. Since leaving the classroom, Ben has taken his teaching experience and applied it to writing tech how-to guides and tutorials, specialising in Linux, Windows, and Android. He has a degree in History and a postgraduate qualification in Computing. Read Ben’s Full Bio
Did you enjoy this tip? If so, check out our YouTube channel from our sister site Online Tech Tips. We cover Windows, Mac, software and apps, and have a bunch of troubleshooting tips and how-to videos. Click the button below to subscribe!