APT – Command Examples to Install / Remove / Manage App Packages in Ubuntu

This tutorial shows beginners how to use apt command to install, remove, and manage app packages in Ubuntu / Debian.

APT is a high-level command line tool for package management in Debian, Ubuntu based systems. It is one of must-have command skills for those want to learn about Ubuntu.

1. Refresh Package Cache.

After added or removed an apt repository or Ubuntu PPA, or changed the apt configuration file, you need to run the command:

sudo apt update

It updates your system package cache by download package information from all configured sources. It’s useful before starting to install, remove, or manage app packages.

As the command started with sudo to grant root user privilege, you need to type user password to run it.

2. Install All Available Package Updates:

Instead of using the ‘Software Updater‘ utility, you can run command to install available upgrades of all packages using a single command:

sudo apt upgrade

This command is usually run after sudo apt update.

As you may found that some packages sometimes are ‘kept back’, since some package upgrades need to remove existing packages (usually dependency libraries). If you insist on installing the package upgrades, use this command instead:

sudo apt full-upgrade

3. Install A Software Package:

To install a software package, simply run apt install command with sudo. For instance, install VLC using command:

sudo apt install vlc

The command will also try to install the dependency packages. If not satisfied, it will output an unmet dependency error.

As you can see, it asks you to type y or n to continue installation or not. You can skip the prompt by adding --yes flag, so the command will be:

sudo apt install vlc --yes

Some apps have dependencies marked as “recommends” and / or “suggests”. By default, it installs the recommended packages, but you want skip them via --no-install-recommends flag:

sudo apt install --no-install-recommends vlc

It does not install the suggests dependency packages by default. If want, simply add --install-suggests to install them:

sudo apt install --install-suggests inkscape

In case you want to re-install an app to solve some issues, use command:

sudo apt install --reinstall PACKAGE_NAME

4. Remove A Software Package:

To remove a software package. for instance VLC media player, simply run command:

sudo apt remove vlc

To also remove the useless dependency packages, add --autoremove or --auto-remove flag.

sudo apt remove --auto-remove vlc

If the software package has already been removed, use sudo apt autoremove command instead to remove useless libraries.

The configuration file for a software package is by default left behind, in case the remove was an accident. You can add --purge flag while removing the package.

You can also run sudo apt purge vlc. However both only purge configurations in system directories, e.g., /etc folder.
sudo apt remove --autoremove --purge vlc

Well, there are a few more apt command that however not used quite often. You can run man apt in terminal or command console to see more about it.

Hi, I'm Merilyn Ne, a computer geek working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.