Skip to content

Installing a software from source. (Untarring a .tar/.tar.gz file)

November 28, 2011

Read this till the end before actually trying out the steps.

After downloading the tar.gz file, untar it by running

tar -xvzf filename.tar.gz

After untarring it, the best way is to go through the README.txt or INSTALL.txt which can be found under the /docs directory among the untarred files.
However, assuming that the software you’re about to install are built with GNU’s autoconf and make tools, I’ll explain the steps below. (Meaning, in most of the cases the following steps will work.)

1. Check to see of there is a script called ‘configure’ among the untarred files. If yes skip this step. Otherwise, do

autoreconf –install

2. This will generate the configure script for you and you will be able to find it among the files. Once ‘configure’ is there, run

./configure

This will generate a file called the Makefile for you. However (A BIG HOWEVER), a Makefile will only be generated provided you have all the dependencies installed on your system. That is, the software you are about to install may depend on other software or libraries to work. Step 2 checks if these dependencies are met and will return an error if any of the dependencies are not met. When you see the error, you will have to install that software/library package in order for the configure script to execute succesfully. If you are using Ubuntu/Debian based distors, you just have to apt-get install the softwares.

3. After installing the dependencies and the successful completion of the configure script, a Makefile will be there among the files. Run

make

This will compile the files of the software. (Note: If you are making any changes to the software, make recognizes that change and recompiles only that. It thus saves you a lot of time by not recompiling the entire thing once again.

4. After the successful completion of make, run

sudo make install

This will install your softwares binary files and libraries under /usr/local.

5. You are good to go. Just type the name of the software in the terminal and hit enter.

IMPORTANT: The problem with the above approach is that (assuming you are using Debian/Ubuntu based distros) your package manager ‘apt’ doesn’t know that the software has been installed. As such, it might cause trouble if you use apt to install this software itself from the repository. The recommended way to install softwares from source is to install them into a non standard location. The changes you will have to do in the above steps in order to install the software into a non-standard location are explained below.

1. Same step.
2. Create a folder ‘temp’ (any name you want) somewhere in your home directory. For sake of explanation, I created a folder named ‘temp’ in my home folder. So its path will be /home/haris/temp. Now run

./configure –prefix=/home/haris/temp

3. Same step.
4. You ran this step with sudo earlier because /usr/local was a standard location and you needed administrative privileges in order to install binary/library files there. But now, since we have given a non-standard location, just run

make install

This will install the binary files of your software (the files that is to be executed in order to launch the program) in the specified location. In this case, under /home/haris/temp/bin.

5. You’re not good to go. In order to run the program, you need to go into the directory containing the binary files and run it from there by typing the name of the software. (This is because linux searches for the executables in standard locations such as /bin, /usr/bin, etc.) However, if you want the software to run from the prompt no matter in which directory you are, here is way for that.

6. The locations linux will search for the executables will be given in a variable called PATH. Try

echo $PATH

in your terminal and you can see the locations.

7. What we need to do is to add the path of our installed software to the PATH variable. To do this, open up the file named .bashrc from your home folder.

sudo gedit ~/.bashrc

8. Add the following to the end of that file (in your case, give the path of the ‘bin’ folder of the installed software). In my case,

PATH=$PATH:/home/haris/temp/bin
export PATH

9. Save and exit. Restart your terminal and try typing the name of the software from anywhere you want. It will launch.

NOTE: Sometimes the Makefile will be there by default among the untarred files. In that case just do step 2 and 3.

Now, in order to uninstall the program, all you have to do is run

sudo make uninstall or make uninstall

depending on how you installed it. Run this command from wherever you ran the  make command earlier.

Also, in order to clear the files created by make, run

make clean

That would be all. Thanks to Ershad!

Good luck!

About these ads
4 Comments leave one →
  1. November 28, 2011 10:46 PM

    Very nice tutorial post :)

    • November 28, 2011 10:55 PM

      Hey, thanks Ershad. Do let me know if there are any flaws in the way I wrote it. I’m glad you have gone through it.

      • November 28, 2011 11:12 PM

        It’s not a flaw, we don’t require ‘sudo’ to edit ~/.bashrc

        I would like to add two more commands:
        $make clean #All files created with ‘make’ will be cleaned
        $sudo make uninstall #Uninstall a software installed with ‘make install’

  2. November 29, 2011 6:17 PM

    Ah thanks! That had slipped my mind. I will certainly add that to the post.

Hey! What do you think? Share your thoughts. :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 72 other followers

%d bloggers like this: