Visit Jeremy's Blog.
Go Back > Linux Answers > Applications / GUI / Multimedia
User Name


By jeremy at 2003-07-09 20:24
Sooner or later when using Linux you will hear the term "compile from source". This can be intimidating the first time you hear it, but once you understand what it is and how it works you will find it is actually quite simple. You may ask yourself why you would want to use source when there are package management systems like rpm and apt. While these tool do make things easy, there are a few drawbacks to using them. First you have to depend on someone to actually do the packaging. This means when a new version comes out you may not be able to install it until the package is updated. You can always go grab the source. Packages are also compiled to the lowest common denominator. Options that many people may need are enabled and all others are disabled. This means that if the feature you want isn't compiled into the package or you want things installed to fit your system exactly source is the only option.

To compile a program from source you do need a few things. Some distros call this the development package. Minimally you will need make, a compiler (usually gcc), the appropriate libraries and a few other basic programs. If you encounter any problems the error message should tell you what you are missing. After correcting the problem you may need to delete the file called config.cache before configure will recognize your changes.

We are now ready to install a basic program. The first thing you need to do is download the source. For this article the program we are installing will be called LinuxQuestions. You will want to download the source to the following directory: /usr/local/src (in this case the filename is linuxquestions.tar.gz). Once downloaded you want to do the following:

tar zxf linuxquestions.tar.gz
cd linuxquestions
make test (optional)
make install
The first command will unzip and untar the downloaded file. You will then need to change into the appropriate directory. Most standard packages will be installed using the ./configure && make && make install process. You should always read the packages instructions which will usually be found in either README or INSTALL. By running ./configure you are doing two basic things: 1) letting the program detect if you have everything it needs installed and where it is 2) telling the program what options you would like it compiled with. The options in questions can range from just a few to literally hundreds. Running
./configure --help | less
will allow you to see the available options. Once configure runs through and you have verified that there are no errors you can continue with make. This step does the actual compiling of the program. Depending on what program you are compiling and the machine you are on this can take anywhere from a few seconds to a few hours. The make test step is optional, but it is a good practice to get into. It will verify that everything is ok and the program operates properly. It should be noted that all steps up to now should be performed by a normal non-root user. The last step however needs to be executed with root permissions. It needs to be run as root as this step will actually copy the compiled programs to your system. If you made it this far you should be able to run the program just as any other program installed on your system. If you ever need to recompile a program you should do a make clean (or make distclean) before doing so. This will delete files created during the previous compile and give you a clean tree.

One notable exception to the previous instructions is perl programs. To install perl programs from source (you can also use CPAN) you need to do the following:
tar zxf linuxquestions-perl.tar.gz
cd linuxquestions-perl
perl Makefile.PL
make test (optional)
make install
You will notice that many of the steps are the same with the notable exception of ./configure vs. perl Makefile.PL.

If you ever encounter problems compiling from source the error should clearly state what you are missing or why it is failing. If you need to post to remember to post the complete error message you are getting and what steps you took.

by Vlad_M on Sun, 2003-07-13 10:19
A most helpful article, however I would really like to see an article on how to compile on any RH version, since they seem to make it their mission to create a distro where compiling anything is impossible.

by MasterC on Sun, 2003-07-13 10:33

The trick to compiling on ANY distro is to have the development packages installed, this would be things like GCC, make, binutils... The reason RH and some of the other RPM based distros tend to leave these out is because they provide RPMs and would expect you to use those RPM's provided. It's just a different way of thought. They still do provide the GCC et al tools, you just have to install them yourself, or rather, knowingly install them.

That's where the trick comes in


by JZL240I-U on Tue, 2003-07-15 02:27
Just two brief remarks:

tar zxf linuxquestions.tar.gz
shouldn't that be tar -zxf linuxquestions.tar.gz, i.e. the minus before the options is missing? Or isn't it necessary here?

And secondly, after a long time of experiments I found out, that some programs expect to be placed in special places in the directory tree. Then one has to specify e.g.

