How to Install Linux programs from Source Code
Even with default package managers like apt-get and yum, there are times when you have to build packages from sources. Most common scenario is that the latest version of program is not yet available in a packaged version or when you need to control the compile time options that come with the program.
Preparing the System for Compiling
Before you can proceed with compiling programs on your system, you will need a compiler, libraries and some other basic utilities. Some of the common programs required for most of the programs are:
- GNU coreutils : The GNU Core Utilities are the basic file, shell and text manipulation utilities of the GNU operating system. These are the core utilities which are expected to exist on every operating system. Previously these utilities were offered as three individual sets of GNU utilities, fileutils, shellutils, and textutils. Those three have been combined into a single set of utilities called the coreutils.
- GNU binutils - The GNU Binutils are a collection of binary tools. The main ones are ld ( GNU linker ) and as ( GNU assembler )
- Gcc - GCC stands for “GNU Compiler Collectionâ€Â. GCC is an integrated distribution of compilers for several major programming languages. These languages currently include C, C++, Objective-C, Objective-C++, Java, Fortran, and Ada.
- Make - Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files. Make gets its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from other files. When you write a program, you should write a makefile for it, so that it is possible to use Make to build and install the program.
- GNU tar/gunzip/bunzip2 – These are archiving utility generally used to unpack source tarballs. These are generally in format of .tar, .tar.gz or bz2.
Step1: Get Source
In this example, we are going to install the latest version of NMAP released a few weeks back. We get the source from ..dist/nmap-4.20.tar.bz2 which is the current version. The latest rpm version available at this time was nmap-4.11 version.
To do this, I created another directory “nmap†and used wget to get the latest tarball as shown in the screenshot below.

Step 2: Unzip the Source Tarball
Now we unpack (unzip) the tarball by using the tar command. Since this tarball has a .tar.bz2 format we will use the command line options “tar –xvjf _filename_†where x stands for extract, j tells it’s a bunzip file (bz2) , v means verbose and f is followed by the filename of the tarball.

This will extract the source code for nmap-4.20 into a folder.
Step 3: Run Configure Script
On different systems, the compiler and other libraries might be in different place than a regular Linux system. For example, you may be different type of bash than other users. Configure program creates a MakeFile which will be later used by make program.
Configure is basically a shell script generally written by GNU Autoconf, which looks at your system settings and tries various things to figure out what works. It takes instructions from MakeFile.in and builds a MakeFile which it thinks would work on the current system.
You can view various program options by running "./configure --help"

On my system I don’t want to install NMAPFE (the front-end for nmap) so I am going to run the configure command again with appropriate options.

Once the configure command finishes, it creates a Makefile which will be used by make program to create binaries of nmap program. Let us now see what configure added to our Makefile which was not there earlier.
[root@localhost nmap-4.20]# diff Makefile.in Makefile
4,11c4,11
< NMAP_PLATFORM=@host@
< prefix = @prefix@
---
> NMAP_PLATFORM=i686-pc-linux-gnu
> prefix = /usr/local
48,49c48,49
< TARGETNMAPFE=@TARGETNMAPFE@
< INSTALLNMAPFE=@INSTALLNMAPFE@
---
> TARGETNMAPFE=
> INSTALLNMAPFE=
The last change shows that it removed NMAPFE, since I use --without-nmapfe in my configure option.
Step 4: Use Make Command
Make utility requires a file named Makefile in the same directory in which you are the command. In our case, the MakeFile has been created by using configure script which we will now use to run make command.
Make command uses the directions present in the Makefile and proceed with the installation. The Makefile indicates the sequence, which it must follow to build various components of nmap. This sequence depends on the way the software is designed by its coder.
Now lets run the make command in nmap folder.

