As a systems administrator I generally use package managers to install software. But in some situations I can not use package manager because provided software version is old or do not compatible. In this situations how can I install new software from source code by compiling.
Software source code can be get in different forms like compressed files like
tar.gz or from repositories like
svn etc. We will follow compressed way in this tutorial. To get more information about
git read following tutorial.
Download Source Code with wget
As stated previously we will get source code with the tool named
wget .We will provide the url of the compressed source code. To get more information about wget look following tutorial.
$ wget http://poftut.com/HelloWorld.tar.gz
Extract Source Code with tar
Downloaded source code is compressed with
tar.gz we will extract it with
tar command like below.
$ tar xvf HelloWorld.tar.gz
Install Compiler and Required Libraries
Before compiling the source code we need to install related compilers and required libraries. More information about the required libraries can be found in the README file of the source code. In this step we will install
$ sudo apt install gcc libgcc-5-dev
Professional projects generally have
configure script is used to te setup related files and folders before compiling.
configure gets information about the current system and compiler with libraries and created
Compile with Make
Now the most important part we will compile the source code.
Make is very useful tool to compile the source code according to provided configuration. there is very complex compile configurations where they are easily handled by
make command. We will just issue
make like below.
make should be run in source code root directory.
Make Compile Faster
Modern computers have more than single CPU core. If we do not provide any option the
make command will compile the source code only using single core. We can use other cores during compile with
-j option. This will use given number of cores. In this example we want to use 4 cores.
$ make -j 4
Install with Make Install
Last step is installing the compiled binaries. We will use
make install command. If the binaries will be copied to the directories those we do not have write right we should use with
$ sudo make install