Installing software from sources

presentation of the installation from the sources (with demonstration)

In computer science, the compilation (of a software or a library) is a procedure by which a source code (format understandable by a human, type ASCII) is transformed into binary code, a language understandable by your computer, for the purpose to be executed. Software is compiled so that it can be launched by the user.

Compiling one’s own software or library can bring some benefits, but is often to be avoided for the neophyte of the linuxian world. This documentation presents a general and popular method for compiling programs and libraries. It should be used, most frequently, when other methods of installing programs have failed:

 

  1. The APT package management system allows you to simply install a lot of software that meets the everyday needs of the average user. When possible, choose this method!

  2. If software is not available in Ubuntu’s default APT repositories, it may be available as an Ubuntu package (.deb) on another repository or directly on the software distributor’s site. Check if a package is available on the distributor’s website.

  3. If a software does not exist in .deb package but is available in other types of packages (.rpm, .slp, .tgz), the alien software is of good utility.

  4. More rarely, some distributors will distribute their software as a package for Autopackage. This installation method remains simple, but is not always very clean.

  5. Finally, other distributors, like Mozilla, publish their software in binary code form, so already compiled.

When none of these possibilities are valid for the program you are trying to install, you will have to go through the compilation. The word is big and looks scary, but it is less than it seems; let’s try to demystify this process together.

Why compile?

Under GNU / Linux, as with any other operating system, software must be compiled before it can be used. “Compilation” is the name of a procedure to transform source code, a set of instructions understandable by programmers, in binary code, understandable only by your computer. The computer is unable to understand source code directly: it must be “translated” so that the machine can interpret it.

This process is often slow, cumbersome and disgusting for the newcomer to Linux, as it probably never had to do under its old operating system. On Microsoft® Windows®, for example, you almost never need to compile your software, program editors that offer installers (the so-called “install.exe” or “setup.exe”) that contain the compiled program and a procedure that copies the program files to the right place on your hard drive. However, under Linux, there is no “install.exe”. A simpler and more user-friendly method has been created to prevent the average user from having to compile: this is the case, among others, with the APT package management system.

 

Why ? Is the installer concept not available on Linux?

In fact, this concept exists but it is avoided. Why ? The reason is that there is a large variety of Linux distributions and computer architectures (depending on the type of processor for example). This diversity is one of the great strengths of Linux, but it is almost impossible to offer an installation program that is suitable for everyone and can be installed on all machines. You should create as many installation programs as there are different types of machines!

But not everything is always available using one of these simplified systems. This is the case, for example, some drivers for your devices or software under development. Since Ubuntu is a desktop-oriented distribution and is intended to be accessible to all, we hope that you have tried the other methods available before, the compilation is the last solution to your problems.

https://github.com/rg3/youtube-dl

Demonstration of the installation of htop

To compile programs, you will first need to install the compilation tools. For that, nothing more simple, it is enough to install the package build-essential:

Install build-essential

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
admuser@srv01:~$ sudo apt-get install build-essential
[sudo] password for admuser:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
binutils cpp cpp-4.6 dpkg-dev fakeroot g++ g++-4.6 gcc gcc-4.6 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
libc-dev-bin libc6-dev libdpkg-perl libgomp1 libmpc2 libmpfr4 libquadmath0 libstdc++6-4.6-dev linux-libc-dev make manpages-dev
Suggested packages:
binutils-doc cpp-doc gcc-4.6-locales debian-keyring g++-multilib g++-4.6-multilib gcc-4.6-doc libstdc++6-4.6-dbg gcc-multilib autoconf
automake1.9 libtool flex bison gdb gcc-doc gcc-4.6-multilib libmudflap0-4.6-dev libgcc1-dbg libgomp1-dbg libquadmath0-dbg libmudflap0-dbg
binutils-gold glibc-doc libstdc++6-4.6-doc make-doc
The following NEW packages will be installed:
binutils build-essential cpp cpp-4.6 dpkg-dev fakeroot g++ g++-4.6 gcc gcc-4.6 libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libc-dev-bin libc6-dev libdpkg-perl libgomp1 libmpc2 libmpfr4 libquadmath0 libstdc++6-4.6-dev linux-libc-dev make
manpages-dev
0 upgraded, 24 newly installed, 0 to remove and 33 not upgraded.
Need to get 32.2 MB of archives.
After this operation, 88.6 MB of additional disk space will be used.
Do you want to continue [Y/n]?


