Friday, April 11, 2008

Compile and Install from Source Code

So you found some neat software that isn't in the repositories or doesn't have a .deb package. (See my post on Security about .deb packages.)

The only option is to download the tar file and compile it and install it.
Although this sounds scary it's really not that hard to do.

Here is a step by step how to.

The simplest place to download the tar.gz file is on your desktop.
Let's say the file name is xyz.tar.gz

Note: The extension for the tar file can be one of the following;
.gz .tgz .bz .b2z


Now create a directory in your home folder where you will uncompress the files. (Mine is named “source”)

Open up your terminal and type this in;

cd Desktop

This will navigate you to your desktop where the tar file is located.

Uncompress your tarballs into the folder using the -c option as follows (and replacing “source” with the name of your directory):

If the file was compressed with gzip it will have the tar.gz or the .tgz extension and you need to use the following code.

If the file has the .tgz extension use this;

tar zxvf xyz.tgz -C ~/source

If the file has the .gz extension use this;

tar zxvf xyz.tar.gz -C ~/source

If the file was compressed with bzip it will have the .bz or the .b2z extension and you should use these commands;

For the .bz extension use this;

tar jxvf xyz.bz -C ~/source

For the .b2z extension use this;

tar jxvf xyz.tar.b2z -C ~/source

If you don’t know the compression method that has been used you can use the file command:

file nameoffile

Now type this into the terminal to change back to your home folder;

cd

Now change directories to your uncompressed files by typing this into the terminal;

cd source/xyz


It is also recommended you go to the directory in Nautilus and look for a “README” or “INSTALL” file, because the software might require you to do things in a specific manner. Normally you would compile the source code like this:

./configure

This will run a script to see whether or not all the dependencies are correct and your build environment are right. If you are missing dependencies the script should tell you the ones you are missing and what it needs.

When the configure script is finished (has completed correctly), run this:

make

Make will do the initial compiling of your software. To finish it of and install your software run:

sudo make install

If the compilation doesn’t succeed check the errors and run:

make clean

before you restart. To remove the software if you don’t need/ want/ like it simply run:

sudo make uninstall


You have now learned how to unpack, compile and install / uninstall a program from source code.
See! It was easy!

TaZMAn

1 comment:

Mr. Smith said...

before you do this, you need to install the build-essential package. This should be on the ubuntu CD i think