Skip to main content
This article explains how to install, update, upgrade, and remove software on Ubuntu using the apt package manager. Ubuntu simplifies software management by handling installation, upgrades, and dependency resolution with apt. Follow the examples below for practical guidance on managing your system’s packages.

Updating the Package Database

Before installing or upgrading any software, it is essential to refresh the local package database. Running the following command downloads the latest package information from the official repositories, ensuring that you work with up-to-date data.
Example output:
If the package information was last refreshed a while ago (for example, one week ago), running sudo apt update ensures you get the latest package listings.

Upgrading Installed Packages

After updating the package database, you can upgrade the installed packages with:
When prompted, type “y” to confirm the upgrade. For added efficiency, you can chain the update and upgrade commands. Using the && operator ensures that the upgrade command runs only if the update is successful:

Installing New Applications

To install a new application such as Nginx, run:
For a smoother process that uses the latest package data, chain the update and install commands together:
During the installation, additional dependencies, including necessary libraries and components, may be automatically installed to ensure Nginx runs correctly. Example output when installing Nginx:

Understanding Packages

A package is an archive containing everything required by a piece of software, including binaries, configuration files, and documentation. Once a package is installed, you can inspect its contents with the dpkg tool. For example, to list all files provided by the Nginx package:
Example output:
This output confirms that the Nginx executable is located at /usr/sbin/nginx. To determine which package provides a specific file, use the dpkg --search command:
Example output:
To gather more details about a specific package, such as its dependencies or description, you can use the apt show command. For instance:
Example output:

Searching for Packages

If you are unsure which package contains the software you need, you can search for it using apt search. For example, to find packages related to “nginx”:
This command looks through both package names and descriptions and may return multiple results. To narrow down the search to package names only, use the --names-only option:
You can also search using multiple keywords. For example, to find a package that includes “nginx”, “module”, and “image”, run:
This ensures that all specified search terms are included in the results.

Removing Packages

When a package is no longer necessary, you can remove it with the following command. For example, to remove Nginx:
Example output:
This command removes only the main package. Residual dependencies that are no longer needed remain on the system.
To clean up those extra dependencies, use:
Example output:
If needed, you can always reinstall Nginx using:
Using apt autoremove is a convenient way to remove both the main package and any leftover dependencies in a single operation.

Conclusion

In this article, we covered the essentials of managing software on Ubuntu using its apt package manager. You learned how to update the package database, upgrade installed packages, install new applications like Nginx, inspect package contents, search for specific packages, and remove unwanted software along with any residual dependencies. By mastering these commands, you can efficiently maintain and secure your Ubuntu system. Let’s move on to the next lesson.

Watch Video