Make command generally takes a while, once complete it will compile nmap’s source code and creates the executables. At this point you can use the nmap program from this folder by just typing ./nmap.
Step 5: Run Make Install
When make is run without any parameters, it starts reading instructions from MakeFile from the start and start compiling code. However, when you run `make install` the make program reads the install label from Makefile and executes only that section of the makefile.
install-nmap: $(TARGET)
$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1 $(DESTDIR)$(nmapdatadir)
$(INSTALL) -c -m 755 -s nmap $(DESTDIR)$(bindir)/nmap
$(INSTALL) -c -m 644 docs/$(TARGET).1 $(DESTDIR)$(mandir)/man1/$(TARGET).1
$(INSTALL) -c -m 644 docs/nmap.xsl $(DESTDIR)$(nmapdatadir)/
$(INSTALL) -c -m 644 docs/nmap.dtd $(DESTDIR)$(nmapdatadir)/
$(INSTALL) -c -m 644 nmap-services $(DESTDIR)$(nmapdatadir)/
$(INSTALL) -c -m 644 nmap-rpc $(DESTDIR)$(nmapdatadir)/
$(INSTALL) -c -m 644 nmap-os-fingerprints $(DESTDIR)$(nmapdatadir)/
$(INSTALL) -c -m 644 nmap-os-db $(DESTDIR)$(nmapdatadir)/
$(INSTALL) -c -m 644 nmap-service-probes $(DESTDIR)$(nmapdatadir)/
$(INSTALL) -c -m 644 nmap-protocols $(DESTDIR)$(nmapdatadir)/
$(INSTALL) -c -m 644 nmap-mac-prefixes $(DESTDIR)$(nmapdatadir)/
Install section instructs make to copy files created in previous step to final directories. For example, executables are copied into /usr/local/bin. When we ran only make the executables were created in the same folder where we unzipped the tarball. So, now when we run make install, these executables are copied to their final destinations.

Tip: Keeping a log of what was installed by the program
Many good programs provide you with `make uninstall` section to easily uninstall the program and its executables from the system. If not provided, you can use this tip to find what was installed when you ran `make install`.
Before running `make install`, run the following command on your system. This will create a big list of all files that exist in your system except the following directories: /proc , /tmp and /dev. These directories are transient and not used when installing programs so we can ignore them.

After running the `make install` again run the same command and create a post-install list. Then you can run diff between these 2 files and it will show you list of all the files that were installed during nmap installation.

I hope this basic tutorial helps you, feel free to ask any questions.

