Unlimited WordPress themes, graphics, videos & courses! Unlimited asset downloads! From $16.50/m
  1. Computer Skills
  2. Electronics

Using the Raspberry Pi Advanced Packaging Tool - APT


The Raspberry Pi is an incredible little computer that is revolutionising computing in the classroom, and at home. It’s single-handedly responsibly for introducing a new generation to programming and experimentation as opposed to learning how to use spreadsheets and word processors.

For anyone new to Raspberry Pi, there is a lot to get to grips with and–consequently–a lot to remember. This tutorial provides an aide memoire of useful things that you need to know. You might wish to bookmark this one.

Setting Up an SD Card

Before you are able to follow this tutorial, you will need to have your Raspberry Pi up and running with an operating system. For the purposes of this tutorial I am using a default installation of Raspian, installed using NOOBS, which I am accessing via SSH from a Mac.

This tutorial assumes that you already have Raspian running on your Raspberry Pi. If it is not, please refer to our tutorials to set up an SD card for your Pi.

Tip: To set up an SD card, refer to the tutorials How to Flash an SD Card for Raspberry Pi and How to Install NOOBS on a Raspberry Pi With a Mac

Command Line Access to a Raspberry Pi

Raspberry Pi With LXTerminal

If you are using your Raspberry Pi directly, in Raspbian Graphical User Interface (GUI) open LXTerminal from the desktop.

If you have not started the GUI, you are using the command line interface (CLI) and can run the necessary commands from here.

Accessing a Pi with Secure Shell (SSH)

Secure Shell, often referred to as SSH, is a cryptographic network protocol to enable secure communication between networked computers, either over a local area network (LAN) or over the Internet. It is, essentially, a secure channel for communications over an insecure network.

Tip: A Raspberry Pi will first need configuring for SSH access from another computer. This tutorial assumes that you already have SSH access enabled on your Pi.

Secure Shell (SSH) From Another Computer

From a Mac, you can use Terminal to access a Raspberry Pi. If you are using a Linux machine, you can use the terminal program that is part of the operating system.

If you are a Windows user, I recommend that you download and install PuTTY  which is a free SSH client program

The Repository and Advanced Packaging Tool

The Respository

Software on Linux generally, and the Raspberry Pi specifically, is maintained via a Repository. A repository contains software that has been compiled and is maintained, often by volunteers, for the benefit of the community.

The people who maintain software in the repository ensure that any, and all, dependencies are taken care of as well.

The Advanced Packaging Tool: APT

In Linux to browse, install, update, upgrade and uninstall software you need to use a Package Manager. The Raspberry Pi uses a package manager called apt or Advanced Packaging Tool.

The Advanced Packaging Tool is not a single program; it is a free user interface the simplifies the management of software on Unix or Linux operating systems including the Raspberry Pi. The functions of Advanced Packaging Tool are executed from the command line.

Tip: Other package managers exist for different versions of Linux. For example, a Fedora build of Linux uses yum or Yellowdog Update Manager. Redhat uses rpm or Redhat Package Manager.

Substitute User Do

It’s probably not a great idea to operate your Raspberry Pi–or any Linux computer–using root privileges as a matter of course. It’s most likely that you are not, anyway. It’s not the default mode of operation with the Raspberry Pi.

This means that executing certain commands may not be possible if you do not have root security privileges. A useful tool, in these circumstances, is sudo the name of which comes from a contraction of substitute user and do.

The command sudo allows users to execute certain commands without having to log in as the root user.

Tip: Installing, upgrading or uninstalling software requires the use root privileges or the use of the command sudo.

How to Update the Repository Database

apt-get update

It is useful to periodically update–or resynchronise–the package index files from their sources. The sources are dependent upon what has been defined in the location /etc/apt/sources.list. In Raspian, the default source in this file is deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi

To update the software repository, on your Raspberry Pi, to the latest version enter the following command:

If you are not running root privileges you will need to enter the following command with sudo:

How to Search for Software by Name

In order to find a particular piece of software you can perform a search by name using the following command

A practical example of this would be Google’s Chromium browser which is not a part of the default Raspian install. To perform a search for Chromium you can enter the command:

Tip: Root privileges are not normally necessary to execute this command.

How to Install a Software Package

Similarly to the the search, use the software name to install the software package. Only the named part of the package is required, not the full filename.

In this example, the package has already been installed

If necessary, apt will automatically retrieve and install packages upon which the indicated package depends. This avoids installation failures that result from missing dependencies.

To install software, use the following command:

If you are not running root privileges you will need to enter the following command with sudo:

A practical example of this would be:

Upgrade all Previously Installed Packages

Upgrade is different to update. Upgrade installs the newest versions of all packages that you currently have on the Raspberry Pi. Only packages that are installed are upgraded.

If you are not running root privileges you will need to enter the following command with sudo:

How to Remove a Software Package

From time-to-time you may wish to perform a spot of data housekeeping and remove any packages that you no longer need. This keeps your Pi lean and ensures that you are not filling your finite SD card with packages or software that are not needed.

To remove a package, enter the following on the command line:

If you are not running root privileges you will need to enter the following command with sudo:

A practical example of this would be:

How to Clean Up the apt-get Cache

The command apt-get clean clears the local repository of retrieved package files. This is a useful tool to free up disk space.

If you are not running root privileges you will need to enter the following command with sudo:

How to Determine Available Disc Space

It’s good to measure how much space is being used and, if using apt-get clean, how much space is freed up.

To get an idea of space, before and after using apt-get clean, use the command df which reports the amount of disk space being used by file systems.

The switch -h outputs the results in a human readable format.

Get Going With apt-get

In this tutorial I have explained the function of the Advanced Packaging Tool and how to use it to install, update, upgrade and remove software on the Raspberry Pi.

I have also shown how to measure the amount of available free space on your Pi.

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.