./configure --prefix=/opt/kde3
to get the executable (?) placed correctly (in this case in /opt/kde3). See also this thread ./configure - make - make install can't work ?!?.

P.S.: Why don't I get those nice lines before and after "code"?

Hehe, now it works. Nice.

by MasterC on Tue, 2003-07-15 04:46
Use the [ code ] brackets without the space

And no the - isn't necessary.


by JZL240I-U on Tue, 2003-07-15 04:52
Originally posted by MasterC
Use the [ code ] brackets without the space
I copied from the original article via CTRL-C / CRTL-V ...

by mlstevenson on Tue, 2003-07-15 17:01
I found your article informative. But, I don't understand how to remove a program, how to uninstall it when it is no longer wanted.

by MasterC on Wed, 2003-07-16 01:06
That's the tricky part as with source there is no "set" way. You can look into a program called checkinstall:

This is probably considered as close as it gets to "make uninstall". Which brings me to my next point:
make uninstall
This is sometimes an option that the programmers will put into the Makefile. If they do, lucky you, all you have to do is type that when you are ready to remove the program and you are done.

The main reason for sources not having a universal way of being removed is that during the make install process they are simply copied over to the necessary locations. If the developer didn't write a make uninstall to rm everything from those locations, there is no way for your system to track them (without something like checkinstall).

Other options are available for things like this, check the LFS forum on this board for more info.


by moses on Wed, 2003-07-16 02:10
I hope I don't say anything so harshly that it offends, it's not meant to.
I ASSume that this is geared toward people who have never installed from source, so I'm critiquing it as such.

Once downloaded you want to do the following:

tar zxf linuxquestions.tar.gz
cd linuxquestions
I disagree with the ordering.
The first thing you want to do is read the README (or equivalent) file and learn what special needs this program has (libs, make arguments, env vars, maybe it doesn't use autoconf, etc.). I guess this would be the second thing, after untaring the package.
The next thing you want to do is follow the instructions in the README on how to build the package. While autoconf is quite popular, it's not the only way to build and distribute a source package.
In the HOW-TO, the note about the README and INSTALL files seems a little lost. Basically, I think that needs to be more obvious and expanded upon.

After reading the README, ./configure --help should be, in my opinion, run. Again, this is mentioned in the HOW-TO, but most READMEs don't actually say much about all the possible options, and the best way to see what you have available to you is via configure (if that's even available).
The user should learn as much as possible about the package they are installing before they jump in and start dealing with error messages because, "bash: ./configure: No such file or directory".

Non-uid0 users can't usually write to /usr/local/src, so maybe you should recommend a "sandbox/src" directory under their home dir for downloading and building packages. Or, one would have to change permissions on /usr/local/src. I have both a ~/sandbox and a /opt/src directory available to normal users. /opt/src is for global packages, and ~/sanbox is my personal playground. Non root can write to /opt/src, of course.

Maybe mention that ./configure --with-blah can enable option blah that wouldn't otherwise be enabled.

You might also consider recommending checking MD5 sums if they exist. This will help to bypass any problems with long downloads, noisy lines, cracked hosts, etc.

Just a few of my comments, I'm sure I could come up with more. . . I like it so far, but it does need work--it's always great to have a start.

by DavidPhillips on Fri, 2003-07-18 16:34
be carefull with "make uninstall"

If it is improperly made it can delete a lot of files you need.
There is on such program I have seen.
I believe it was an issue with one of the sources used in LFS 3.?

by asktoby on Tue, 2003-07-29 07:03
Great article. Left me with a few questions though:

I have been untar-ing my source files in random directories inside my Documents folder and compiling from there, rather than using /usr/local/src. Apart from being a little messy, is there any harm in doing that?

Once the (./configure, make, make install) process is complete and the app is working correctly, can you safely delete the source files?

Is there any need to close all open apps before installing?

Is there any need to re-boot after installing?

Must you install as root or can you install as anyone?


All times are GMT -5. The time now is 10:16 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration