|
>>
|
No. 513
6. Installing packages from source
* A lot of programs and libraries for Linux are written in C or C++. Initially the program consists of text files which can be read and edited with a text editor. In a second step these files can be compiled with a compiler. On linux this will probably be the GNU C compiler (gcc or g++). The compiler will transform the text files into binary code, which can be executed on your system (You could say that the human language is converted into computer language). When everything is compiled and ready, the different pieces of the program or library can be installed on your system.
* Source packages are often distributed in the form of a tar archive. A tar archive is actually a collection of files that are stored as one file with the .tar extension. The archive can be created or extracted with the tar utility. The name "tar" is derived from "tape archive" as tar was historically used to make backups to tape drives. A tar archive does not use file compression techniques to make the file smaller. That's why tar archives are usually compressed with the standard linux compression tools: gzip (extension .gz) and bzip2 (extension .bz2). As a result, source packages often have two extensions (e.g. archive.tar.gz), and they are often called tarballs. Modern versions of tar will uncompress the tarball automatically for you. The typical command to uncompress and extract a tarball is: 'tar -xvf archive.tar.gz' . The "-x" option tells tar to extract, "-v" tells tar to be verbose (show the files that are extracted), "-f" tells tar that it has to extract from a file.
* When you have extracted the tarball, a new directory will be made, with the contents of the archive. Now we can start building the program. First we 'cd' into the directory, and read the README and INSTALL files. These files often contain information about the dependencies of the program, instructions to build or install the program, etc. We can install the needed dependencies with Synaptic. But we have to make sure that for every dependency, we have the corresponding development package installed as well. These packages have the same name as the original package, but with the "-dev" postfix. They are only necessary when you want to compile programs from source. The first command we have to give is ./configure. This script is provided by the source package, and it checks what building tools we use on our system, if the necessary dependencies are installed, and a lot more. It is very likely that it will return an error because something is missing on your system. Just have a look at the error, and install the necessary package. You have to repeat this process until the './configure' command succeeds [10]. Now we can type make in the terminal. The 'make' command will build everything needed for the package. This might take a while, depending on how large the program is. Now we are ready to install the necessary components on our system. Source packages should install their files in the '/usr/local/' hierarchy by default. You will need root privileges to do the installation. To install, we type sudo make install in the terminal. The executables will now be installed in the '/usr/local/bin' directory, and you can now use them as any other command.
* One of the difficulties with installed source packages, is that it is not so easy to uninstall them. Sometimes you will be able to issue sudo make uninstall from within the source package directory. But this will not always be the case. And once the files are installed in the '/usr/local' hierarchy, it is very hard to know which files belongs to which package. That is why I would like to introduce you to the 'Stow' system. The idea is that we install every package we build from source into it's own subdirectory in the '/usr/local/stow' directory. When this is done, we can use the stow command to make links in the '/usr/local' hierarchy for every file in that subdirectory. Now our system will recognize the programs and libraries we installed. When we want to delete a package, we can use 'stow' again to delete all the links for that package in the '/usr/local' hierarchy. And we can start from a clean slate again. Stow makes it also very easy to have multiple versions of a package installed. You can install them next to each other in the '/usr/local/stow' directory. The system won't know about them until you make the necessary links with stow. To use a newer version of a program, you delete the links to the older version, and make new ones to the new version. Completely deleting a package from your system is very simple as well. Just delete the links with the 'stow' command, and remove the directory of that program.
* I will now give you an example of installing a source package with the help of stow (You have to install the stow package with synaptic first). Lets say that we want to install a package named package-1.2 .We compile the package first with the ./configure and make commands (it doesn't matter from where). Then we install the package in its own directory in the stow directory with: sudo make install prefix=/usr/local/stow/package-1.2. Now we have to cd into the stow directory (/usr/local/stow), and let stow create the necessary links with this command: stow package-1.2. To delete the links to your package again type stow -D package-1.2 from the '/usr/local/stow' directory.
|