Ubuntu is a free, open-source, user-friendly and one of the most widely used operating systems around the world. Ubuntu Desktop operating system provides a GUI method to install and remove packages. If you are using the server operating system that it is very difficult for a beginner user to manage the packages. In this case, you should know how to use APT to manage packages on Ubuntu.
The APT (Advanced Package Tool) is a command-line tool used for managing packages in the Debian-based operating system. It provides an easier way to install, update, upgrade, uninstall, list and manage packages in Linux.
In this post, we will show you how to manage packages with APT on Debian and Ubuntu operating system.
# Requirements
- A server running Debian/Ubuntu operating system.
- A root password is set up on your server.
# Update and Upgrade Packages
Before installing any package, you will need to update a local copy of the package database.
To update the package database, run the following command:
apt update -y
Once your package database has been updated, it is recommended to upgrade all system packages with the updated version. You can do it with the following command:
apt upgrade -y
If you want to upgrade a specific package, run the following command:
apt upgrade firefox -y
It is also recommended to run the dist-upgrade command to install all dependencies with a new version of packages.
apt dist-upgrade -y
# Install and Uninstall Packages
To install a new package, run the following command:
apt install firefox -y
To remove an installed package from the system, run the following command:
apt remove firefox -y
To install multiple packages, run the following command:
apt install package1 package2 package3 -y
# Download and Install a Package
If you want to download only package .deb file, run the following command:
apt download apache2
This will download apache2_2.4.41-4ubuntu3_amd64.deb file to your current directory.
You can install the downloaded file with the following command:
dpkg -i apache2_2.4.41-4ubuntu3_amd64.deb
If you get any dependency error during the package installation, you can resolve it with the following command:
apt install -f
# Search Packages
If you don't know the exact name of the package that you want to install then you can use apt-cache command to search a specific package using keyword.
For example, to search all package that contains word nginx run the following command:
apt-cache search nginx
You should see the following output:
libnginx-mod-http-image-filter - HTTP image filter module for Nginx
libnginx-mod-http-xslt-filter - XSLT Transformation module for Nginx
libnginx-mod-mail - Mail module for Nginx
libnginx-mod-stream - Stream module for Nginx
nginx - small, powerful, scalable web/proxy server
nginx-common - small, powerful, scalable web/proxy server - common files
nginx-core - nginx web/proxy server (standard version)
# Find a Dependencies of a Package
If you want to find the dependencies of a specific package, run the following command:
apt-cache depends nginx
You should see the following output:
nginx
|Depends: nginx-core
|Depends: nginx-full
|Depends: nginx-light
Depends: nginx-extras
|Depends: nginx-core
|Depends: nginx-full
|Depends: nginx-light
Depends: nginx-extras
# Display Package Information
To display the full information of any package, run the following command:
apt-cache show snmp
You should see the following output:
Package: snmp
Architecture: amd64
Version: 5.8+dfsg-2ubuntu2
Priority: optional
Section: net
Source: net-snmp
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Net-SNMP Packaging Team <pkg-net-snmp-devel@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 669
Depends: libc6 (>= 2.14), libsnmp35 (= 5.8+dfsg-2ubuntu2), libssl1.1 (>= 1.1.0), libsnmp-base (>= 5.7.3+dfsg-5)
Recommends: perl
Filename: pool/main/n/net-snmp/snmp_5.8+dfsg-2ubuntu2_amd64.deb
Size: 167640
MD5sum: 21c5774c594213123cbd6112a2dd48db
SHA1: 8bca24f69f5955ff950ea278fdf291663fee0525
SHA256: 5db0f9bf027a91c62bbeebb8719a414593ae33f889ebc4cbd75747b57f25ab9c
Homepage: http://net-snmp.sourceforge.net/
Description-en: SNMP (Simple Network Management Protocol) applications
The Simple Network Management Protocol (SNMP) provides a framework
for the exchange of management information between agents (servers)
and clients.
# List Installed Packages
To get a list of all installed packages, run the following command:
apt list --installed
You should see the following output:
Listing... Done
acpid/focal,now 1:2.0.32-1ubuntu1 amd64 [installed]
adduser/focal,focal,now 3.118ubuntu2 all [installed]
alsa-topology-conf/focal,focal,now 1.2.2-1 all [installed,automatic]
alsa-ucm-conf/focal,focal,now 1.2.2-1 all [installed,automatic]
apt-utils/focal-updates,focal-security,now 2.0.2ubuntu0.1 amd64 [installed]
apt/focal-updates,focal-security,now 2.0.2ubuntu0.1 amd64 [installed]
base-files/focal,now 11ubuntu5 amd64 [installed]
base-passwd/focal,now 3.5.47 amd64 [installed]
bash/focal,now 5.0-6ubuntu1 amd64 [installed]
bsdmainutils/focal,now 11.1.2ubuntu3 amd64 [installed,automatic]
bsdutils/focal,now 1:2.34-0.1ubuntu9 amd64 [installed]
busybox-initramfs/focal,now 1:1.30.1-4ubuntu6 amd64 [installed]
bzip2/focal,now 1.0.8-2 amd64 [installed,automatic]
ca-certificates/focal,focal,now 20190110ubuntu1 all [installed]
To check whether a specific package is installed or not, run the following command:
apt list -a apache2
You should see the following output:
apache2/focal,now 2.4.41-4ubuntu3 amd64 [installed]
apache2/focal 2.4.41-4ubuntu3 i386
To list all packages that are upgradeable, run the following command:
apt list --upgradeable
# Remove Unwanted Packages
When you install any packages, it will download a package file to the /var/cache/apt directory. You can remove those package cache with the following command:
apt clean
When you remove any package, all dependencies that are installed with this package are still persisted in your system. You can remove all unwanted dependencies with the following command:
apt autoremove
# Conclusion
In the above guide, you learned how to manage packages with the APT command in a Debian-based operating system. I hope this will help you to perform day-to-day tasks.