Friday, February 27, 2009

Compiling and Installing software from source

Typically applications you must compile from source as a ".tar.gz", ".tar.bz2", or ".zip" file.

You'll probably want to operate from inside your home directory. If your user is (for example) username, your home directory will be /home/username/. For the rest of this section we will assume you have downloaded your zip file to /home/username/src. If you do not have a src directory, you can create it with the following "mkdir" (make directory) command:

mkdir /home/username/src/
So, we have our source package in /home/username/src/.

Change to the /home/username/src/ directory with the "cd" (change directory) command like so:

cd /home/username/src/

Use the "ls" (list directory contents) command, to see the file is present:

ls

We now need to unzip the zipped file, this is done differently depending on the file extension.

for files ending in .tar.gz, use:

tar -zxvf filename.tar.gz
(replacing with the name of the file).

for files ending in .tar.bz2, use:

tar -jxvf
filename.tar.bz2

for files ending in .zip, use:

unzip
filename.zip

You should now have a new directory, containing all of the source files. To confirm it exists, and to get its name, use the "ls" command again.

we now need to go into the new directory, so use the cd command:

cd

This is where things will differ. Some packages will have an INSTALL or README file which will contain installation instructions. use "ls" to see if the software has an install or readme file. If it does have one, you can use the "more" command to read it, like so:

more INSTALL

Generally, the final 3 stages are as follows:
- Configure the installation
- Compile the software
- Install the binaries

The pre-installation configuration is done by executing ./configure:

./configure

This will perform some requirements testing on your system, and create a "Makefile" which will explain to the "make" utility how the software should be compiled. If you receive any error messages during this stage, you may wish to search the linux forums to see if they have been found and resolved by someone else already, if not, feel free to send a mail to me- Please include all of the output including any error messages, and some details about your system - what distro you are using, what are you trying to install etc etc


The next stage is to compile the software, this is done using "make". When you run "make" it will read the instructions in the Makefile and build the application binaries.

make

The final stage is to install these binaries, ie, copy them to a more permanent location. Typically only the "root" user can do this, so you will need to swich to the root user with the su command:

Once you are root, install the binaries using the "make" command, followed by "install", like so:

make install

That is it! Check the user documentation of the software you installed for details of how to run the application.

1 comment: