How To Add, Remove and Update Software in Linux Using Apt

APT Package Management
(Image credit: Tom's Hardware)

Linux has many ways to install software. We can build our own executables or use AppImage to run containerized applications. But at the heart of many Linux distros is a package management system, which for Debian based systems, such as the Raspberry Pi and Ubuntu, is Apt.

Apt, the Advanced Packaging Tool is a command line application which handles the installation, categorization and removal of applications and their dependencies from the software repositories. Apt is the heart of Debian systems and the lessons learnt are applicable from the $35 Raspberry Pi to million dollar super computers. Apt is available via the Terminal and we can even administrate systems remotely using a remote connection such as SSH.

A command line tool may seem daunting but here we detail the most common commands that you will use to keep your system updated with the latest software.

So why not just use apt-get?

(Image credit: Tom's Hardware)

Apt isn’t something new, it has been around since 2014, but it really came to notice with Ubuntu 16.04. But many users use “apt-get” instead so what’s the difference? They both serve the same purpose, software management, but with Apt it boils down to simply removing the “-get” from the command. 

Take for example the commands that we used in this how-to.

Swipe to scroll horizontally
aptapt-getFunction
apt updateapt-get updateUpdate software repositories.
apt upgradeapt-get upgradeUpgrade system software.
apt installapt-get installInstall an application.
apt removeapt-get removeRemove an application.
apt purgeapt-get purgeRemove an application and user configuration files.

(Image credit: Tom's Hardware)

But Apt does have a few extra commands, in fact we will use one in the how to.

Swipe to scroll horizontally
CommandFunction
apt searchSearch for a specific application.
apt edit-sourcesEdit /etc/apt/sources.list file which contains all of your software repositories. This is really a shortcut command which opens a text editor.
apt listList all of the installed applications.
apt showList the details of an application, including any dependencies.
apt mooUses ASCII to display a cow. Ok this is more a joke than a tool. See also cowsay.

Apt is the tool to learn and use for everyday tasks. Apt-get is not being deprecated, but it would be wise to invest your time learning Apt.

Searching for software with Apt

Using Apt we can search the software repository for specific applications and keywords.

Open a terminal and use the apt search command followed by the name of an application. In our example, we use vlc to search for any applications that have vlc in the title. This command can generate a lot of results, but we can scroll up and down the list using our mouse / trackpad.

$ apt search vlc

(Image credit: Tom's Hardware)

To pause the output of the command, we can pipe (send the output) to “less”. The less command is used to store a page of output, which we can scroll or page through using the spacebar.

$ apt search vlc | less

(Image credit: Tom's Hardware)

To be more specific we can further pipe the output from less and use “grep” to search for a specific keyword. Here we search for any VLC tools to use with Python 3.

$ apt search vlc | less | grep “python3”

(Image credit: Tom's Hardware)

Once we have found the appropriate application we can use the install command to install it onto our system.

Installing Linux Software With Apt

After identifying our required application we next need to install it. Before we run an installation we need to update, ensuring that we get the latest software.

1. Open a terminal and use the update command. The update command will update the list of available packages for your machine. 

$ sudo apt update

(Image credit: Tom's Hardware)

2. Use the install command to download and install your chosen application. In our example we install VLC, a popular media player.

$ sudo apt install vlc

(Image credit: Tom's Hardware)

After a few moments the application will be installed and available via the Terminal and via the Applications menu.

Upgrading software with Apt

To upgrade all of your installed software we can use the “upgrade” command. Using this with “update,” we can ensure that our software repositories are up-to-date, meaning that any new software is at the latest version.

1. Open a terminal and use the update command. The update command will update the list of available packages for your machine.

$ sudo apt update

(Image credit: Tom's Hardware)

2. Run the upgrade command to download and install the latest software. We use the -y switch to automatically agree to installing the software.

$ sudo apt upgrade -y

We can also chain together these commands into a one line script. Using “&&” between the commands we can instruct the system to chain the commands to run one after the other. The “&&” means that the second command will only run if the first command runs successfully.

$ sudo apt update && sudo apt upgrade -y

(Image credit: Tom's Hardware)

Depending on the amount of required updates, this can take from a few seconds to multiple minutes.

Removing software

There are two ways to uninstall an application from the system. The first “removes” the application from the system, leaving any user configuration files intact. This is the most common and safest means to remove software

Open a terminal and use the following command to remove the application. In our example we uninstalled VLC.

$ sudo apt remove vlc

(Image credit: Tom's Hardware)

The second way is to “purge” the application and any config files from the system. This is a nuclear option, used to remove the application should we need a fresh start.

1. Open a terminal and use the purge command to remove VLC and any of its configuration files. Only use this command if you do not need or have backed up any configuration files.

$ sudo apt purge vlc

(Image credit: Tom's Hardware)

2. Confirm that you are happy to purge the application and any configuration files.

APT Package Management

(Image credit: Tom's Hardware)
Les Pounder

Les Pounder is an associate editor at Tom's Hardware. He is a creative technologist and for seven years has created projects to educate and inspire minds both young and old. He has worked with the Raspberry Pi Foundation to write and deliver their teacher training program "Picademy".

  • mitch074
    There is no need to use 'less' before a 'grep', since the former can't 'see' the console anymore it won't page the output. You could put it after the 'grep' though.
    The main interest of apt over apt-get isn't that it has more commands, only that its syntax is simpler and its output more user-friendly. It is, for example, easier to clean up packages that were installed to solve dependencies and that are no longer needed (autoremove is a recent addition to apt-get). It's no better than apt-get at solving dependency hell though, you'll want to use 'aptitude' here.
    It is, also, very specific to Debian derivatives : Red Hat and its ilk use dnf, yum and other dependency solvers to manage rpm packages... apt and apt-get won't be much use on them.
    Reply