Compiling programs
From Linux 101, The beginner's guide to all things Linux.
So you are now to the point where you realize that you want a new program on your system, but you're not quite sure how to achieve that.
|
Note: This article deals with how to compile a program from source. That's not the same thing as installing a .rpm or .deb file, or any other distribution-specific method. Later in the course we can discuss these things as well, but some feedback from readers will bring that about. |
Installing programs in Linux is a simple four step process.
Contents |
[edit] Extraction
Follow the instructions on File Compression to extract the file that you downloaded. Most files should extract into a directory of the same name. You can use tab completion to make it easy to change into that directory.
Each package normally ships with an INSTALL or README file. You should always open and at least glance at both files if possible. It will go into exact details for your program or considerations you need to know before proceeding into the next steps.
[edit] Configuring
Each program usually comes with a configure script. You will need to look at the directory listing to see the exact name. The usual name 99% of the time is configure, but sometimes they make it config or Configure. To run it, usually just do:
-
./configure
Various packages can also have optional support for different things. To see a complete list of configuration options, you can run:
-
./configure --help
The default installation directory for configure scripts is in /usr/local. If you would like to change this to /usr, you can use the option:
-
./configure --prefix=/usr
It is always a good idea to read through the output of the configure script. You can get a good feel of what your program requires, and make sure it found support for everything you want the program to do.
[edit] Compiling
After the configuration script completes, it creates a few important files about the settings, and also how to make the program, which is the Makefile it creates. For this step, usually all you need to run is:
-
make
You should see a lot of compiling (running of gcc or g++) and sometimes maybe some helper programs. This could last for several minutes, so you may want to go get something to drink. Compiling can be a time consuming process.
You can tell if it completed successfully if make does not exit saying error. If it does say error, you should seek some additional help from a friend.
Some programs have some tests you can run that ensure a good program was created. These would be documented in the INSTALL file. To run them:
-
make tests
[edit] Installing
After a successful make you can then run:
- #
make install
and your program should install itself where it belongs. Watch the output to see what programs it puts into /usr/bin, since that's the programs you'll be running.
If you are a more cautious person, you can see what would happen in the install by first running:
-
make -n install
|
Note: You must run make install as root since it will attempt to copy files into write-restricted directories. You can use su to do this. |

