Managing packages in Raspberry Pi using APT

Posted on 25th January 2016

APT (Advanced Packaging Tool) is a set of tools that was developed for Debian Linux platform as an easy command line interface for the dpkg utility. APT tools are used in Raspberry Pi computers running Raspbian to install new packages, update already installed packages, uninstall/remove packages, browse package details and search for packages.

The three most popular APT tools are apt, apt-get and apt-cache. This article explains apt tool however the usage is similar for others also.

When installing new packages APT will download the package files from a list of sources that are defined in the file /etc/apt/sources.list. By default it will have at least one source defined. The example below shows the sources.list file from Raspbian Jessie.

pi@raspberrypi:~ $ nano /etc/apt/sources.list
deb jessie main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src jessie main contrib non-free rpi

Note: You must be logged in as root user and in the sudoers list to be able add, remove or update packages.

How to get a list of installed softwares

To get a list of installed packages run apt list

pi@raspberrypi:~ $ sudo apt list --installed

This command will give you a long list of installed packages. You could pipe its output with more command.

pi@raspberrypi:~ $ sudo apt list --installed | more

Update available software list

Before you start to install new packages you need to update the list of available packages using the apt update command.

pi@raspberrypi:~ $ sudo apt update

How to install new packages

You need to update the package list before installing new packages. To install new packages run the apt install. For example to install Apache web server you run

pi@raspberrypi:~ $ sudo apt-get install apache2

The above command will which packages and dependencies will be installed, and disk space requirements. You need to press Y to continue the install.

View package information

To view detailed information about a package such as package version, size, and description run the command apt show. To show information about apache2 package:

pi@raspberrypi:~ $ apt show apache2

You don't need sudo for apt show command.

How to remove a package

To remove a package that is already installed, use the apt remove command. The following command removes the package named 3dchess

pi@raspberrypi:~ $ sudo apt remove 3dchess

Installing and removing packages at the same time

You could install a package and remove another package with a single command. All you need to do is to append a - to packages you want to remove. For example the following command adds php5 package and remove the 3dchess package. (Note the - at the end of the package name 3dchess)

pi@raspberrypi:~ $ sudo apt install php5 3dchess-

Similarly you could remove a package and install another from the same command. In this case you add a + to the package name you need to install

pi@raspberrypi:~ $ sudo apt install php5 3dchess+

How to upgrade installed packages

To upgrade packages that are already installed on your raspberry pi, run the apt upgrade command.

pi@raspberrypi:~ $ sudo apt upgrade

This command will tell you which packages will be upgraded, how much space required and how much space will be freed. You need to confirm to continue the operation by pressing Y

Search Package

If you need to search for a keyword in the description of available packages, run apt search

pi@raspberrypi:~ $ sudo apt search webserver

How to remove a package

To remove a package that is already installed, use the apt remove command. The following command removes the package named 3dchess

pi@raspberrypi:~ $ sudo apt remove 3dchess

Getting additional help

In this article I've covered the important commands to get you started with apt on Raspberry Pi. Most of the package management tasks can be performed by learning these few commands. For additional commands and features you can run the apt command without any parameters or check the man pages.

Post a comment


Nothing the first to share wisdom.