Written By: X_console
You will find that most of the software you installed with your Linux distribution will quickly become outdated. You can give your thanks for this to the hundreds of Linux hackers out there who patch programs, upgrade them, and send them out.
One excellent example is the Linux kernel. Whichever distribution you bought, you can bet that it came with an older kernel than the one available right now.
So how do you upgrade software in Linux? Or how about installing and
uninstalling applications? Most distributions come with software
package managers. The most common is the RedHat Package Manager, or
rpm for short.
rpm is available in many Linux
distributions. However, other distributions have their own package
manager. Slackware has
and Debian has
This tutorial will not be based on installing and uninstalling software through the use of package managers. Rather, it will cover the basics of installing software from source, as well as how to remove software as painlessly as possible.
Okay, so you have your trusty package manager and there is little reason to build software from source. Right?
Not so. When new software comes out, chances are, they will be in source code format. A format for your package manager will take a while to come out. Okay, so maybe it will not take that long, but still, if you are one of those who just has to have the newest software as soon as it comes out, source is the only way to go. Also, certain software packages need to be configured in source code format for certain features to be enabled. The binary file you get for your package manager may not have been compiled with this feature you want.
Another reason to compile source: in the event that your package manager breaks down, you may need to build it up from source. Or if you need to use a different Linux distribution without your package manager, knowing how to build from source will be helpful.
Perhaps the most enticing reason to build from source is if you are a programmer. Most Linux programs are released under the GNU General Public License. In a nutshell, programs released under this license allows you to modify and/or to redistribute the program and the source code.. So feel free to make modifications to the source code before compiling them. (Of course, you should only do this if you know what you are doing.)
Building software from source means that you need to have development tools like compilers, interpreters, and debuggers. Most Linux distributions come with a set of development tools. If at all possible, install all the development tools that come with your distribution, because you never know when you might need them. If you cannot install all the development tools, then install at least the following:
Certain programs will require certain development tools. Be sure to read the documentation that comes with the source code. The documents will normally tell you what other extra tools need to be present for the program to be properly built. You may also be required to install certain libraries that might be required by certain programs.
Linux programs normally come in two flavors: stable and development. Stable releases are those releases that the programmers think are safe enough for production use. Basically this means that it has been thoroughly tested and a lot of the bugs have been cleaned out.
Development programs are those that are alpha and beta releases. These are still being tested and may contain serious bugs that could damage your system. Development releases are mainly for people who want to examine the source code and find as many bugs as possible. Unless you want to tinker with the source code, choose the stable releases.
Before you download a source package, you may be asked if you want to download the glibc or the libc package. These are just libraries. If you are using the latest releases of RedHat, Debian, Suse, Caldera, Slackware, or other distributions based on them, you can download either one, but it is recommended you download the glibc version.
This is a very common question with a very easy answer. You can
download and save the package anywhere you want. Some people like it
/tmp; others, like
me, make a directory specially for downloaded packages, for instance:
/packages. I like to be able to
keep an organized system so I know where everything is. Again, this is
completely up to you. It does not in any way affect the building of the
Third party software is normally installed in
Binaries go in
and, if the software is for the root user,
/usr/local is basically just
a mirror of the
except that it is where you put your third party software in. Programs
that don't seem to be fit for
(use your judgment), can go into
However these are just conventions. You can install programs anywhere
Installing from source is remarkably easy. At the most it is a five-step procedure. Here are the commands you will type into a console or terminal screen:
tar xvzf foo.tar.gz
That is it. Of course, it is only that simple provided you do not run into problems. In the next section we break everything down and examine what is going on.
It should be noted that most programs are built in the above procedure. Certain programs, however, do not follow the above standard. You will need to refer to the documentation included with the source package.
When you download a source package, it will normally be in an
archived and compressed format. They will have the extension
These files are called tarballs in Linux speak. A
.tar.gz file and a
.tgz file are the same.
.tgz is just shorthand for writing
Beware, though, certain
packages are made specifically for Slackware's
Make sure you check if a tarball is for generic Linux systems or for
Slackware. If the tarball is a
it is most likely for a generic Linux system.
If you happen to download a tarball from a Windows OS, there is a
chance that the tarball's extension will get mangled. For instance, you
want to download
After downloading you find that it has been saved as
foo_tar_tar. This is probably due
to the multiple dots in the original filename. Simply rename it back to
foo.tgz. Both are fine.
Save the tarball to a temporary directory. This can be
/tmp or wherever you like.
Assuming you saved it in
you can now begin to unpack it with the following command (as root):
tar xvzf foo.tar.gz
This assumes that the file you want to unpack is
foo.tar.gz. The above
tar command along with its options
will unpack and uncompress the file. Otherwise you would have to do it
tar xvf foo.tar
That is fine too. Personally I prefer not having to type two commands if I can do it all in one command. Once you have unpacked the source, a directory will (most of the time) be created. This directory will be the name of the tarball.
Since our tarball was called
the created directory in the
directory is now
Just to be sure, run the
command to get a listing of all the files in the directory, and the
name of the directory created when you unpacked the source tarball.
Next step is to
cd into that
directory and then you can start building the software.
It is time to run the
attempt to guess the correct values for system-dependent variables.
These values are used to create a Makefile, which in turn will be used
to build your software. To run the
script, type the command:
You will see tons of messages running down your system. Do not worry
about it. If
a problem, it will tell you and then it will stop. At which point you
will have to figure out what the problem is, and hopefully, fix it. If
all goes well, then
should exit gracefully. If you do an
you will find that there is now a Makefile.
configure comes with many
options. You can view a list of all options using the following
./configure --help | less
The one option you will most probably be interested in is
--prefix=path. This option lets
you specify where you want the software and all its files to be
installed in. If you are concerned about an organized system, this is
the way to go. If you just want to see if you can compile the software
and where all the files will be installed, this is what you want.
Before we do this, let us create a directory for the installed files to
be put in. Lets call it
Now we run the configure script:
When you install your software, all of its contents will be kept in
/tmp/test/foo. At the moment,
/tmp/test/foo will be empty. You
have not yet built and installed your software. You have only just
generated a configured Makefile. If you do not specify a
--prefix=path option, your
software will be installed in the default directory, normally
Now comes the exciting part. This is where you actually start
building the executable program from the source code. This is done
make command. Make
sure you have the Makefile generated otherwise
will not work:
More text will start to fly off your screen. Again, do not worry
about it. If something goes wrong,
will give you an error message. If you have no idea what this error
message means, be sure to copy it down and post it here at
If all goes well (which it should if you read the documentation provided in the tarball and your system meets the minimum requirements needed to run the program.), you now have your software ready to be run. The final stage is to install it.
If you have managed to get here, congratulations. The chances of
anything going wrong here is very slim. To install the software, make
sure that you are root. Then run the command:
More stuff will fly off your screen. You should be used to this by
now. When everything stops, your software has been installed. Since we
configure, all our
software has been installed in
Check it to be sure. Be sure to keep your Makefile with you. You will
need it later on. If you used the
option, you will need to modify your
file and add the software's path to your
variable. Just add the following line right at the bottom of
Next we have to update your
and this is done with the
With that done, your program should now be ready to run. See if you
can run the program. If you get library errors, try running
ldconfig and then running the
When all is well, it is recommended that you run
makewhatis to update your
whatis database and
updatedb to update your
locate database. Finally, you will
want to get rid of all the object files created during the
make process. This will save you
disk space. Use the command
to accomplish this.
How do you uninstall software that you have built from source? Well,
there are three ways to do this. We will start with the easiest way, to
the hardest way. First if you kept your Makefile like I told you to,
you may be able to run the command:
If text flies off your screen, that is a good sign. If
make says it does not understand
you, that is a bad sign. In the event that
cannot understand you, you may have used the
option, in which case you can uninstall the program simply by deleting
the directory it is resting in, in our case,
If you decided not to use the
option and you did not keep the Makefile, you are in serious trouble.
First, you will need to run
again to generate the Makefile. Then try to run a
uninstall and see if that works. If it does not, then you
will need to read the Makefile to see where everything gets installed.
Save yourself the trouble and keep the Makefile, or use the
Now for a real life example. I downloaded a tarball called
bar.tar.gz and saved it in /tmp.
Okay, so the tarball name is not real. But the procedure is. First I
decide I want to install the files in
So obviously, I will have to create the appropriate directories. Now I
should mention that you do not need to be root to configure and
build the software. However, you must be root when you are
installing the software.
tar xvzf bar.tar.gz
Now that my software is installed, I then edit my
/etc/profile and append the
Finally, I source my
file and then I am ready to use my program. When I want to uninstall
it, I can just run
and if that does not work, I can just delete the subdirectory
So that covers the main basics. Do not be afraid to build programs
from source. It is not hard. After all, if you plan on upgrading your
kernel, you need to build it from source anyway. Sometimes you may not
have to run the
script at all. Read the
README files included in
the tarball. It tells you what to do.
[ top ]