Ubuntu and other Linux
distributions have extensive package repositories to save you the trouble of
compiling anything yourself. Still, sometimes you’ll find an obscure
application or a new version of a program that you’ll have to compile from
source.
You don’t have to be a programmer
to build a program from source and install it on your system; you only have to
know the basics. With just a few commands, you can build from source like a
pro.
Installing the
Required Software
Installing the build-essential package in Ubuntu’s package
repositories automatically installs the basic software you’ll need to compile
from source, like the GCC compiler and other utilities. Install it by
running the following command in a terminal:
$sudo apt-get install build-essential
Getting a Source
Package
Now you’ll need your desired application’s source code.
These packages are usually in compressed files with the .tar.gz or .tar.bz2
file extensions.
As an example, let’s try compiling gawk from source.
Locate the program’s .tar.gz or .tar.bz2 file and save it to your
computer.( You can also use wget utility to download)
$ wget http://ftp.gnu.org/gnu/gawk/gawk-4.1.1.tar.xz
A .tar.gz or .tar.bz2 is like a .zip file. To use it, we’ll
have to extract its contents.
Use this command to extract a .tar.gz file:
tar -xzvf file.tar.gz
Or use this command to extract a .tar.bz2 file:
tar -xjvf file.tar.bz2
eg: $ tar xvf gawk-4.1.1.tar.xz
Resolving
Dependencies
Once you’re in the extracted directory, run the following
command:
./configure
Once ./configure completes successfully, you’re ready to
compile and install the package.
Compiling and
Installing
Use the following command to compile the program:
$ make
After this command finishes, the program is successfully
compiled — but it’s not installed. Use the following command to install it to
your system:
$ sudo make install
That is it! You have successfully compiled and installed
AWK. Verify it by executing the awk command as follows −
$ which awk
Comments
Post a Comment