In this day modern day, most software installations can be done using repositories and package managers. However, you might face a situation of having only the source files availalble with you – you probably would want to try out bleeding edge software, which hasn’t been packaged yet, or isn’t available in the repos yet.
So if you really want to try it out, then the only way would be to download the source files and compile them.
Contrary to what most people think – Compiling from sources isn’t that complicated – the entire process takes 3 commands.
Let’s have a look at each of these steps now.
Before you start compiling, you need to extact the source files, as most of them come as either tar(.tar), gzipped tar(.tar.gz , .tgz) or as bzipped tar file(.tar.bz2). Any decent archiver should extract it. You can do it via the command line by typing
tar xvfz package-name.tar.gz (for gzipped files) or
tar xvfj package-name.tar.bz2 (for bzipped files)
You should also have the required header files(kernel header files, tools such as gcc, make, bison etc). Don’t worry, if you’re missing any one file the configure step will tell you something is missing.
Let’s now get to the compiling stage.First cd to the directory where you extracted the files by typing
Yes, the “.” is there. This step just checks your system and assigns values for system-dependent variables. These values are used for generating a Makefile. The Makefile in turn is used for generating the actual binary.
When you run the configure script, you’ll see a bunch of weird messages scrolling on your screen. This is normal and you shouldn’t worry about it. If configure finds an error, it complains about it and exits.
For example, here’s a snippet of the messages that might be flowing
checking dynamic linker characteristics… GNU/Linux ld.so
checking whether to build static libraries… no
configure: creating libtool
checking for ppoll… yes
checking for pkg-config… /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0… yes
checking for BLUEZ… yes
checking for GLIB… yes
checking for GMODULE… yes
checking for dlopen in -ldl… yes
If some file or library is missing, you’ll get a message like
checking for DBUS… no
configure: error: D-Bus library is required
If all is fine,the configure program will exit gracefully, like this
config.status: creating test/Makefile
config.status: creating scripts/Makefile
config.status: creating config.h
config.status: executing depfiles commands
Next, we issue the make command,
This will do the actual build and compile of the sources. Again you’ll see a bunch of weird messages flowing by the screen(geek porn! :P ) and once done, you’ll fall back to the prompt. Again if some error has occurred you will be notified
The final step, is to install the binaries and the libraries that were built in the above step. This requires root privileges. So for that su to root and and issue the make install command
That’s it! You’ve successfully compiled the program from its source and installed it. Easy isn’t it?
- The package will contain a README or an INSTALL file. It’s recommended that you read it before you start compiling, so that you might be spared of some nasty surprises
- Uninstalling programs installed by the above step is tricky, you can’t use package managers to remove them. For that you’ll have to cd to directory where you installed it from and issue make uninstall. For this reason I recommend, that you keep a separate directory for storing all these “compile-from-source” type of files