Featured Articles
Stitch
Rhythmic Walk
Major Project - Divine Application
Generi Rig for Blender
KWrite/Kate MEL Syntax Highlighting
Improving the Maya Linux File Browser
Latest News
Search

How to compile software on Linux PDF

So, you're using Linux at work. Thus far, all is as expected - it doesn't seem to crash, and is a damn sight nippier than most things you've used before. In short, life is good


And then you find out that you need to install some software. Who knows what - a new version of MPlayer maybe, or a game to help kill some time. You visit the program's website, go to the download page, and then the problem smacks you in the face like a wet trout - how the heck do you install a program on Linux without administrator privileges?

 

Well, if you've got administrator privileges, it's a piece of cake. If you're running Debian/Ubuntu/Kubuntu Linux, it's normally a case of opening a console and typing "sudo apt-get install <progra> ", and that's it - Linux will automatically download the latest version of the program from the internet and install it for you. If you're running some variant of Red Hat/Mandrake/SuSE or something similar, then you just download a .rpm file and install it with "rpm -ivh ".

But we're at work. We don't have the administrator privileges needed to run those commands. And the administrator probably has far more important things to do than install every piece of software we're curious to try. But never fear, there is an answer - compiling the software and installing it into our home area...

It sounds scary, but when you get down to it and actually do it, it's pretty straightforward. It normally comes down to these simple steps:


1) Make a folder where you want to install your new program to. I tend to put each new program I compile in it's own folder in ~/.Software - the dot at the front of the directory name means that it's hidden by default, which keeps it nice and out of the way. But you can install it anywhere you like

mkdir -p ~/.Software/MPlayer


2) Next step, go to the website in question, find the downloads section and look for a link to download the source code. The file in question will almost always have one of the following endings: ".tar.gz", ".tgz", or ".tar.bz2", for example "mplayer-1.0rc2.tar.gz" or "mplayer-1.0rc2.tar.bz2". Download this file to somewhere in your home area.

3) That file you downloaded is lots of files compressed together - just like a ".zip" file on windows. So just like on Windows, we need to uncompress it. Open a console, and "cd" to the directory where you saved the source file, and extract it with the tar command like this:

cd ~/Downloads/
tar -xf mplayer-1.0rc2.tar.bz2


4) That should have decompressed everything for us. Have a look for the new folder that'll have been created in the directory where you extracted those files, and "cd" into it. We now have to run a shell script called "configure". This script takes a look at our system and works out exactly how this software should be compiled and installed, and then generates these instructions in the form of "makefiles". Now, if we had administrative privileges, we could just run "./configure" at this point and be done with it. But we're not allowed to install software in the default location (/usr/local), so we have to tell the configure script that we want to install somewhere else. We do this by using the "--prefix" flag, followed by our chosen install directory:

./configure --prefix=/home/karl/.Software/MPlayer


This'll then generate our makefiles for us. Keep an eye out for serious error messages along the way (like missing pieces of software, for example). Note that configure needs the *full* install path - "~/.Software/MPlayer" wouldn't work. Also note that every software package normally has tons of unique command line options - typically for including or excluding pieces of functionality, for example. For the full list for a given package, run configure with the "-h" flag.

5) So, we have our makefiles. Would you believe it, the hard part's out of the way now. We can now compile the program just by running "make".

make


If anything goes wrong at this stage, you'll normally get several pages of errors. The first one is always the culprit, so scroll up until you find the first line with "error" in it. Depending on the speed of your machine and the complexity of what you're compiling, this stage can take a while... Coffee time!


6) If make completed successfully, the program is now compiled. All that remains is to copy the program and everything it needs into its install directory:

make install


7) Your brand-spanking-new program is installed and ready to go! Go have a look in the install directory you created - the program itself will typically be in the "bin/" folder, with additional libraries in "lib/", settings files in "etc/" and images/sounds in "share". Depending on the program, you may need to add a few extra lines to your "~/.bashrc" file so our new program feels at home:

#Make sure we always run our new mplayer instead of the system-wide mplayer
export PATH="~/.Software/MPlayer/bin:$PATH"

#Make sure MPlayer uses the new libraries instead of the system-wide older ones
export LD_LIBRARY_PATH="~/.Software/MPlayer/lib:$LD_LIBRARY_PATH"


That's it, your new program is now ready to go. Most Linux programs do fall into this simple recipe - just ./configure; make; make install. Not as tough as it sounds at first...

 

 
Comments

You must javascript enabled to use this form

amazing, huge thnaks
the way, you explain, things really get clear and confused equations in brain cells start making more sense.

keep rocking and write more often....

Posted by lala, on 01/09/2010 at 19:34

thanks Karl for these notes,
but...
if the make fails with errors,
it usually means that libraries are missing?
and these should be installed as an administrator?
eg Ubuntu: sudo apt-get install (?).lib
So interesting, but I still can't get past 'make' errors.

Posted by Dave, on 01/24/2011 at 07:51

Hey there Dave,

:
if the make fails with errors,
it usually means that libraries are missing?
and these should be installed as an administrator?

Normally, yes. Nine times out of ten, if it errors out then it's because something's missing (occasionally it's because of a bug in the code or incompatibilities with the versions of other packages you already have installed on your machine, but this sort of thing doesn't happen too often).

The errors you get from compiling software manually can be a bit hard to understand, and can require a bit of googling or technical knowledge to diagnose. I tend to look for the first line with 'error' in it, and see if it's either something I recognise, or if Google has any further information on it. The process varies from case to case...

However, if you've got permissions to 'sudo apt-get install' on your machine, then you probably don't need this guide at all, as 'apt-get install' is a much easier way to install software than compiling it manually! :) This guide is mostly for people who want to try software out at work or uni...

Does that clear things up?
Karl

Posted by Karl, whose homepage is here on 02/01/2011 at 23:46

 1 
Page 1 of 1 ( 3 Comments )

< Prev

Designed by: Drupal hosting Mambo templates Best web hosting
http://www.kreanimate.co.uk/site, Powered by Joomla and designed by SiteGround web hosting