Wednesday, April 12, 2006

how to compile programe on linux


Installing programs

1 Installing RPMs.

The two of the most common methods of installing software are .rpm and .tar.gz (or .tgz, .bz2, .gz)of the two RPMs are the most popular. RPMs are precompiled, installation-ready packages. You might prefer those, if you are new to Linux as compiling from source is not always easy.
Read More

RPMS in KDE are handled by kpackage. Open it and move around a bit. kpackage is opened by default when you double click a RPM in the file manager.  To download them in Netscape, hold the <shift>button and left-click the link (works for every other file, too). There is one obstacle, though: if you aren't root, you can't use kpackage to install or uninstall rpms. ( Although new versions seem to prompt you for the root password ) There are two ways to handle this, both involve opening a virtual terminal (click on the icon that looks like a monitor or hit <Ctrl>-t in the filemanager), this is something like the DOS-window known from some lesser OS's. Type 'su' to become root. Now you may fire up kpackage (type 'kpackage' at the prompt) or second install the rpms by hand.

Some options for installing by hand are: rpm -i [Package_name] : installs the program, rpm -U [Package_name] : upgrades an installed package with a new version, rpm -e [Package_name] : uninstalls, Adding the -vv option (e.g. rpm -ivv) turns on verbose mode (useful if encountering errors). RPM keeps a database about all installed programs, so you won't be able to accidentally erase important programs or files, which other programs rely on. Though be aware that you are doing your installs as root so rpms from obscure sites may be badly configured or even contain malicious content. A very common issue with rpm is failed dependencies, rpm checks if the package you are about to install has all the other packages installed that are required to run the program properly. Alas it only does these checks against its own database. So if you compiled and installed a prerequisite, rpm won't find that and will refuse to install. In this case you may either: Install the prerequisite again via a rpm-package or tell rpm to ignore dependencies (option --nodeps and the ultimate --force). Be careful with these options, though as you can easily break your OS...

one way to check rpms without kpackage or RPM is using the 'midnight commander' ('mc'), which runs on console or in a virtual terminal (e.g. kvt). mc allows you to browse a rpm just like a directory and have a look at all installation scripts (besides: it also makes a formidable file manager).

Install or upgrade? It is important to discriminate between these two. An example: You want to upgrade a library (that's a collection of program routines) because you want to install a program that needs that new version. But some of your programs depend on the old version. If you now upgrade with rpm -U these programs perhaps won't work anymore. You may now get all these programs in rpms that are compiled against the new version of this library. Or you just use the -i switch. Most libraries can coexist in different versions on one system.

Common resources are: and (preferably) its worldwide mirrors. Mandrake-Linux is compatible to RedHat-Linux. Apart from the KDE-base rpm and system initialization stuff you may use original RedHat packages. For Mandrake specific updates check Mandrake's FTP server and its mirrors via Mandrake's main site at  The RPM repository at RpmFind contains some 10.000 rpm-packages. They offer a tool 'rpmfind' which eases the process of finding and downloading specific rpms.

Recommended reading: man rpm, rpm --help | more, RPM HOWTO, Software Building HOWTO

2 Installing from source

So-called 'tarballs' are packages with the ending tar.gz, .tgz, .bz2 or .gz. These mostly contain programs in source-code that you have to compile yourself. They contain files like README, INSTALL etc. Read them and follow the instructions.
The basic commands needed to compile most programs are. /configure, make, make install. It all depends on the programmer that wrote them if they compile straight away or if you have to fiddle with path-or makefile settings or have to install other programs first (Check the Software Building HOWTO for that).

If you don't want to do that, check the rpm-repository at first, if they have an rpm of that program you won't need to do it yourself.  It may be a good idea to keep large downloaded packages somewhere in case you need them again (I use cdrs as they are so cheap).

Why someone wants to compile from source anyway if it can be such a tedious task?, you may ask. Some reasons are: you may customize program features and install paths self compiled programs usually are even more stable and faster than precompiled ones because they are more suited to your system settings, upgrading is easier: you just simply apply a patch and recompile. With rpms you have to download the whole program again. Source code is more up-to-date. Programs are written in source code. To make a rpm of them, you first have to compile them, write the installation scripts and (hopefully) test them. So if this program has a flaw or is missing a feature you want badly you can do nothing but issue a bug-report or a feature request and hope for the next version. If you have the source chances are the author will write a fix/patch, which you can apply soon.

The following is a quick walkthrough to compile a program

Compiling software from source:

We will be using the Ed editor as an example the latest download can be found at

Download the source files to your hard drive.
Change to the directory that you downloaded to.
The file is called ed-0.2.tar.gz this is the latest as of this writing.
Extract the file using ark right click the file and choose archiving tool.
In the new window that opens choose Action | extract.
Choose the location to extract to and make sure the all button is checked press ok.
In a few seconds this will be completed.
As an alternative you can open a console and type 'gunzip ed-0.2.tar.gz' and then type 'tar xvf ed-0.2.tar'.
The switches for tar mean x=extract v=verbose this lets you see what it is doing and f=file.
Open the file manager and navigate to the location containing the source files.
Press Ctrl + t this will open a console in the current directory.
For the remainder of this I will assume you are working as root.
In the console type './configure' when completed check for any errors.
If there are no errors you will want to type 'make'.
Again check that there are no errors and then type 'make install'.
I highly recomend reading the man page for ed before running it while ed is easy to compile it is not easy to run.
There you have it 90% of all files are compiled this way
make install


Common resources are:, . These are mirrored at many university FTP servers.

3 Other installation methods.

Debian users can check out Havoc Pennington's Debian tutorial 's chapter 16 on dpkg and apt

Debian users should also check out the Debian User's guide located at

Slackware users can take a look at the Linux newbies guide to Slackware packages

No comments: