How-To: Compile Programs From Source in Linux
Reasons to compile
With the prevalence of software available for many distros, why would anyone want to compile software from source? Compiling allows you to custom-fit a program to your particular hardware configuration and CPU architecture, which is useful if a program has no binary that is compatible with your processor. However, this is seldom a problem these days, since most computers now use 32 or 64-bit x86 processors. In the past, Linux enthusiasts often compiled programs from source to wring the greatest possible performance out of their hardware. More recently, this has mostly become a non-issue due to the increases made in computing speed; while compiling may offer a slight performance increase, it is not enough to really make a difference.
Although the introduction of package management on most distros, less diversity in CPU architecture among the user base, and massive increases in hardware speed have largely reduced or eliminated the need to compile software yourself, there are still a few instances where you would have to do so. Although the various official and unofficial software repositories for Ubuntu and other distros include most of the tools that the average user would need for any given purpose, the repositories are not completely comprehensive. Old packages sometimes get dropped and updated versions are often slow to be added. It may also take a release cycle or more for brand-new programs to be included.
While Ubuntu and Debian have “backports” repositories that have fairly new packages in them, many other distros do not have such a resource. For large projects with large community support, the developer may offer nightly builds, but this is not the case for most projects. The only reliable way to get bleeding-edge software (stability issues aside) is to either find a repository that has it or download the source code from the developer and build it yourself.
If you want to be a programmer at some point, you are going to need to know how to compile applications, since that is really the only way to develop your own projects and effectively contribute your own code to open source projects that other people have started.
It is also wise to compile security-oriented software (like encryption tools) yourself. Although binaries are generally trustworthy if they came from an official repository or developer website, you can never really be 100% sure of what you're getting unless you build it yourself. (preferably after a code audit, if you have sufficient skill to do so)
Alternatively, you may find a program you are interested in, but it is not packaged for your distribution (e.g. RPM packages on a DEB-based distro) and there is no native package available for you to use. While there are tools (like alien) that can convert packages from one type to another, the program may not always work correctly after it has been converted.
In such situations, your only real option is to build from source.
Reasons not to compile
Although compiling software from source can solve some of your problems, it can also create new ones. Compiling and installing software from source effectively bypasses your package management system. This means that you must personally do the work that your package management system would otherwise do, such as keeping track of installed software, satisfying dependencies, and even preventing conflicts between different programs. This last situation is where the most can go wrong.
A decent package manager is aware of the specific version of the dependencies that a program needs to run and is able to cross-reference that data with the needs of other programs. This is especially important when updating; if a new version of a program includes dependencies that would break other installed programs, the package management tool should postpone installing the new version until the other programs that would be affected can be safely updated as well. When you compile from source, you are forcing your changes through safeguards meant to help protect your system's software integrity. This can be very dangerous if you have not taken the time to understand and estimate the repercussions this action may have.
Compiling software from source is a useful concept to understand, (or even essential, depending on your aspirations) but it should always be considered a measure of last resort. On most modern distros, there are much better ways to install software, and these should always be used first whenever possible.
This guide will tell you how to compile programs from source on Linux. We will not cover the specifics of building a kernel, but we will teach you how to build individual programs on any distro. Likewise, this guide will not address specialized tools (like emerge) that are found on source-based distros like Gentoo. This guide is intended for fairly advanced users instead of those new to Linux. Some knowledge of the terminal is required due to the way the compiling process works.
Preparation
Before you compile your first program, you must prepare your compiler toolkit. Linux has many compilers and related tools available as part of the GNU Project; these include gcc, (the GNU C compiler) g++, (the GNU C++ compiler) make, (a tool to help automate the build process) and many others. You will probably need to install them yourself (check your distro's repositories) since few distros include them out of the box.
Fortunately, many distros include most of the compiler utilities in a single package so you won't have to install each one separately. (Ubuntu's is called “build-essential”) Unless you are familiar with the language the program is written in, you may not know what compilation tools you will need until you run the configuration script.
Standard procedure
1. First, you must acquire the source code of the program you wish to compile. (this can be found at the developer's website or at an online resource like Sourceforge.) Source code usually comes in archive files called tarballs, identifiable by a tar.gz extension. You should save the tarball to a folder where you have write permission, such as your own home directory. The temp (/tmp) folder is not recommended due to reasons we will address later.
2. Open a terminal and navigate to the directory where you saved the source tarball.
3. Extract the tarball by typing “tar -xvf program.tar.gz”. (obviously, you should substitute program.tar.gz with the real filename) Most of the time, a tarball will create a new folder (this guide will refer to it as the build directory) during the extraction process and will place its contents in there.
4. Navigate to the build directory.
5. The build directory may have many files and subfolders in it, but the first thing you should look for is a file called “configure”. For a moment, you should compare the software compilation process to cooking. Before you start making dinner, you need to know what goes into a recipe, (and the cooking instructions) or the dish will turn out wrong. The configuration script is like a grocery list; it makes sure that you have everything you need before the compilation process begins.

![]()
Greethn
December 09, 2010 at 3:26am
I want to know what you're running for the terminal in the screenshots. Contest Programming
![]()
Lykopis
June 07, 2010 at 6:21pm
Yeah: I fail to see why M$-Windows users complain about Linux.
You made your decision to use M$-Windows, just as us Linux users made the decision to use Linux.
Most of us know how to find the codecs to play encrypted dvd's and music codecs not packaged in the distro.
They are missing for legal reasons, but can be found and used if legal in your country.
Linux is not good at windows gaming, but has lots of opensource games you can use.( I am not gamer anyway)
If something isn't there or don't work right I can build a package for it, but in M$-Windows forget it.
Modern Linux systems I find just as easy to use as a M$-Windows system, as far as point and click goes.
Last but not least ----Linux is not Windows----
![]()
verilitas
March 30, 2009 at 3:47pm
The only thing that I would ever want to write a program for is DVD playing. I'm a nube at Linux. When I found out that I could not run a DVD on ubuntu linux, I started using microsoft much more. I even tried using a DVD player designed for windows in wine, and I had no luck. Puppy Linux was a good dog, and it played DVD's. However, it always seemed to have a poor digital quality to it as though I were watching an abridged video file.
And my old video card would not work with ubuntu linux at all. Needless to say that was a problem that I couldn't fix from inside the OS.
![]()
EccentricEgg
March 26, 2009 at 1:14am
while compiling may seem simple to the Linux crowd, it serves as another insignificant (thanks to package managers) but daunting task completely foreign to the Windows (and to a lesser extent Mac) group. i like the idea and power of Linux but find that i need volumes of information to do in Linux what is a matter of a few clicks under Windows. i don't program (other than the occassional automation script) and GIMP, Firefox, Opera, OpenOffice, and Notepad++ are available for Windows so for me other than OS price, there is not a Linux-only app or must-have feature that is worth the hours of reading and countless headaches i would endure to get to the same level of comfort with Linux as i have with Windows.
now this may seem like i'm bashing Linux but really i'm just trying to help the Linux folks get the elusive handle on what keeps people from leaving the overpriced, buggy, bloatware that is Windows. Out-of-the-box idiot-proof Usability. i must say i agree with December 2008 THE LIST "Seven Things That Can Help Linux Overtake Windows" item #2 "Configure the OS without a text editor. Requiring manual configuration of the Xorg.conf file is inexcusable in 2008." BUT i think that ALL cofiguration should always and forever be possible from the console even as graphical controls with ample idiot-proof help become ever more available. in Linux the console and text files are KING get used to it.
and for anyone wondering, i've installed Linux in various forms and flavors dozens of times over the past 10 years but have yet to keep it more than a week or two before losing interest due to the problems noted above. alas, i will sometime in the next few months (i hope) have time to once again try to make the jump to Linux (probably LinuxMint) since i refuse to buy another MicroSoft OS. My beloved XP Pro is getting a bit long in the tooth and i won't be buying a new rig for a few more years so i think, headaches aside, Linux will be the way to go.
sometimes i really miss MaximumLinux
Just my long-winded 2 cents :)
"My deep regret is some people are so deeply entrenched in their own world views that they will simply not countenance alternatives."-Alister E. McGrath
"America didn't become the great nation it is by suppressing ideas it progressed by allowing freedom of speech and freedom of inquiry."-Ben Stein
"It is my belief that unless we afford others in our friendships the possibility to disagree with our views no real learning and thereby no growth can take place. Whether or not I agree, if I do not at least truly consider the opposing view I have no basis to contrast or question my own suppositions. To blindly choose a position without comparing the merits and faults of that and other positions honestly is utter hubris and ultimate folly."-EccentricEgg
![]()
rayatwork05
March 17, 2009 at 4:27am
unixfool, i see how that would be useful if you use programs that crash alot...however none of my windows programs have problems...and i cant imagine any more benefit that could come out of them...IE, Steam & games, Photoshop, etc....they are already fast, powerful, error free, and easy to install/use.
for developers, yes linux is the way to go.
![]()
unixfool
March 13, 2009 at 2:08pm
I don't understand why Windows nazis always attempt to dictate how Linux should be...
Compiling source is only complicated when you don't do your homework. Sure, Windows guys don't have to compile, but I certainly love the option of being able to optimize a piece of software if I want...Windows users don't have that option, but then again, why are they complaining about it?
Linux users have the option of submitting bug reports or even delving into the code itself and either fixing it or pointing out errors to the dev teams of a software package. Empowering yourself with knowledge serves everyone much better than whining, though.
![]()
rayatwork05
March 12, 2009 at 5:09am
im computer savvy and went for linux recently (openSUSE), the first thing i wanted to do was play my games via steam.
it was harder then it should have been, and havnt been back to linux since. if i cant do something that simple, neither can a laymen. its much easier to double click a file i download and click next,next,next, finish.
therefore linux needs to get over itself, get past that, before it can be widely adopted by the masses.
![]()
botticelli
March 12, 2009 at 12:55am
After reading the above article, compiling seems easy; at least the steps are, if one does not run into problems. I would like to have a go at it.
Can anyone please suggest a relatively easy program that can be used with the above instructions as "my first compiling exercise" sort of thing?
![]()
redilyn
March 12, 2009 at 7:18pm
You would try to compile The Mana World.
It is pretty easy but you will likely have to resolve some depedencies which should be good pratice.
http://themanaworld.org/downloads.php
*hint* If you have trouble with dependencies and are using ubuntu or a derivative of ubuntu try the following command in the terminal (may also work for other distros).
sudo apt-get build-dep tmw
---------------------------------------
"In a world with no walls or fences, who needs Windows or Gates?"
"Linux is evolution, not intelligent design." - Linus Torvalds
![]()
amacieli
March 11, 2009 at 2:33am
don't forget to tell them about the option in make to use all of your cores to do compilation so much faster. -i5 i think it was. perfect for larger builds.
![]()
MeTo
March 10, 2009 at 1:37pm
This is what keeps people away from linux.
"Also, keep in mind that many programs are notoriously hard to compile,
even for experts. (OpenOffice.org is a prime example) This experience
can be very frustrating, but persistence is the only way to get through
it."I hate to say it but i guess i will stay with Microcrap.
![]()
compro01
March 11, 2009 at 8:31am
Compiling from source is rarely required.
If anything, application management on a modern linux distro is nicer than it is on windows due to having a central package manager.
![]()
redilyn
March 10, 2009 at 7:07pm
"This is what keeps people away from linux."
This is only true
if you have not done any research. You are assuming that all linux
distros would require you to compile from source to get the newest
version of an app.When using a distro which includes advanced
package manaqment tools such as ubuntu, compiling from source is almost
never required. For example, the newest version of open office can be
install from debs (using apt-get) simply by adding a new repo to your
sources list.Personally I don't care what OS anyone uses but it
is annoying when people lump all linux distros together because
they are based on the linux kernel. That is just foolish.
![]()
MeTo
March 11, 2009 at 7:46am
"This is what keeps people away from linux."
"This is only true
if you have not done any research. You are assuming that all linux
distros would require you to compile from source to get the newest
version of an app.When using a distro which includes advanced
package manaqment tools such as ubuntu, compiling from source is almost
never required. For example, the newest version of open office can be
install from debs (using apt-get) simply by adding a new repo to your
sources list.Personally I don't care what OS anyone uses but it
is annoying when people lump all linux distros together because
they are based on the linux kernel. That is just foolish."Well when all those fancy distroes don't work right where do you have to go down to the kernal it's worse than the old DOS day's. That is why Linux is dying breed. IMHO
![]()
redilyn
March 11, 2009 at 11:15am
"Well when all those fancy distroes don't work right where do you have
to go down to the kernal it's worse than the old DOS day's. That is why
Linux is dying breed. IMHO"When your fancy windows doesn't work where do you go? To your windows cd.
When your fancy linux distro doesn't work where do you go? To your distro's livecd.
Nuff said.
"In a world with no walls or fences, who needs Windows or Gates?"
"Linux is evolution, not intelligent design." - Linus Torvalds
![]()
Hg Dragon
March 10, 2009 at 12:39pm
I want to know what you're running for the terminal in the screenshots.
![]()
redilyn
March 10, 2009 at 6:43pm
Looks like the default ubuntu terminal with the background and text color changed.
![]()
Hg Dragon
March 11, 2009 at 8:13am
By default the Ubuntu terminal window is black text on a white background. There is no emphasis on different files or directories. They've either loaded a replacement terminal or tweaked it to color-code different objects/commands in the window.
![]()
Will_kraft
March 11, 2009 at 10:22am
Actually, all I did was change the text color and background on the standard GNOME terminal. (I like green-on-black better than the standard black-on-white) I've also aliased my ls to 'ls --color=always'.














