Installing software from source

All software programs are built from different files. These files are called source code and are written in programming languages. The most common programming languages that are used on Linux are C and C++.

There are all sorts of reasons that you may want to download and install a piece of software that is distributed as source code. Some of these are as follows:

  • The software isn't available in the Raspbian repositories.
  • The latest version of the software isn't in the Raspbian repositories.
  • The features in the software aren't available in the packages in the Raspbian repositories.

There are a several disadvantages to installing software from source, such as these:

  • Updates aren't automatically installed for any software packages that are installed from source.
  • Additional software is required to compile and install the software. Generally this is the build-essential metapackage.
  • It can take a long time to compile and install software depending on its complexity.

If you find a software package that you want to download and install on your Raspberry Pi, the first thing you need to do is make sure that you have all the required tools to build the application:

  1. The most common tools can be installed after you have installed the build-essential package:
    sudo apt-get install build-essential
    

    This will install all the software tools you need to use to compile most C and C++ applications, including the make application and the gcc and g++ compilers.

  2. Now you need to download the application that you want to install. In this example, we will use the Apache2 web server. You can download Apache2 from http://apache.mirror.serversaustralia.com.au//httpd/httpd-2.4.10.tar.bz2.
  3. You can download the source code using a web browser. Another easy way to download the code is to use the wget application. It automatically downloads a file and stores it in your Raspberry Pi:
    wget http://apache.mirror.serversaustralia.com.au//httpd/httpd-2.4.10.tar.bz2
    

    Once you source code has been downloaded on your Raspberry Pi, you need to extract the software from the archive. An archive is just a file that contains many other files that have been shrunk to make them easier to distribute.

  4. To extract a .tar.bz2 archive such as the Apache2 application, run the following command:
    tarxvfhttpd-2.4.10.tar.gz
    

    The exact command will vary depending on the software that you are trying to install, but will generally be very similar to the command you just used.

These commands will unpack all the files in the Apache2 archive and put them into a folder that contains the entire Apache2 source.

Almost all software packages that you download contain a file inside them, called README.md. This file generally contains instructions that you need to follow to install and build the software.

Here is the normal process you need to follow to build a software package:

  • ./configure
  • make
  • make install

These commands perform lot of processes. Let's start with ./configure. The ./configure command is a script that generates the MakeFile file used by make to compile the software. This MakeFile file is customized to suit your Raspberry Pi. It will also let you know whether there are any other dependencies that you need to install to be able to build the software.

The make command is the command that actually compiles the software from the source code into an application that you can run on your Raspberry Pi. This compilation process will show lots of information as it progresses, and the process may take quite a long time. The Linux kernel can take well over half an hour to compile,so it is probably best to go and grab a cup of coffee!

After the applications have been compiled, you need to install them. Fortunately, most applications include an installation script that does this for you. Simply run make install!

Tip

Just remember that these instructions are generic and that some software packages may need to be installed differently.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset