How to Install Any Ubuntu Package Using Apt

The shell-based package manager makes software management a breeze

Although the graphical package manager that ships by default with Ubuntu Linux is good, it's not perfect — these graphical tools often just share popular or recommended apps, leaving potentially thousands of additional programs hidden in obscurity. These tools function as a pretty front-end for the Advanced Packaging Tool. APT is the default package-management framework for Ubuntu and several other popular distributions.

So instead of relying on a slimmed-down menu from a graphical installer, why not just use APT-based tools yourself?

Invoking APT directly requires access to a shell prompt, which you can launch by pressing Ctrl+Alt+T to open the Terminal program. The procedures described below work on all currently supported versions of Ubuntu Linux.

A Note About Package Management

In Microsoft Windows, to install a new program you must download and execute its installer, or — if it's a "portable app" — extract the program's files to a location on your filesystem. Linux, however, enjoys a multitude of methods for installing and managing software. The files for installing software is usually called a package and packages come in many different flavors. Ubuntu, for example, uses the conventions of the Debian family of distributions it hails from, so Ubuntu packages end in .DEB. However, Ubuntu also supports methods like installing and compiling from source code or the newer Snap packages.

A package manager serves as a traffic cop for dependencies, or webs of interdependence among packages. Some packages require specific other packages as well as their own; others require that some packages be removed before they'll work. APT and the tools that invoke it address dependencies on your behalf, but the specific commands you use with these tools governs how they address dependencies.

Each type of package-management framework and each specific Linux distribution maintains a library of software that's expected to work on it. Those libraries are called repositories. Although the package maintainers for each distribution include that distribution's repositories by default within the package-management tool, stand-alone apps — particularly major ones — source from their own repositories. To add software from them, you must first add the repository to your package-management tool.

Package Management on Ubuntu

The Ubuntu Software GUI.

Although you're free to use the GUI to install and manage applications, power users (as well as people who need more than the limited selection that the GUI offers) default to a shell program that interfaces with APT.

The standard command to access APT—intuitively, but confusingly, called apt—manages most work for you. In Ubuntu documentation, you'll see a difference between apt and apt-get. The former is optimized for human interaction; the latter more directly ties into the internals of the operating system and APT as a framework. To add to the fun, a package-management utility called aptitude is different from both apt and apt-get. Although there are some syntactical differences and slight capability differences between apt and apt-get, you're generally fine using apt except for when the additional firepower of apt-get may make more sense (or if you're much more fluent in Linux package management than the average bear).

To access APT regardless of the shell program, you must use elevated privileges. Thus, you must invoke sudo; otherwise APT access is denied:

Apt update with and without sudo

One cool thing about apt and apt-get? They both support the -y flag to automatically answer "Y" at any prompt that requires your confirmation. This shortcut proves handy when you're updating an environment for the first time in a while and would otherwise have to confirm certain upgrades potentially dozens of times.

How to Sync APT with Repositories

To refresh your computer's index of packages at each of the repositories to which it's connected, use the apt update command. This command — which, as a matter of good housekeeping, should always be the first thing you invoke before making other package changes — syncs your local copy of available packages and their versions against the current-state index with the repositories. Run this:

sudo apt update

Apt processes updates. It occasionally throws errors about, e.g., missing security keys or other errors. Review the command's output to determine whether you've experienced any critical configuration errors. One nice thing about running apt update is that it's a great quick-look exploration about the state of your package-management environment.

Visit Ubuntu's community documentation page for detailed instructions for adding new software repositories.

How to Update Ubuntu Linux Packages

To update packages on your computer, use the following command:

sudo apt upgrade -y

Updates are easy, but there's a catch. One difference between apt and apt-get is that the latter supports different types of upgrades. For example, apt-get update and apt-get dist-upgrade both differ slightly from apt upgrade:

  • apt-get upgrade: Updates the package but does not, by default, delete other packages or add new ones. Instead, the upgrade will fail if it requires added or deleted dependencies.
  • apt-get dist-upgrade: Updates and deletes prior versions of the package, including dependencies.
  • apt upgrade: Functions like apt-get upgrade --with-new-packages, which is a fancy way of saying that it updates, but does not delete prior versions, yet it does install new packages (but won't delete them) if doing so is required to satisfy dependencies.

If you're okay with apt deleting packages to satisfy dependencies, use the full-upgrade option instead:

sudo apt full-upgrade -y

Finding and Installing New Software

After you've updated your repositories and upgraded existing packages, you're in good shape to search for, and install new programs.

Use the apt search and apt show commands to search for new software and explore their technical requirements. This first command scours all valid repositories to which you've connected, according to specific search terms:

sudo apt show

For example to search for a web browser type the following:

sudo apt search "web browser"
apt search

To get more information about a package type the following:

sudo apt show

For example, an apt show command for the chromium-browser package shows quite a bit of technical information:

apt show command

Use sudo apt-cache show instead to obtain significantly more technical information about the package.

After you've discovered the name of the package you want, install it with the apt install command. To install the chromium-browser package, for example, type:

sudo apt install chromium-browser

And you'll be prompted to install the additional packages that chromium-browser depends upon. (If you used the -y flag, the command would execute without the prompt.)

apt install command for "chromium-browser"

Tidying Up Packages

A few other apt-related commands prove helpful:

  • apt reinstall: Reinstalls the package from the repository source, useful if you think you've broken a program that you like.
  • apt remove: Removes a package, but leaves user-configured files in place.
  • apt purge: Removes a package and also all associated files related to it, including user configuration files.
  • apt autoremove: Deletes packages that had been installed as dependencies but, given that they're obsolete or the other package was removed, are now orphaned. Running this command occasionally can recover some disk space.

When you install a package a file with a .DEB extension is downloaded and placed into the folder /var/cache/apt/packages. The package is then installed from that folder.

Clear the folders /var/cache/apt/packages and /var/cache/apt/packages/partial by using the following command:

sudo apt-get clean 
Was this page helpful?