Having done so, we can now focus on the compilation itself.

Here, I propose you to learn how to compile a simple little program: htop. This is an alternative tool to top, which allows to see the list of programs running. This will be an opportunity to discover the main compilation commands that will be used to install most software.
Note that it is found in the repositories via apt-get, but we will still try to compile manually to train.

* téléchargement du code source depuis le site web officiel : http://sourceforge.net/projects/htop/

Download and detar screen

1
2
3
4
5
6
7
8
9
admuser@srv01:~$ tar -zxvf htop-1.0.2.tar.gz
[ ..... ]
htop-1.0.2/scripts/
htop-1.0.2/scripts/MakeHeader.py
htop-1.0.2/missing
htop-1.0.2/COPYING
htop-1.0.2/Hashtable.h
htop-1.0.2/config.guess
admuser@srv01:~$

* Take note of the installation file INSTALL

extracting the contents of the INSTALL file

1
2
3
admuser@srv01:~/htop-1.0.2$ vim -R INSTALL

* Run the configure command
configure is a program that analyzes your computer and checks to see if all the tools necessary to compile the software you want to install are present. Its execution can take time because it carries out many tests:

Running the configure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
admuser@srv01:~/htop-1.0.2$ ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
[ .... ]

If you have not installed the buils-essential packages you will get the following error:

error when the compiler is not present

1
2
3
4
5
6
7
admuser@srv01:~/htop-1.0.2$ ./configure
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/admuser/htop-1.0.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

Package validation ends with an error:

configure error

1
2
3
4
5
checking for strdup... yes
checking whether gcc -std=c99 option works... yes
checking for refresh in -lncursesw... no
configure: error: You may want to use --disable-unicode or install libncursesw.

Yet if we look at the packages that are installed we find that libncrusesw is present:

installation validation of pkg

1
2
3
4
5
6
7
8
9
admuser@srv01:~/htop-1.0.2$ dpkg -l | grep libncursesw
ii libncursesw5 5.9-4 shared libraries for terminal handling (wide character support)

admuser@srv01:~/htop-1.0.2$ apt-cache search libncursesw
libncursesw5 - shared libraries for terminal handling (wide character support)
libncursesw5-dbg - debugging/profiling libraries for ncursesw
libncursesw5-dev - developer s libraries for ncursesw
centerim-utf8 - A text-mode multi-protocol instant messenger client

What we are missing is the development package that contains the libraries for the compilation

library installation for ncursesw5-dev

1
2
3
4
5
admuser@srv01:~/htop-1.0.2$ sudo apt-get install libncursesw5-dev

admuser@srv01:~/htop-1.0.2$ dpkg -l | grep libncursesw
ii libncursesw5 5.9-4 shared libraries for terminal handling (wide character support)
ii libncursesw5-dev 5.9-4 developer's libraries for ncursesw

New attempt:

new compilation attempt

1
2
3
4
5
6
7
8
9
admuser@srv01:~/htop-1.0.2$ ./configure
[ ... ]
checking for strdup... yes
checking whether gcc -std=c99 option works... yes
checking for refresh in -lncursesw... yes
checking ncursesw/curses.h usability... yes
checking ncursesw/curses.h presence... yes
checking for ncursesw/curses.h... yes
configure: error: missing headers: curses.h

Here is exactly when we find the tedious coast to install from the sources must be able to resolve all dependencies to be able to compile the program, previously we installed libncursesW now you have to install libncurses (yes, without the W it’s not the same library)

