How to compile a program from source


This is a small introduction to how you install programs from tar.gz.

First you need the sources.  I usually download to /usr/local/src.
In /usr/local/src check what the file contains with "tar -tzf <filename>".
If it looks ok unpack it with "tar -xzf <filename>".
Enter the directory.

Read the docs... it might be a  README, INSTALL, README*, INSTALL*.

Often it you use autoconf. Do "./configure --prefix=/usr/local/<younameit>".
If configure works compile it "make".
Then if make works install it "make install".

Now you want your binaries accessable in your path.
Do "ln -s /usr/local/<younamedit>/bin/* /usr/local/bin". This will create symlinks to the binaries.
You may also want to add the sbin-dir "ln -s /usr/local/<younamedit>/sbin /* /usr/local/sbin".

Then you want to get access to the manuals.  Eg in /etc/profile add :/usr/local/<younamedit>/man to the MANPATH variable.-

Perhaps you have some dynamic-libraries that need to be added to ld.so.conf.
Add the dir to /etc/ld.so.conf and run "ldconfig"


Quick example

cd /usr/local/src
wget http://somehost/prog.tar.gz
tar -tzf prog.tar.gz
tar -xzf prog.tar.gz
cd prog
less README
less INSTALL
export CFLAGS='-march=i686 -O2'
./configure --help |less
./configure --prefix=/usr/local/prog
make
make install
ln -s /usr/local/prog/bin/* /usr/local/bin
ln -s /usr/local/prog/sbin/* /usr/local/sbin
echo "/usr/local/prog/lib" >> /etc/ld.so.conf

Author Per-Olof Pettersson