Table of Contents
In this article, I will take you through 20 Useful APT GET Examples on Ubuntu 18.04. APT utilities download packages and call dpkg utilities to manipulate the packages once they are on the local system. The primary APT command is apt-get, its arguments determine what the command does.
To know more about APT CACHE, you can check 13 Useful APT CACHE Examples on Ubuntu 18.04.
What is APT GET
APT GET(Advanced Package Tool) is basically a utility that download, install, remove, upgrade and update packages in your Debian based Systems.
Prerequisites
a)You only require a running Ubuntu 18.04 System.
b)You can either run all commands through root user or with user having sudo access. Please check How to add User into Sudoers to provide sudo access to a User.
APT GET Examples
Also Read: 13 Useful examples of touch Command in Linux
1. Check APT GET Version
To check the apt-get version, you need to run sudo apt-get -v
command. As you can see from the below output, current version in 1.6.11.
test@localhost:~$ sudo apt-get -v apt 1.6.11 (amd64) Supported modules: *Ver: Standard .deb *Pkg: Debian dpkg interface (Priority 30) Pkg: Debian APT solver interface (Priority -1000) Pkg: Debian APT planner interface (Priority -1000) S.L: 'deb' Debian binary tree S.L: 'deb-src' Debian source tree Idx: Debian Source Index
2. Update System Using APT GET Update
To update your system with all the latest updates available in repository, you can run sudo apt-get update
command. In this case since system is already updated so it is not showing any latest updates to install.
test@localhost:~$ sudo apt-get update Hit:1 http://in.archive.ubuntu.com/ubuntu bionic InRelease Get:2 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB] Hit:3 https://artifacts.elastic.co/packages/7.x/apt stable InRelease Get:4 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB] Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB] Get:6 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [843 kB] Get:7 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [38.5 kB]
3. Upgrade Packages Using APT GET Upgrade
To upgrade all the packages in your system, you can run sudo apt-get upgrade
command.
test@localhost:~$ sudo apt-get upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages were automatically installed and are no longer required: gir1.2-geocodeglib-1.0 ubuntu-web-launchers Use 'sudo apt autoremove' to remove them. The following packages have been kept back: libgl1-mesa-dri libxatracker2 linux-generic-hwe-18.04 linux-headers-generic-hwe-18.04 linux-image-generic-hwe-18.04 The following packages will be upgraded: apt apt-utils base-files bluez bluez-cups bluez-obexd bsdutils dmsetup dpkg elasticsearch fdisk firefox firefox-locale-en gdb gdbserver gir1.2-javascriptcoregtk-4.0 gir1.2-mutter-2 gir1.2-nm-1.0 gir1.2-nma-1.0 gir1.2-snapd-1 gir1.2-webkit2-4.0 gnome-control-center gnome-control-center-data gnome-control-center-faces
4. Cleanup Repository Using APT GET AUTOCLEAN
Sometimes you might want to clean your repository of retrieved package files, in those cases you need to use sudo apt-get autoclean
command and clean the repository.
test@localhost:~$ sudo apt-get autoclean Reading package lists... Done Building dependency tree Reading state information... Done
5. Remove files Using APT GET AUTOREMOVE
In few cases you want to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed. For those cases you can use autoremove
option as shown below.
test@localhost:~$ sudo apt-get autoremove Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 0 to remove and 153 not upgraded.
6. Install Packages Using APT GET INSTALL
If you want to install any packages say apache2 in your Server, you can run sudo apt-get install apache2
command and install it. Since I already installed the latest version of apache2 so it won't install it again.
test@localhost:~$ sudo apt-get install apache2 Reading package lists... Done Building dependency tree Reading state information... Done apache2 is already the newest version (2.4.29-1ubuntu4.11). 0 upgraded, 0 newly installed, 0 to remove and 153 not upgraded.
7. Change Dependencies to New Version During Upgrade
If you are trying to upgrade your Server, you probably also want to install the latest version of all the dependencies during upgrade. You can do that by using dist-upgrade
option with apt get command as shown below.
test@localhost:~$ sudo apt-get dist-upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages were automatically installed and are no longer required: gir1.2-geocodeglib-1.0 libllvm8 ubuntu-web-launchers Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: libllvm9 linux-headers-5.3.0-28 linux-headers-5.3.0-28-generic linux-image-5.3.0-28-generic linux-modules-5.3.0-28-generic linux-modules-extra-5.3.0-28-generic The following packages will be upgraded: apt apt-utils base-files bluez bluez-cups bluez-obexd bsdutils dmsetup dpkg elasticsearch fdisk firefox firefox-locale-en gdb gdbserver gir1.2-javascriptcoregtk-4.0 gir1.2-mutter-2 gir1.2-nm-1.0 gir1.2-nma-1.0 gir1.2-snapd-1 gir1.2-webkit2-4.0 gnome-control-center gnome-control-center-data gnome-control-center-faces
8. Purge Packages using APT GET Purge
If you want to remove anything that can be removed, then you need to use sudo apt-get purge
command to remove those files.
test@localhost:~$ sudo apt-get purge Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 0 to remove and 153 not upgraded.
9. Download Packages Using APT GET Download
If you only want to download a package and does not want to install it, then you can use sudo apt-get download apache2
command to download apache2 package.
test@localhost:~$ sudo apt-get download apache2 Get:1 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2 amd64 2.4.29-1ubuntu4.11 [95.1 kB] Fetched 95.1 kB in 0s (423 kB/s)
NOTE:
10. Download ChangeLog Using APT GET
If you want to download changelog of a package say for apache2 package in this case, then you need to run sudo apt-get changelog apache2
command. You can see from below output it has fetched the changelog of apache2 2.4.29 package.
test@localhost:~$ sudo apt-get changelog apache2 Get:1 https://changelogs.ubuntu.com apache2 2.4.29-1ubuntu4.11 Changelog [247 kB] Fetched 247 kB in 1s (180 kB/s)
11. Check Broken Packages
If you want to check all the broken packages in your repository, you can do that by running sudo apt-get check
command. In this case, there is no broken packages as you can see from below output.
test@localhost:~$ sudo apt-get check Reading package lists... Done Building dependency tree Reading state information... Done
12. Simulate Package Installation
If you only want to perform a simulation of even and does not want to really change anything in your system, then you can run sudo apt-get install terminator --simulate
command to check how terminator package will change your system.
test@localhost:~$ sudo apt-get install terminator --simulate Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: gir1.2-keybinder-3.0 libkeybinder-3.0-0 python-cairo python-dbus python-gi python-gi-cairo python-psutil Suggested packages: python-dbus-dbg python-dbus-doc python-psutil-doc The following NEW packages will be installed: gir1.2-keybinder-3.0 libkeybinder-3.0-0 python-cairo python-dbus python-gi python-gi-cairo python-psutil terminator 0 upgraded, 8 newly installed, 0 to remove and 153 not upgraded. Inst libkeybinder-3.0-0 (0.3.2-1 Ubuntu:18.04/bionic [amd64]) Inst gir1.2-keybinder-3.0 (0.3.2-1 Ubuntu:18.04/bionic [amd64])
NOTE:
terminator
package as an example here. You can choose any package as per your requirement.13. Only Upgrade the Packages
If you only want to upgrade your packages and does not want to really install any package, then you can use --only-upgrade
option with apt get command to do that as shown below.
test@localhost:~$ sudo apt-get install terminator --only-upgrade Reading package lists... Done Building dependency tree Reading state information... Done Skipping terminator, it is not installed and only upgrades are requested. 0 upgraded, 0 newly installed, 0 to remove and 153 not upgraded.
14. Check Installation Suggestions
If you want to check all the suggestions currently available during a package installation, then you can use --install-suggests
option to do that as shown below.
test@localhost:~$ sudo apt-get install terminator --install-suggests Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: blt blt-demo fonts-font-awesome fonts-lato gir1.2-keybinder-3.0 javascript-common libjs-jquery libjs-modernizr libjs-sphinxdoc libjs-underscore libkeybinder-3.0-0 Suggested packages: python2.7-gdbm-dbg python2.7-tk-dbg The following NEW packages will be installed: blt blt-demo fonts-font-awesome fonts-lato gir1.2-keybinder-3.0 javascript-common libjs-jquery libjs-modernizr libjs-sphinxdoc libjs-underscore libkeybinder-3.0-0 0 upgraded, 37 newly installed, 0 to remove and 153 not upgraded. Need to get 20.7 MB of archives. After this operation, 76.9 MB of additional disk space will be used. Do you want to continue? [Y/n] n
15. Assume Yes to all Question Asked
If you want to answer Yes to all the questions asked during installation, then you can use -y
option to do that. It will not ask you any questions during package installation and will consider yes as an answer to all questions.
test@localhost:~$ sudo apt-get install openssl -y Reading package lists... Done Building dependency tree Reading state information... Done openssl is already the newest version (1.1.1-1ubuntu2.1~18.04.5). openssl set to manually installed. 0 upgraded, 0 newly installed, 0 to remove and 153 not upgraded
16. Ignore Any Hold Packages
If you want to ignore all the packages which has a hold places on it during a installation, then you can use --ignore-hold
option and ignore it as shown below.
test@localhost:~$ sudo apt-get install docker --ignore-hold Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: docker 0 upgraded, 1 newly installed, 0 to remove and 153 not upgraded. Need to get 12.9 kB of archives. After this operation, 45.1 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 docker amd64 1.5-1build1 [12.9 kB] Fetched 12.9 kB in 0s (109 kB/s) Selecting previously unselected package docker. (Reading database ... 274874 files and directories currently installed.) Preparing to unpack .../docker_1.5-1build1_amd64.deb ... Unpacking docker (1.5-1build1) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Setting up docker (1.5-1build1) ...
17. Uninstall Packages Using APT GET REMOVE
If you want to uninstall any packages say docker
package in this case, you can run sudo apt-get remove
docker command to remove docker package from the system.
test@localhost:~$ sudo apt-get remove docker Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: docker 0 upgraded, 0 newly installed, 1 to remove and 153 not upgraded. After this operation, 45.1 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 274880 files and directories currently installed.) Removing docker (1.5-1build1) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
18. Do not Show Packages which Needs to be Upgraded
If you do not want to show all the packages list which needs to be upgraded during any installation, then you need to run sudo apt-get install docker --no-show-upgraded
command as shown below.
test@localhost:~$ sudo apt-get install docker --no-show-upgraded Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: docker 0 upgraded, 1 newly installed, 0 to remove and 153 not upgraded. Need to get 0 B/12.9 kB of archives. After this operation, 45.1 kB of additional disk space will be used. Selecting previously unselected package docker. (Reading database ... 274874 files and directories currently installed.) Preparing to unpack .../docker_1.5-1build1_amd64.deb ... Unpacking docker (1.5-1build1) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Setting up docker (1.5-1build1) ...
19. Install New Packages during APT GET Upgrade
If you want to install new packages available in the repository during upgrade, you can do that by running sudo apt-get upgrade --with-new-pkgs
command. This is useful if the update of a installed package requires new dependencies to be installed. Instead of holding the package back upgrade will upgrade the package and install the new dependencies as shown below.
test@localhost:~$ sudo apt-get upgrade --with-new-pkgs Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages were automatically installed and are no longer required: gir1.2-geocodeglib-1.0 libllvm8 ubuntu-web-launchers Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: libllvm9 linux-headers-5.3.0-28 linux-headers-5.3.0-28-generic linux-image-5.3.0-28-generic linux-modules-5.3.0-28-generic linux-modules-extra-5.3.0-28-generic The following packages will be upgraded: apt apt-utils base-files bluez bluez-cups bluez-obexd bsdutils dmsetup dpkg elasticsearch fdisk firefox firefox-locale-en gdb gdbserver gir1.2-javascriptcoregtk-4.0 gir1.2-mutter-2 gir1.2-nm-1.0 gir1.2-nma-1.0 gir1.2-snapd-1 gir1.2-webkit2-4.0 gnome-control-center gnome-control-center-data gnome-control-center-faces gnome-initial-setup gnome-shell gnome-shell-common gnome-software gnome-software-common gnome-software-plugin-snap grep grub-common grub-pc grub-pc-bin grub2-common
NOTE:
20. Check Other Options Using --help
If you to check all the options available with apt get, then you can run apt-get --help
command and check.
test@localhost:~$ apt-get --help apt 1.6.11 (amd64) Usage: apt-get [options] command apt-get [options] install|remove pkg1 [pkg2 ...] apt-get [options] source pkg1 [pkg2 ...] apt-get is a command line interface for retrieval of packages and information about them from authenticated sources and for installation, upgrade and removal of packages together with their dependencies. Most used commands: update - Retrieve new lists of packages upgrade - Perform an upgrade
Also Read: A Practical Guide to Linux Commands
Reference: APT-GET MAN Page
Nicely done, onley thing i was puzzeld while apche installed is was getting a read file couldnt get out so i had to seach for it 🙂
Thanks alot!