APT, also known as Advanced Packaging Tool, is the command-line tool for managing packages in Debian-based distributions like Ubuntu 16.04, Ubuntu 18.04, Debian 8, Debian 9 and much more. APT simplifies the process of installing, removing, and upgrading packages and is even used to upgrade the entire operating system through the Command Line Interface
This tutorial will explain how to manage packages using the APT command line tool on Ubuntu. The commands have been tested on Ubuntu versions 22.04 to 16.04
Requirements
- A server running Ubuntu Server or Desktop
- A root or sudo access on the server.
All commands below are run as root user. Either log in as root user on the shell or run:
sudo -s
to become the root user. As an alternative, you can prepend ‘sudo ‘ to all commands.
Install and Update Packages
Apt-get obtains information from different sources and is stored in a local database. The update command fetched the packages from their locations and update the packages to a newer version.
apt-get update -y
After running the above command, your database should be up-to-date.
The upgrade command is used to upgrade all the currently installed software packages to the newer version.
apt-get upgrade -y
You can also use dist-upgrade command to upgrade the packages, but it changes package dependencies with a smart conflict resolution method.
apt-get dist-upgrade -y
Once your database is updated, you can install any packages by running the following command:
apt-get install package1 package2
For example, you can install Nginx web server package by running the following command:
apt-get install nginx
If you want to download only package file but not install it, you can run the following command:
apt-get install -d package1
The above command will download the package file in /var/cache/apt/archives directory.
To reinstall any package with the newer version run the following command:
apt-get install package1 --reinstall
Remove a Package with Apt
To remove a package from your system run the following command:
apt-get remove package1
The above command will only remove the package but keep the configuration file.
To remove the package with configuration file with the following command:
apt-get purge package1
You can also remove all unwanted packages and clean the database with the following command:
apt-get autoremove
apt-get clean
Search Package with Apt-Cache
The command apt-cache is used to search for software packages.
To find the package by its description, run the following command:
apt-cache search proftpd
You should see the following output:
resource-agents - Cluster Resource Agents
fail2ban - ban hosts that cause multiple authentication errors
ftpd - File Transfer Protocol (FTP) server
gadmin-proftpd - GTK+ configuration tool for proftpd
gadmin-proftpd-dbg - GTK+ configuration tool for proftpd debug package
gadmintools - GTK+ server administration tools (meta-package)
proftpd-basic - Versatile, virtual-hosting FTP daemon - binaries
proftpd-dev - Versatile, virtual-hosting FTP daemon - development files
proftpd-doc - Versatile, virtual-hosting FTP daemon - documentation
proftpd-mod-autohost - ProFTPD module mod_autohost
proftpd-mod-case - ProFTPD module mod_case
proftpd-mod-clamav - ProFTPD module mod_clamav
proftpd-mod-dnsbl - ProFTPD module mod_dnsbl
proftpd-mod-fsync - ProFTPD module mod_fsync
proftpd-mod-geoip - Versatile, virtual-hosting FTP daemon - GeoIP module
proftpd-mod-ldap - Versatile, virtual-hosting FTP daemon - LDAP module
proftpd-mod-msg - ProFTPD module mod_msg
proftpd-mod-mysql - Versatile, virtual-hosting FTP daemon - MySQL module
proftpd-mod-odbc - Versatile, virtual-hosting FTP daemon - ODBC module
proftpd-mod-pgsql - Versatile, virtual-hosting FTP daemon - PostgreSQL module
proftpd-mod-sqlite - Versatile, virtual-hosting FTP daemon - SQLite3 module
proftpd-mod-tar - ProFTPD module mod_tar
proftpd-mod-vroot - ProFTPD module mod_vroot
To find all the packages starting with proftpd with the following command:
apt-cache pkgnames proftpd
You should see the following output:
apt-cache pkgnames proftpd
proftpd-mod-dnsbl
proftpd-mod-odbc
proftpd-mod-pgsql
proftpd-doc
proftpd-mod-tar
proftpd-mod-ldap
proftpd-mod-case
proftpd-mod-geoip
proftpd-mod-mysql
proftpd-basic
proftpd-mod-vroot
proftpd-mod-clamav
proftpd-mod-autohost
proftpd-mod-fsync
proftpd-mod-sqlite
proftpd-mod-msg
proftpd-dev
You can check the complete information of any package (nano) with the following command:
apt-cache show nano
Output:
Package: nano
Priority: standard
Section: editors
Installed-Size: 600
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Jordi Mallach <[email protected]>
Architecture: amd64
Version: 2.2.6-1ubuntu1
Replaces: pico
Provides: editor
Depends: libc6 (>= 2.14), libncursesw5 (>= 5.6+20070908), libtinfo5, dpkg (>= 1.15.4) | install-info
Suggests: spell
Conflicts: pico
Breaks: alpine-pico (<= 2.00+dfsg-5)
Filename: pool/main/n/nano/nano_2.2.6-1ubuntu1_amd64.deb
Size: 194060
MD5sum: c97dc062e9941bfe13b6b303cf8ed639
SHA1: ee93fcfd1f2ecd601b0a8f8932319848043f4f0f
SHA256: f20d8cca5c30b90ebf68301d126f86e473ac83e7d6fdc36f59bcd685c2eb4020
Description-en: small, friendly text editor inspired by Pico
GNU nano is an easy-to-use text editor originally designed as a replacement
for Pico, the ncurses-based editor from the non-free mailer package Pine
(itself now available under the Apache License as Alpine).
.
However, nano also implements many features missing in pico, including:
- feature toggles;
- interactive search and replace (with regular expression support);
- go to line (and column) command;
- auto-indentation and color syntax-highlighting;
- filename tab-completion and support for multiple buffers;
- full internationalization support.
Description-md5: b7e1d8c3d831118724cfe8ea3996b595
Homepage: http://www.nano-editor.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: standard, kubuntu-active, kubuntu-active
To check the dependencies of a specific package with the following command: