Learning Raspbian (2015)
Chapter 5. Installing Software on Raspbian
The primary purpose of an operating system is to provide a consistent software platform, regardless of the underlying hardware. Once the operating system is installed, it can be expanded with many other software packages.
Raspbian is a good example of a Linux-based operating system. As Raspbian is based on Debian, it has access to its huge software repository. Raspbian initially had access to over 35,000 different software packages in the Debian repositories, but this number keeps growing.
Debian Wheezy, on which Raspbian is based, doesn't officially support the older ARMV6 CPU in the Raspberry Pi. During initial development of Raspbian in 2012, the developers spent a huge amount of time recompiling the vast collection of software in the Debian repositories for the ARMv6K architecture to get maximum performance out of the Raspberry Pi.
This chapter runs through several different methods of installing software on your Raspberry Pi.
Package management in Linux
There are many different tools available to manage software on a Linux distribution. Some of these include the APT and RPM package managers.
Raspbian uses the Advanced Packaging Tool, also known as the APT. The APT handles the dependencies of any package. Installation and removal of software packages are handled by an application called dpkg. It is the recommended way to install any software on your Raspberry Pi. Every part of Raspbian is bundled into a package.
The APT can automatically download the software that you want to install from repositories that are preconfigured. A repository is a collection of precompiled software that can be installed. These repositories are automatically selected, based on your location, to maximize download speed. It also automatically handles updates of all the software packages that are installed on your Raspberry Pi. The APT was first released in 1998 and is often hailed as one of Debian's best features.
Methods of installing software
There are several different ways to install software on your Raspberry Pi. These include:
· GUI Package Manager
· Raspberry Pi Store
· The source
All of these methods, with the exception of installing from source code, use APT and dpkg to install the software package.
dpkg is a software application at the center of Raspbian's software package management system. It is a software tool that actually installs a software package from a .deb file.
A .deb file contains three different parts:
· A Debian-binary file that contains the version of dpkg needed to install the package
· A control archive that has all the information needed to install the package
· A data archive that contains the actual software itself
dpkg reads the .deb file and determines whether all of the required software is installed. If the required software isn't installed, it will let you know what the required software is.
The APT is a frontend tool that makes using dpkg a lot easier. It is preconfigured with several repositories that contain every official package that is available to be installed on your Raspberry Pi.
These repositories are split into several different archives or groups, depending on what software packages are contained in each. It is also extremely easy to add other third-party repositories.
The main archive
The main archive contains all of the software that makes up the Raspbian distribution. If the package is not in the archive, it is not considered a part of the Raspbian distribution. No packages in this archive require any software that is outside it. The Debian project requires that all packages in this archive should be free and can be distributed, modified, and shared freely. The software in this archive is supported by the Debian project.
The contrib archive
Any package that requires other packages that aren't part of the main archive is included in the contrib archive. The contrib archive may also contain wrapper packages and other pieces of free software that work with non-free software.
The non-free archive
Any other software that does not comply with the Debian project's guidelines for free software is included in the non-free archive. Other pieces of software that have problems that may affect their free distribution are included in the archive as well.
The official Raspbian repositories are signed with a digital signature to ensure that the package does not get corrupted when it is downloaded. This is achieved using public key encryption and a digital certificate to prove that the packages in the repository are from who they say they are.
Using the console
The most common way to install software on your Raspberry Pi is by using apt-get. It is a very powerful command-line application.
To run apt-get, you need to use the command shell. The command shell is available for you through an application that is installed in Raspbian by default. The application is called LXTerminal.
You can launch LXTerminal by double-clicking on its icon on the desktop.
LXTerminal allows you to run commands using the bash command shell (and other command shells if desired). You will learn more about the bash shell in Chapter 6, The Console.
Generally, each command you run fits in one line. When you have finished typing a command, simply press Enter to run it. The output of the program will be displayed in the following lines. If you want to rerun or modify a command that you have just typed, simply press the up arrow key on your keyboard and you will see the previous command displayed again. You will then be able to edit and rerun it by pressing Enter again.
Don't forget that Linux is case sensitive, so the Apt-get command won't work but apt-get will!
Linux is an inherently secure operating system. Most of the commands in this chapter require administrator permissions. It is really easy to see whether you need root permissions. If they are required, you will see the following:
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
To run a command as the system administrator, simply add it to the beginning of any command that you need to run:
Depending on whether you have set a password or not, you may be asked to enter your password. Running apt-get is really simple just type apt-get and press Enter:
The apt-get command will respond with a heap of information about the different options that are available. The options that we are interested in are:
· apt-get update
· apt-get install
· apt-get remove
The first thing that we want to do is ensure that Raspbian knows what the latest versions of software are. The apt-get update command automatically connects to the Raspbian repository and downloads the latest list of packages.
It is recommended that before installing any software, you run the apt-get update command if you haven't done so recently.
The real power of the apt packaging system becomes apparent when you run the install command. To actually install the software package on your Raspberry Pi, you need to run apt-get install followed by the name of the software package.
Consider the following command:
sudo apt-get install apache2
This command will install the Apache2 web server. This is one of the most popular web servers in the world, with a 59% market share at the time of writing this book. Apache2 is extremely powerful but can be quite resource heavy depending on its configuration.
You will see something similar in your console to what is shown in the following screenshot:
Installing Apache2 using apt-get install
The apt-get command will automatically connect to the Internet and download the Apache2 package and all the packages that Apache2 needs to operate. You may be asked to confirm that you want to continue installing the software. Simply press the Y key and thenEnter. After the package is installed and configured, your new software is ready to go!
There are many packages that are available to extend the function of Apache2. These packages won't be installed by default. If you need to install these extras, they will need to be installed manually.
There are some packages that you are able to install, called metapackages. These packages represent a collection of packages that add a particular function to your Raspberry Pi. An example of this is as follows: if you used a distribution based on Raspbian that didn't include a graphical user interface, you could install this interface in one go by installing a metapackage. These packages behave as normal packages but are actually collections of several different packages behind the scenes. You are also able to use the * wildcard to represent multiple characters. To install all the available php packages, you could run this:
sudo apt-get install php-*
Sometimes, you will want to remove some software packages that have been installed and are no longer required. Removing a package is as easy as installing it. You simply use the apt-get remove command.
Run the following command:
sudo apt-get remove apache2
You should get an output similar to this:
Removing Apache2 using apt-get remove
For a bit of fun, try running apt-get moo!
Searching for packages
There are so many packages available to install using apt-get that it can be difficult to find the package that you want to install. Fortunately, it is really easy to search for the packages that are available to be installed. To do this, you use the apt-cache search tool.
Following on from our example of using the Apache2 package, you are able to see other extensions to the Apache2 package by running this command:
sudo apt-cache search apache2
The apt-cache search tool will list all the packages that mention Apache2 in their description or require Apache2.
Synaptic GUI Package Manager
There are many different ways in which you can install software on your Raspberry Pi. Using apt-get is one way. Another way is by using a GUI tool such as the Synaptic Package Manager. Unfortunately, it isn't installed in Raspbian by default, but it is easily installed using apt-get.
To install synaptic, run the following command in LXTerminal:
sudo apt-get install synaptic
Synaptic will take a few minutes to install on your Raspberry Pi as it is a reasonably large application. You will find the Synaptic Package Manager in the Other submenu in the main menu.
The Synaptic Package Manager
Searching and installing packages in Synaptic
You can search for packages in Synaptic using the search button:
1. Simply click on the Search button and enter the package that you are looking for.
Searching for a package
2. After clicking on Search, you will be shown all the packages that meet the search criteria. Simply check the packages that you want to install and select Mark for Installation. You can select as many packages as you want.
Packages are also organized by category on the left-hand side. This is a really easy way to try and find the software packages you are looking for.
Selecting a package
3. When you click on Apply, Synaptic will ask you to confirm that you want to install the packages that you have selected. After you click on Apply, the packages will be installed.
4. The package installation may take several minutes, depending on what packages you are installing. The progress of the installation can be tracked by selecting Details.
Synaptic installing the Apache2 web server
Uninstalling packages using Synaptic
Uninstalling packages using Synaptic is very similar to installing packages:
1. If you are trying to uninstall a package that you previously installed, you need to search for it. You can also see any packages that are installed by selecting the Status filter on the left. This will let you see all the packages that have been installed in a list. Over 850 packages are installed in the default Raspbian distribution, so it is quicker to search for them.
2. Once you have found the package that you want to uninstall, simply click on the checkbox and select Mark for Removal.
3. When you have finished selecting packages for removal, click on Apply.
Removing a package using Synaptic
The Pi Store
The Pi Store is another tool that you can use to install software on your Raspberry Pi. The Raspberry Pi Store is installed by default in Raspbian and can be opened using the Pi Store icon on the desktop. The Pi Store groups together most of the best pieces of software that are available to be installed on your Raspberry Pi in one place.
The Pi Store
The Pi Store is the only piece of software installed on your Raspberry Pi that actually sells commercial software and other content. To be able to purchase non-free software from the Pi Store, you need to register and provide a payment method such as a credit card.
The Pi Store is really easy to use:
1. Simply find the software that you want to install, and click on Buy Now.
2. Log in with your account, and away you go!
The Pi Store automatically handles all updates to any software that you have purchased.
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:
2. 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.
3. 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.
4. 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:
5. 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.
6. To extract a .tar.bz2 archive such as the Apache2 application, run the following command:
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:
· 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!
Just remember that these instructions are generic and that some software packages may need to be installed differently.
Raspbian is constantly under development, and updates that have fixes, new features, and security improvements are continually being released. It is highly recommended that you install all the updates that are available. There are many ways to do this, including using apt get and Synaptic.
Installing updates using apt-get
The apt-get command can be used to update the software in your Raspberry Pi. The first thing you need to do is ask apt-get to get the list of all pieces of software that are available for installation on your Raspberry Pi:
sudo apt-get update
This command may take a few minutes depending on your internet connection. To perform upgrades of the packages, you need to run the following command:
sudo apt-get upgrade
This command will download and install all the latest packages from the Raspbian repositories on your Raspberry Pi. You will then be fully up to date!
Installing updates using Synaptic
Updates can also be installed using the Synaptic Package Manager:
1. This can be done by selecting the Refresh button.
Refreshing available packages using Synaptic
2. Once the package list has been refreshed, click on Mark All Upgrades.
3. You will be asked to confirm the packages you are upgrading. Simply select Mark and then click on Apply, then all of the software on your Raspberry Pi will be up to date.
Selecting packages to be upgraded
Other software that you can install
There is only this much software that can be installed on the default Raspbian installation. Most pieces of software included in Raspbian are aimed at the educational market. Because of this, there isn't much productivity software preinstalled on your Raspberry Pi. Fortunately, this is easy to fix!
LibreOffice is a free, complete office suite that contains many of the features that are also found in Microsoft Office. It consists of many applications, and is available for installation through the Raspberry Pi Store.
A few of these applications are as follows:
Writer is a complete word processor with features similar to Microsoft word.
Calc is a spreadsheet application with many features, including graphs.
Impress is an application designed to create presentations.
Base is a database application similar to Microsoft Access, and it lets you create simple database applications
There are many other applications included in LibreOffice that aren't mentioned here. The best way to see all the features is to download LibreOffice and give it a go! You can find more information at www.libreoffice.org.
IceDove e-mail client
Another important productivity tool for the Raspberry Pi is the IceDove e-mail client. IceDove is the popular Thunderbird e-mail client that has been rebranded by Debian due to copyright issues with the Thunderbird and Firefox logos.
IceDove is an excellent e-mail client and is highly recommended. You can install IceDove by running this command:
sudo apt-get install icedove
Another excellent application is the IceWeasel web browser.
IceWeasel is a rebranded version of Firefox, and it supports all the features that you have come to expect from a modern web browser.
You can install IceWeasel by running the following command:
sudo apt-get install iceweasel
In this chapter, you learned several ways to install software packages on your Raspberry Pi, and some of the tools that you can use to do this. Thanks to the huge Debian repositories and the open source nature of Linux-based operating systems such as Raspbian, there is so much variety in software available for the Raspberry Pi. Now that you know how to install software on this device, you simply need to start looking for what you are after.