Installing libncurses5-dev for dependency resolution

1
2
3
4
5
6
7
8
admuser@srv01:~/htop-1.0.2$ sudo apt-get install libncurses5-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
ncurses-doc
The following NEW packages will be installed:
libncurses5-dev

New attempt:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
admuser@srv01:~/htop-1.0.2$ ./configure
[ ... ]
checking for refresh in -lncursesw... yes
checking ncursesw/curses.h usability... yes
checking ncursesw/curses.h presence... yes
checking for ncursesw/curses.h... yes
checking for /proc/stat... yes
checking for /proc/meminfo... yes
checking for usable sched_setaffinity... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating htop.1
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands

Youpiii !! the validation of the dependencies is solved: D.

The program is ready to be compiled! Rest assured, the hardest is behind you. 🙂
You just have to start the compilation with a simple command:

* Compile the software with the make command

 

make htop

1
2
3
4
5
6
7
8
admuser@srv01:~/htop-1.0.2$ make
make all-am
make[1]: Entering directory '/home/admuser/htop-1.0.2'
gcc -DHAVE_CONFIG_H -I. -DNDEBUG -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR="/usr/local/etc" -g -O2 -MT htop-AvailableMetersPanel.o -MD -MP -MF .deps/htop-AvailableMetersPanel.Tpo -c -o htop-AvailableMetersPanel.o `test -f 'AvailableMetersPanel.c' || echo './'`AvailableMetersPanel.c
mv -f .deps/htop-AvailableMetersPanel.Tpo .deps/htop-AvailableMetersPanel.Po
gcc -DHAVE_CONFIG_H -I. -DNDEBUG -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR="/usr/local/etc" -g -O2 -MT htop-CategoriesPanel.o -MD -MP -MF .deps/htop-CategoriesPanel.Tpo -c -o htop-CategoriesPanel.o `test -f 'CategoriesPanel.c' || echo './'`CategoriesPanel.c
mv -f .deps/htop-CategoriesPanel.Tpo .deps/htop-CategoriesPanel.Po
[ ... ]

During compilation, barbarian lines will appear in your console. You should not have to worry about it, all the problems that have been previously detected by configure.
Compiling a program can take time; it all depends on the size of it. It is thus much faster and easier to compile htop than Firefox for example.

It is possible to test the application:

 

execution htop

1
admuser@srv01:~/htop-1.0.2$ ./htop

* Install the application with make install

Installation htop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
admuser@srv01:~/htop-1.0.2$ sudo make install
make install-am
make[1]: Entering directory `/home/admuser/htop-1.0.2'
make[2]: Entering directory `/home/admuser/htop-1.0.2'
test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
/bin/bash ./libtool --mode=install /usr/bin/install -c htop '/usr/local/bin'
libtool: install: /usr/bin/install -c htop /usr/local/bin/htop
test -z "/usr/local/share/applications" || /bin/mkdir -p "/usr/local/share/applications"
/usr/bin/install -c -m 644 htop.desktop '/usr/local/share/applications'
test -z "/usr/local/share/man/man1" || /bin/mkdir -p "/usr/local/share/man/man1"
/usr/bin/install -c -m 644 htop.1 '/usr/local/share/man/man1'
test -z "/usr/local/share/pixmaps" || /bin/mkdir -p "/usr/local/share/pixmaps"
/usr/bin/install -c -m 644 htop.png '/usr/local/share/pixmaps'
make[2]: Leaving directory `/home/admuser/htop-1.0.2'
make[1]: Leaving directory `/home/admuser/htop-1.0.2'
admuser@srv01:~/htop-1.0.2$ htop

This is the “simple” explanation of the installation from the sources we will see in more detail the information for the ./configure and the make.

special thanks to the author of the page: http://en.openclassrooms.com/informatique/cours/reprenez-controle-at-la-aide-linux/compiler-un-programme-de-les-sources