A question I've always had
I really enjoyed this post. I knew the concept, but the supporting details are quite helpful. One thing I've always wondered about; once you've installed a program from source, is it safe to delete the files you've inflated/unpacked?
What I mean is, let's say you use `tar -xvjf` to inflate a file into /tmp, and at the end you use `make install` to copy the binaries to places like `/usr/local/bin` and all that. Can you then go back into /tmp and delete the source code and compiled binaries? That should be okay, right?
Deleting Source Tarballs
IMHO, once you have installed the program from its source code then its safe to delete the source-files. Since, make install would transfer all the required files into their appropriate places.
It may make sense to keep your Makefile as it will show you what configuration settings you used and might come handy when you want to uninstall the program or maybe move to another version.
./configure: no such file or directory
What to do if ./configure gives error: ./configure: no such file or directory? There is no configure/config files in the tar.gz. However, there are these other files config.guess, config.sub, configure_osx which don't run?
This is while trying to install mysql-gui-common source distribution.
AutoGen
IIRC, mysql-gui-common comes with autogen.sh. Try using
./autogen.sh
make
make install
Hope This Helps
mozilla firefox and no ./configure ?
How can I install this Mozilla Firefox? I just tar and gunzipped it, tried the ./configure but had the same problem as above. Then I tried the .sh file and it did the following. Do you have any other ideas?
dv041:/uhome/nskitt/Firefox/firefox> ll
total 13676
-rw-r--r-- 1 nskitt nskitt 232 Feb 20 04:25 browserconfig.properties
drwxrwxr-x 3 nskitt nskitt 4096 Mar 13 10:25 chrome
drwxrwxr-x 2 nskitt nskitt 8192 Mar 13 10:25 components
drwxrwxr-x 5 nskitt nskitt 4096 Oct 26 11:34 defaults
drwxrwxr-x 2 nskitt nskitt 4096 Mar 13 10:25 dictionaries
drwxrwxr-x 5 nskitt nskitt 4096 Oct 26 11:34 extensions
-rwxr-xr-x 1 nskitt nskitt 5247 Feb 20 04:25 firefox
-rwxr-xr-x 1 nskitt nskitt 10534708 Feb 20 04:25 firefox-bin
drwxrwxr-x 2 nskitt nskitt 4096 Mar 13 10:25 greprefs
drwxrwxr-x 2 nskitt nskitt 4096 Mar 13 10:25 icons
drwxr-xr-x 3 nskitt nskitt 4096 Oct 20 15:23 jre1.5.0_07
-rw-r--r-- 1 nskitt nskitt 476 Feb 20 04:26 libfreebl3.chk
-rwxr-xr-x 1 nskitt nskitt 231468 Feb 20 04:26 libfreebl3.so
-rwxr-xr-x 1 nskitt nskitt 627004 Feb 20 04:25 libmozjs.so
-rwxr-xr-x 1 nskitt nskitt 176716 Feb 20 04:25 libnspr4.so
-rwxr-xr-x 1 nskitt nskitt 430608 Feb 20 04:26 libnss3.so
-rwxr-xr-x 1 nskitt nskitt 260832 Feb 20 04:26 libnssckbi.so
-rwxr-xr-x 1 nskitt nskitt 15304 Feb 20 04:25 libplc4.so
-rwxr-xr-x 1 nskitt nskitt 8240 Feb 20 04:25 libplds4.so
-rwxr-xr-x 1 nskitt nskitt 138316 Feb 20 04:26 libsmime3.so
-rw-r--r-- 1 nskitt nskitt 476 Feb 20 04:26 libsoftokn3.chk
-rwxr-xr-x 1 nskitt nskitt 309624 Feb 20 04:26 libsoftokn3.so
-rwxr-xr-x 1 nskitt nskitt 155560 Feb 20 04:26 libssl3.so
-rwxr-xr-x 1 nskitt nskitt 94924 Feb 20 04:25 libxpcom_compat.so
-rwxr-xr-x 1 nskitt nskitt 698672 Feb 20 04:25 libxpcom_core.so
-rwxr-xr-x 1 nskitt nskitt 9240 Feb 20 04:25 libxpcom.so
-rwxr-xr-x 1 nskitt nskitt 8284 Feb 20 04:25 libxpistub.so
-rwxr-xr-x 1 nskitt nskitt 10336 Feb 20 04:26 mozilla-xremote-client
-rw-r--r-- 1 nskitt nskitt 112 Feb 20 04:25 old-homepage-default.pro perties
drwxrwxr-x 2 nskitt nskitt 4096 Mar 13 10:25 plugins
-rw-r--r-- 1 nskitt nskitt 177 Feb 20 04:25 readme.txt
-rwxr-xr-x 1 nskitt nskitt 2257 Feb 20 04:25 removed-files
drwxrwxr-x 6 nskitt nskitt 8192 Mar 13 10:25 res
-rwxr-xr-x 1 nskitt nskitt 10492 Feb 20 04:25 run-mozilla.sh
drwxrwxr-x 2 nskitt nskitt 4096 Mar 13 10:25 searchplugins
-rwxr-xr-x 1 nskitt nskitt 67496 Feb 20 04:26 updater
-rw-r--r-- 1 nskitt nskitt 145 Feb 20 04:25 updater.ini
drwxr-xr-x 3 nskitt nskitt 4096 Oct 20 15:44 updates
-rwxr-xr-x 1 nskitt nskitt 21368 Feb 20 04:26 xpicleanup
dv041:/uhome/nskitt/Firefox/firefox> firefox
firefox: Command not found.
dv041:/uhome/nskitt/Firefox/firefox> xemacs firefox
dv041:/uhome/nskitt/Firefox/firefox> ./run-mozilla.sh
run-mozilla.sh: Cannot execute .
dv041:/uhome/nskitt/Firefox/firefox> make
make: *** No targets specified and no makefile found. Stop.
Post new comment