How To Use APT(Advanced Pacage Tool) in Ubuntu/Debian Linux
This post will guide you how to use APT tool for the package management on your Ubuntu or Debian based systems. How do I use the APT package management tool to install, remove,update,upgrade and manage software packages on Ubuntu or Debian Linux.
- APT Command
- Updating Package Index with APT Command
- Upgrading Installed Packages with APT Command
- Installing Package with APT Command
- Installing Multiple Packages with APT Command
- Installing a Package with a Specified Version
- Searching for a Package with APT Command
- Show Information about the Given Packages
- Remvoing Installed Packages with APT Command
- Removing Unused Packages
- Listing All Installed or Upgradeable Packages
APT Command
apt provides a high-level commandline interface for the package management system. It is intended as an end user interface and enables some options better suited for interactive usage by default compared to more specialized APT tools like apt-get(8) and apt-cache(8).
The syntax of the APT command is as follows:
apt [-h] [-o=config_string] [-c=config_file] [-t=target_release] [-a=architecture] {list | search | show | update |install pkg [{=pkg_version_number | /target_release}]... | remove pkg... | upgrade | full-upgrade | edit-sources | {-v | --version} | {-h | --help}}
Updating Package Index with APT Command
Apt Tools works on the indexes of available packages. If the indexes are not updated, and the APT Tool won’t know if there are any newer packages available. This is you need to resynchronize the package index files from their sources before installing a package. The indexes of available packages are fetched from the location(s) specified in /etc/apt/sources.list.
An update should always be performed before an upgrade or dist-upgrade.
To updating the package indexes, you need to run the following command:
$ sudo apt update
Outputs:
devops@devops-ubuntu:~$ sudo apt update
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease
Hit:5 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease
Hit:6 https://download.docker.com/linux/ubuntu bionic InRelease
Hit:7 http://repository.spotify.com stable InRelease
Hit:8 http://ppa.launchpad.net/team-xbmc/ppa/ubuntu bionic InRelease
Hit:9 https://repo.skype.com/deb stable InRelease
Get:10 http://dl.bintray.com/apache/cassandra 311x InRelease [3,183 B]
Fetched 3,183 B in 1s (2,184 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
55 packages can be upgraded. Run 'apt list --upgradable' to see them.
Upgrading Installed Packages with APT Command
Once the package index have been updated and you can use the apt
command with the subcommand “upgrade
” to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list
. type:
$ sudo apt upgrade
Outputs:
devops@devops-ubuntu:~$ sudo apt upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages will be upgraded: amd64-microcode base-files bluez bluez-cups bluez-obexd containerd.io docker-ce docker-ce-cli grep ibverbs-providers libbluetooth3 libegl-mesa0 libegl1-mesa libgbm1 libgl1-mesa-dri libgl1-mesa-dri:i386 libgl1-mesa-glx libgl1-mesa-glx:i386 libglapi-mesa libglapi-mesa:i386 libglx-mesa0 libglx-mesa0:i386 libibverbs1 libnss-myhostname libnss-systemd libpam-systemd libpython2.7 libpython2.7-minimal libpython2.7-stdlib libpython3.6 libpython3.6-dev libpython3.6-minimal libpython3.6-stdlib libsystemd0 libudev1 libudev1:i386 libwayland-egl1-mesa libxatracker2 linux-libc-dev mesa-va-drivers mesa-vdpau-drivers python2.7 python2.7-minimal python3.6 python3.6-dev python3.6-minimal python3.6-venv systemd systemd-sysv thunderbird thunderbird-gnome-support thunderbird-locale-en thunderbird-locale-en-us ubuntu-drivers-common udev 55 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 210 MB of archives. After this operation, 5,973 kB disk space will be freed. Do you want to continue? [Y/n]Y
Note: Packages currently installed with new versions available are retrieved and upgraded;
Installing Package with APT Command
If you want to install a package using apt
command, and you can install it with the subcommand “install
“. For example, you wish to install a package called wget
, and you can install it by running the following command:
$ sudo apt install wget
Outputs:
devops@devops-ubuntu:~$ sudo apt install wget
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libpango1.0-0 libpangox-1.0-0
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
wget
0 upgraded, 1 newly installed, 0 to remove and 55 not upgraded.
Need to get 316 kB of archives.
After this operation, 954 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 wget amd64 1.19.4-1ubuntu2.2 [316 kB]
Fetched 316 kB in 0s (1,620 kB/s)
Selecting previously unselected package wget.
(Reading database ... 186877 files and directories currently installed.)
Preparing to unpack .../wget_1.19.4-1ubuntu2.2_amd64.deb ...
Unpacking wget (1.19.4-1ubuntu2.2) ...
Setting up wget (1.19.4-1ubuntu2.2) ...
Processing triggers for install-info (6.5.0.dfsg.1-2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Installing Multiple Packages with APT Command
If you want to install multiple packages using apt
command at a time, and you just need to provide the package names all together to the apt command.
$ sudo apt install <package1> <package2>
Installing a Package with a Specified Version
If you do not install the latest version from the default APT repository, and you can specify the version number while installing a package using apt
command. And you need to know the exact verion number that you want to install. type:
$ sudo apt install <pacakgeName>=<versionNumber> $ sudo apt install wget=1.19.4-1ubuntu2.2
Outputs:
devops@devops-ubuntu:~$ sudo apt install wget=1.19.4-1ubuntu2.2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
wget
0 upgraded, 1 newly installed, 0 to remove and 55 not upgraded.
Need to get 316 kB of archives.
After this operation, 954 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 wget amd64 1.19.4-1ubuntu2.2 [316 kB]
Fetched 316 kB in 0s (1,617 kB/s)
Selecting previously unselected package wget.
(Reading database ... 186865 files and directories currently installed.)
Preparing to unpack .../wget_1.19.4-1ubuntu2.2_amd64.deb ...
Unpacking wget (1.19.4-1ubuntu2.2) ...
Setting up wget (1.19.4-1ubuntu2.2) ...
Processing triggers for install-info (6.5.0.dfsg.1-2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Searching for a Package with APT Command
If you want to search for the given regex term in the list of available packages and display all matched package names. you can use the apt
command with its subcommand “search
“, type:
$ sudo apt search firefox
Outputs:
devops@devops-ubuntu:~$ sudo apt search firefox Sorting... Done Full Text Search... Done firefox/bionic-security,bionic-updates,now 69.0.2+build1-0ubuntu0.18.04.1 amd64 [installed] Safe and easy web browser from Mozilla firefox-dbg/bionic-security,bionic-updates 69.0.2+build1-0ubuntu0.18.04.1 amd64 Safe and easy web browser from Mozilla - debug symbols firefox-dev/bionic-security,bionic-updates 69.0.2+build1-0ubuntu0.18.04.1 amd64 Safe and easy web browser from Mozilla - development files firefox-geckodriver/bionic-security,bionic-updates 69.0.2+build1-0ubuntu0.18.04.1 amd64 Safe and easy web browser from Mozilla - geckodriver firefox-globalmenu/bionic-security,bionic-updates 68.0.2+build1-0ubuntu0.18.04.1 amd64 Safe and easy web browser from Mozilla (transitional package) firefox-launchpad-plugin/bionic,bionic 0.5 all Launchpad firefox integration ......
Show Information about the Given Packages
If you want to show information about the given package(s) including its dependencies, installation and download size, sources the package is available from, the description of the packages content using apt command. and you can use apt
command with its subcommand “show
“, type:
$ sudo apt show firefox
Outputs:
devops@devops-ubuntu:~$ sudo apt show firefox
Package: firefox
Version: 69.0.2+build1-0ubuntu0.18.04.1
Priority: optional
Section: web
Origin: Ubuntu
Maintainer: Ubuntu Mozilla Team <ubuntu-mozillateam@lists.ubuntu.com>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 189 MB
Provides: gnome-www-browser, iceweasel, www-browser
Depends: lsb-release, libatk1.0-0 (>= 1.12.4), libc6 (>= 2.27), libcairo-gobject2 (>= 1.10.0), libcairo2 (>= 1.10.0), libdbus-1-3 (>= 1.9.14), libdbus-glib-1-2 (>= 0.78), libfontconfig1 (>= 2.12), libfreetype6 (>= 2.3.5), libgcc1 (>= 1:4.2), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.31.8), libgtk-3-0 (>= 3.4), libpango-1.0-0 (>= 1.22.0), libpangocairo-1.0-0 (>= 1.14.0), libstartup-notification0 (>= 0.8), libstdc++6 (>= 6), libx11-6, libx11-xcb1, libxcb-shm0, libxcb1, libxcomposite1 (>= 1:0.3-1), libxdamage1 (>= 1:1.1), libxext6, libxfixes3, libxrender1, libxt6
Recommends: xul-ext-ubufox, libcanberra0, libdbusmenu-glib4, libdbusmenu-gtk3-4
Suggests: fonts-lyx
Replaces: kubuntu-firefox-installer
Task: ubuntu-desktop, kubuntu-desktop, kubuntu-full, xubuntu-desktop, lubuntu-gtk-desktop, lubuntu-desktop, ubuntustudio-desktop, ubuntukylin-desktop, ubuntu-mate-core, ubuntu-mate-desktop
Xul-Appid: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
Supported: 5y
Download-Size: 50.3 MB
APT-Manual-Installed: yes
APT-Sources: http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages
Description: Safe and easy web browser from Mozilla
Firefox delivers safe, easy web browsing. A familiar user interface,
enhanced security features including protection from online identity theft,
and integrated search let you get the most out of the web.
N: There is 1 additional record. Please use the '-a' switch to see it
Remvoing Installed Packages with APT Command
If you want to remove a installed package using apt command on your ubuntu system, and you can run apt
command with remove
subcommand. and it will only remove the package files only but configuration file still remain on your system.
If you want to remove a package and its all configuration files, and you need to use apt
command with its anoter subcommand “purge
“. type:
$ sudo apt remove wget
or
$ sudo apt purge wget
Outputs:
devops@devops-ubuntu:~$ sudo apt remove wget
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libpango1.0-0 libpangox-1.0-0
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
hplip minecraft-launcher printer-driver-postscript-hp ssh-import-id ubuntu-standard wget
0 upgraded, 0 newly installed, 6 to remove and 55 not upgraded.
After this operation, 3,863 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 187040 files and directories currently installed.)
Removing printer-driver-postscript-hp (3.17.10+repack0-5) ...
Removing hplip (3.17.10+repack0-5) ...
Removing minecraft-launcher (2.1.3676) ...
Removing ssh-import-id (5.7-0ubuntu1.1) ...
Removing ubuntu-standard (1.417.3) ...
Removing wget (1.19.4-1ubuntu2.2) ...
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) ...
Processing triggers for install-info (6.5.0.dfsg.1-2) ...
Processing triggers for cups (2.2.7-1ubuntu2.7) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) ...
Processing triggers for dbus (1.12.2-1ubuntu1.1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for mime-support (3.60ubuntu1) ...
devops@devops-ubuntu:~$
Removing Unused Packages
You can use autoremove
subcommand to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed. type:
$ sudo apt autoremove
Outputs:
devops@devops-ubuntu:~$ sudo apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
libpango1.0-0 libpangox-1.0-0
0 upgraded, 0 newly installed, 2 to remove and 55 not upgraded.
After this operation, 203 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 186885 files and directories currently installed.)
Removing libpango1.0-0:amd64 (1.40.14-1ubuntu0.1) ...
Removing libpangox-1.0-0:amd64 (0.0.2-5) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Listing All Installed or Upgradeable Packages
If you want to display a list of all installed pacakges or all the packages that have a newer version can be upgraded. you can use the following commands:
$ sudo apt list --installed $ sudo apt list --upgradeable
Outputs:
devops@devops-ubuntu:~$ sudo apt list --installed
Listing... Done
accountsservice/bionic,now 0.6.45-1ubuntu1 amd64 [installed]
acl/bionic,now 2.2.52-3build1 amd64 [installed]
acpi-support/bionic,now 0.142 amd64 [installed]
acpid/bionic,now 1:2.0.28-1ubuntu1 amd64 [installed]
adduser/bionic,bionic,now 3.116ubuntu1 all [installed]
adium-theme-ubuntu/bionic,bionic,now 0.3.4-0ubuntu4 all [installed]
adwaita-icon-theme/bionic,bionic,now 3.28.0-1ubuntu1 all [installed]
aisleriot/bionic,now 1:3.22.5-1 amd64 [installed]
alien/bionic,bionic,now 8.95 all [installed]
alsa-base/bionic,bionic,now 1.0.25+dfsg-0ubuntu5 all [installed]
alsa-utils/bionic,now 1.1.3-1ubuntu1 amd64 [installed]
......
devops@devops-ubuntu:~$ sudo apt list --upgradeable
Listing... Done
amd64-microcode/bionic-proposed 3.20181128.1~ubuntu0.18.04.1 amd64 [upgradable from: 3.20180524.1~ubuntu0.18.04.2]
base-files/bionic-proposed 10.1ubuntu2.7 amd64 [upgradable from: 10.1ubuntu2.6]
bluez/bionic-proposed 5.48-0ubuntu3.2 amd64 [upgradable from: 5.48-0ubuntu3.1]
bluez-cups/bionic-proposed 5.48-0ubuntu3.2 amd64 [upgradable from: 5.48-0ubuntu3.1]
bluez-obexd/bionic-proposed 5.48-0ubuntu3.2 amd64 [upgradable from: 5.48-0ubuntu3.1]
containerd.io/bionic 1.2.10-2 amd64 [upgradable from: 1.2.6-3]
......
If you want to get more help while using apt command, and you can use the following commands:
$ man apt $ man apt-get $ apt help
Outputs:
devops@devops-ubuntu:~$ apt help
apt 1.6.12 (amd64)
Usage: apt [options] command
apt is a commandline package manager and provides commands for
searching and managing as well as querying information about packages.
It provides the same functionality as the specialized APT tools,
like apt-get and apt-cache, but enables options more suitable for
interactive use by default.
Most used commands:
list - list packages based on package names
search - search in package descriptions
show - show package details
install - install packages
remove - remove packages
autoremove - Remove automatically all unused packages
update - update list of available packages
upgrade - upgrade the system by installing/upgrading packages
full-upgrade - upgrade the system by removing/installing/upgrading packages
edit-sources - edit the source information file
See apt(8) for more information about the available commands.
Configuration options and syntax is detailed in apt.conf(5).
Information about how to configure sources can be found in sources.list(5).
Package and version choices can be expressed via apt_preferences(5).
Security details are available in apt-secure(8).
This APT has Super Cow Powers.
devops@devops-ubuntu:~$
Conclusion
You should know that how to use APT pacakge management Tool to install/remove/update/upgrade packages in your Ubuntu or Debian based systmes.