Installing software in Linux from source - Tips4ever


Hi this is Mahesh, Tips4ever is my IT Journey to technology, computers, software, Internet and much more....

Jun 8, 2010

Installing software in Linux from source

    First of all you do not worry about how can read this loooooooong procedure. Be cooooooooooooooool yar it is just four steps of unpack, configure, build, install with four commands tar unpack, ./configure, make, make install.
    All are know about that linux softwares available in three formates.

  • RPM (Redhat Packmanager it is in .rpm file format for Redhat based Linux)
  • DEB (Debian Packmanager it is in .deb file format for Debian based Linux)
  • Source Packs(It is a universal pack for all platforms available in tarball compressed format like {packname.version}.tar.gz or .tar.bz2)
    We can install .rpm packages by typing rpm -i {packname-version.rpm (vlcplayer-0.9.5.rpm)} in command-line base or by using YUM Package manager in GUI friendly (select and install) in Redhat base Linux like Fedora and more... and same as we can install .deb packages by typing apt-get install {Packagename-version.deb} in command-line base or use Synaptic Packmanager in GUI friendly in Debian based Linux like Ubuntu and there are some more Package manager form different Linux distributors for manage there packages in GUI friendly and also in command-line. This two formates is easy as like .exe in windows click and install.

    Lets come to source packages it is a universal packages for all platform like Windows, Linux(both Redhat and Debian base Linux) and Power PC's . It is in the tarball compressed format with file extension .tar.gz or tar.bz2 and more... we uncompress the content to any location as we like by using tar command shown as below.   

# tar xvzf package-version.tar.gz (or tar xvjf package-version.tar.bz2)
# cd package-version (directory where package content uncompress)
# ./configure
# make
# make install

It is not same for all packages some packages will use some advanced procedure. I recommended it is better to read manual README  or INSTALL file for installation process.


  • Step 1. Unpacking
  • Step 2. Configuring
  • Step 3. Building
  • Step 4. Installing
  • Cleaning up the mess
  • Uninstalling

Step 1. Unpacking

After downloading the package, you unpack(uncompress) it with this command because it is in tarball compressed:

me@linux: ~$ tar xvzf packname-version.tar.gz

As you can see, you use the tar command with the appropriate options (xvzf) for unpacking the tarball. If you have a package with tar.bz2 extension instead, you must tell tar that this isn't a gcompressped tar archive. You do so by using the j option instead of z, like this:

me@linux: ~$ tar xvjf packname-version.tar.bz2

What happens after unpacking, depends on the package, normally when unpack the source file it unpack with the packname with version see by typing ls command:

me@linux: ~$ ls 
packname-version packname-version.tar.gz
me@linux: ~$

In above example unpacking our package packname-version.tar.gz did what expected and created a directory with the package's name vith version number packname-version . Now you must cd(change directory) into that newly created directory:

me@linux: ~$ cd packname-version 
me@linux: ~/packname-version$

Read any documentation you find in this directory, like README or INSTALL files, before continuing!

 Step 2. Configuring

Now, after we've changed into the package's directory (and done a little RTFM'ing), it's time to configure the package. I recomended to read the README and INSTALL or and manual for the package installation procegure befor going to running the configure script. 

You run the script with this command:
me@linux: ~/packname-version$ ./configure 

When you run the configure script, you don't actually compile anything yet. configure just checks your system and assigns values for system-dependent variables. These values are used for generating a Makefile. The Makefile in turn is used for generating the actual binary.

When you run the configure script, you'll see a bunch of weird messages scrolling on your screen. This is normal and you shouldn't worry about it. If configure finds an error, it complains about it and exits. However, if everything works like it should, configure doesn't complain about anything, exits, and shuts up.
If configure exited without errors, it's time to move on to the next step.

 Step 3. Building

It's finally time to actually build the binary, the executable program, from the source code. This is done by running the make command:

me@linux: ~/packname-version$ make

Note that make needs the Makefile for building the program. Otherwise it doesn't know what to do. This is why it's so important to run the configure script successfully, or generate the Makefile some other way.
When you run make, you'll see again a bunch of strange messages filling your screen. This is also perfectly normal and nothing you should worry about. This step may take some time, depending on how big the program is and how fast your computer is. At this point I usually lose my patience completely. Don't worry yar take a break with coffee.

If all goes as it should, your executable is finished and ready to run after make has done its job. Now, the final step is to install the program.

 Step 4. Installing

Now it's finally time to install the program. When doing this you must be root. If you've done things as a normal user, you can become root with the su command. It'll ask you the root password and then you're ready for the final step!

me@linux: ~/packname-version$ su
root@linux: /home/me/packname-version#

Now when you're root, you can install the program with the make install command:

root@linux: /home/me/packname-version# make install

For Debian base Linux like Ubuntu use sudo command as follows:
me@linux: ~/packname-version$sudo make install

Again, you'll get some weird messages scrolling on the screen. After it's stopped, congrats: you've installed the software and you're ready to run it!

Because in this example we didn't change the behavior of the configure script, the program was installed in the default place. In many cases it's /usr/local/bin. If /usr/local/bin (or whatever place your program was installed in) is already in your PATH, you can just run the program by typing its name.
And one more thing: if you became root with su, you'd better get back your normal user privileges type exit to become a normal user again as follow

root@linux: /home/me/packname-version# exit
me@linux: ~/packname-version$

It is not necessary for Debian user it will temporary changes as root in yours name and automatically forgets the root mode for some time. But some Linux distributors it is long up when your shell is open. So, it is better to close and re-open current shell.

 Cleaning up the mess

I bet you want to save some disk space. If this is the case, you'll want to get rid of some files you don't need. When you ran make it created all sorts of files that were needed during the build process but are useless now and are just taking up disk space. This is why you'll want to make clean:

me@linux: ~/packname-version$ make clean

However, make sure you keep your Makefile. It's needed if you later decide to uninstall the program and want to do it as painlessly as possible!


    It is easy to uninstall the package which are installed by rpm and same as .deb with apt-get remove other with other ways. And also easy to uninstall sourcepackages by needing Makefile file on where the file is created in building process and use following command where the file located.
root@linux: /home/me/packname-version# make uninstall

If we lose Makefile file, We can manually delete the installed files. It is not a easy way to manually id and delete the sertain application related file. My idea is re-process all the above as previously done without any change and don't re-install it and take the Makefile and use above Make uninstall command to uninstall application.