Sometimes there is no package, or you need a newer version or a different build option. Then you can compile: turn the source code into a program yourself.
Get the tools
You need a compiler and make. Install the usual set with:
$ sudo apt install build-essential # Debian, Ubuntu
$ sudo dnf install gcc make # Fedora, RHELProjects often need libraries too, including their header files. Those packages usually end in -dev on Debian and -devel on Fedora.
Unpack and read
Get the source from the project's official site, and check the published checksum or signature if there is one.
$ tar -xf hello-2.12.tar.gz
$ cd hello-2.12
$ less READMERead README or INSTALL first. Not every project uses the steps below. Some use CMake, Meson or other build tools.
configure
Many projects ship a script named configure:
$ ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
config.status: creating MakefileIt inspects your system, checks for requirements and writes a Makefile. If it stops with an error, a tool or library is usually missing. The ./ runs the script in the current directory.
To choose where the program will be installed:
$ ./configure --prefix="$HOME/.local"make and make install
$ make
$ sudo make installmake reads the Makefile and builds the program inside the source directory. make install copies the results into place. The default for configure scripts of this kind is under /usr/local, which is why it needs sudo. With a prefix in your home directory, run make install without sudo.
Do not run ./configure or make as root. Building runs code from the project.
The cost
Your package manager does not know about files installed this way. It will not update them, so security fixes are your job. Some projects support:
$ sudo make uninstallKeep the configured source directory in case you need it. Tools such as checkinstall can wrap an install in a package, but support varies.
Try it
Build a tiny program of your own. Save this as hi.c:
#include <stdio.h>
int main(void) { puts("hi"); return 0; }Then run:
$ make hi
cc hi.c -o hi
$ ./hi
himake has a built-in rule for single C files, so no Makefile is needed here. For the packaged side of software, see the packages, disk and FHS lab.
Check your understanding
Compile Source Code
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.