Compiling Simple Programs
In the open source world, it is easy to compile software from source code. We are going to download the source code for the GNU
The download comes in what is called a "tarball". This is the open source world equivalent to a zip file. Decompressing and opening the archive can be a bit tricky on GNU/Linux; the tar command has pretty nasty syntax. We will need an extra utility to decompress this .lz file.
$ sudo apt install lzip
$ lzip -d ed-1.16.tar.lz
$ tar -xfv ed-1.16.tar
Now we have a folder with the ed source code inside. Let's change to that directory and see how easy it can be to compile open source software.
$ cd ed-1.16
Notice that we are using a slightly different notation to invoke a couple programs,
./. Since the shell will only look in folders listed in the
$PATH variable, if we want to execute a program within the current directory we have
to specify that we want to search in the current directory (
Let's try a more difficult example. This time, we are going to try to compile the
git version control system. Unfortunately, we do not have all the necessary dependencies and this will cause the compilation to fail. The repeated failure to
build software due to dependencies is affectionately known as dependency hell.
Uh oh, hit a snag. The
make process says he cannot find a C header file, zlib.h. Let's download and create the zlib library real quick.
$ cd ~/
$ wget https://zlib.net/zlib-1.2.11.tar.xz
$ tar xf zlib-1.2.11.tar.xz
$ cd zlib-1.2.11
$ sudo make install
Now we go back to the
git source code folder and attempt to build again. One interesting feature of the
make build process is that it will only recompile files that have changed since the last compile. We will again hit some snags, but this time we will just use the package manager to install the missing dependencies.
We have successfully built the
git version control system. Much of open source software has it's source code controlled using
git these days. This was just a demonstration of how open source software is packaged and built. Hopefully you also can recognize the usefulness of a package manager! If you want to get your hands dirty building lots of source code, there is a GNU/Linux distro where you can build everything directly from source code: Linux From Scratch.