You are on page 1of 10

Ubuntu Lab-5

Using apt Commands in Linux


What is apt?
Debian Linux uses dpkg packaging system. A packaging system is a way to provide programs
and applications for installation. This way, you don’t have to build a program from the source
code which, trust me, is not a pretty way to handle packages. APT (Advanced Package Tool) is
the command line tool to interact with the packaging system in Debian-based Linux
distributions.
APT is a more friendly way to handle packaging. You can use it to find and install new
packages, upgrade packages, remove the packages etc. apt commands provide command line
way to interact with APT and manage packages.
Update package database with apt
apt actually works on a database of available packages. If the database is not updated, the system
won’t know if there are any newer packages available. This is why updating the repository
should be the first thing to do in in any Linux system after a fresh install. Updating the package
database requires superuser privileges so you’ll need to use sudo.
sudo apt update
When you run this command, you’ll see the package information being retrieved from various
servers.

apt commands provide command line way to interact with APT and manage packages.

You’ll see three types of lines here, Hit, Get and Ign. Basically these are:

 Hit: there is no change in package version from the previous version


 Ign: the package is being ignored. Either the package is way too recent that it doesn’t
even bother to check or there was an error in retrieving the file but error was trivial and
thus it is being ignored.
Ubuntu Lab-5

 Get: There is a new version available. It will download the information about the version
(not the package itself).

Upgrade installed packages with apt

Once you have updated the package database, you can now upgrade the installed packages. The
most convenient way is to upgrade all the packages that have available updates. You can simply
use the command below:

sudo apt upgrade


This will show you how many and which all packages are going to be upgraded.

There is another way to provide a complete upgrade by using the command below:

sudo apt full-upgrade


full-upgrade works the same as upgrade except that if system upgrade needs the removal of a
package already installed on the system, it will do that. Whereas, the normal upgrade command
won’t do this.
Ubuntu Lab-5

The fastest and the most convenient way to update Ubuntu system by using this command:

sudo apt update && sudo apt upgrade -y

How to install new packages with apt

If you already know the name of the package, you can install it using the command below:

sudo apt install <package_name>


Ubuntu Lab-5

Just replace the <package_name> with the desired package. Suppose you want to install mplayer,
you can simply use the command below:

sudo apt install mplayer

The good thing here is that you can use auto-completion. So, if you are not sure about the exact
package name, you can type a few letters and press tab and it will suggest all the packages
available with those letters.

How to install multiple packages with apt

You are not bound to install just one package at a time. You can install several packages at a
time by providing the package names all together:

sudo apt install <package_1> <package_2> <package_3>


Ubuntu Lab-5

How to install a specific version of an application

By default, the latest version available in the repository will be installed for an application. But if
you don’t want to install the latest version, you can specify the version number. You would need
to know the exact version number that you want to install.

Just add =version with the name of the package.

sudo apt install <package_name>=<version_number>

How to remove installed packages with apt

Removing packages is as easy as installing them. Just use the command below:

sudo apt remove <package_name>


Ubuntu Lab-5

Another way of uninstalling packages is to use purge. The command is used in the following
manner:

sudo apt purge <package_name>

Search for packages

It will find all the packages containing your search term.

apt search <search term>


Ubuntu Lab-5

See the content of a package

If you want to know more about a package before installing or removing it, you can use the
below command:

apt show <package_name>

This will show information about the given package(s) like its dependencies, installation and
download size, different sources the package is available from, the description of the content of
the package among other things:
Ubuntu Lab-5

List upgradable and installed versions

apt command has a new option called list. Using this command, you can see all the packages that
have a newer version ready to be upgraded:

apt list --upgradeable


List all upgradeable packages

You can also see all the installed packages on the system with installed option:

apt list --installed


Ubuntu Lab-5

There is also a third option called –all-versions. It will list all the packages available for your
system:

apt list --all-versions

How to clean your system with apt

sudo apt autoremove


This command removes libs and packages that were installed automatically to satisfy the
dependencies of an installed package. If the package is removed, these automatically installed
packages, though useless, remains in the system.
Ubuntu Lab-5

You might also like