This article explains how to manage software on Ubuntu using the apt package manager, covering installation, updates, upgrades, and removals.
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.
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.
Copy
Ask AI
sudo apt update
Example output:
Copy
Ask AI
sudo apt update[sudo] password for jeremy:Get:1 http://us.archive.ubuntu.com/ubuntu noble InRelease [97.5 kB]Get:2 http://us.archive.ubuntu.com/ubuntu noble-updates InRelease [89.7 kB]Get:3 http://us.archive.ubuntu.com/ubuntu noble-backports InRelease [89.7 kB]Get:4 http://security.ubuntu.com/ubuntu noble-security InRelease [89.7 kB]Fetched 179 kB in 2s (77.4 kB/s)Reading package lists... DoneBuilding dependency tree... DoneReading state information... Done4 packages can be upgraded. Run 'apt list --upgradable' to see them.jeremy@kodekloud:~$
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.
After updating the package database, you can upgrade the installed packages with:
Copy
Ask AI
sudo apt upgrade
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:
For a smoother process that uses the latest package data, chain the update and install commands together:
Copy
Ask AI
sudo apt update && sudo apt install nginx
During the installation, additional dependencies, including necessary libraries and components, may be automatically installed to ensure Nginx runs correctly.Example output when installing Nginx:
Copy
Ask AI
sudo apt update && sudo apt install nginxHit:1 http://us.archive.ubuntu.com/ubuntu noble InReleaseHit:2 http://security.ubuntu.com/ubuntu noble-security InReleaseHit:3 http://us.archive.ubuntu.com/ubuntu noble-updates InReleaseHit:4 http://us.archive.ubuntu.com/ubuntu noble-backports InReleaseReading package lists... DoneBuilding dependency treeReading state information... DoneThe following additional packages will be installed: nginx-commonSuggested packages: fcgiwrap nginx-doc ssl-certThe following NEW packages will be installed: nginx nginx-common0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.Need to get 552 kB of archives.After this operation, 1,596 kB of additional disk space will be used.Do you want to continue? [Y/n]
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:
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:
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”:
Copy
Ask AI
apt search 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:
Copy
Ask AI
apt search --names-only nginx
You can also search using multiple keywords. For example, to find a package that includes “nginx”, “module”, and “image”, run:
Copy
Ask AI
apt search nginx-module-image
This ensures that all specified search terms are included in the results.
When a package is no longer necessary, you can remove it with the following command. For example, to remove Nginx:
Copy
Ask AI
sudo apt remove nginx
Example output:
Copy
Ask AI
jeremy@kodekloud:~$ sudo apt remove nginxReading package lists... DoneBuilding dependency tree... DoneReading state information... DoneThe following packages will be REMOVED: nginx nginx-common0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.After this operation, 1,596 kB disk space will be freed.Do you want to continue? [Y/n] y
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:
Copy
Ask AI
sudo apt autoremove nginx
Example output:
Copy
Ask AI
sudo apt autoremove nginxReading package lists... DoneBuilding dependency tree... DoneReading state information... DoneThe following packages will be REMOVED: nginx nginx-common0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.After this operation, 1,596 kB disk space will be freed.Do you want to continue? [Y/n] y(Reading database ... 83359 files and directories currently installed.)Removing nginx-common (1.24.0-2ubuntu7) ...Removing nginx (1.24.0-2ubuntu7) ...Processing triggers for man-db (2.12.0-4build2) ...
If needed, you can always reinstall Nginx using:
Copy
Ask AI
sudo apt install nginx
Using apt autoremove is a convenient way to remove both the main package and any leftover dependencies in a single operation.
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.