How To Use APT-GET and APT-CACHE for Package Management In Linux
Basic Commands of APT-CACHE and APT-GET for Package Management
Installation, removal, updation and searching of software packages with the help of apt-cache and apt-get commands from the command line are discussed in this tutorial.
apt-get
An effective and free package management command line program is called apt-get, which is utilized to work with APT (Advanced Packaging Tool) library of Ubuntu for the removal of existing software packages, installation of new software packages and so on.
apt-cache
It searches apt software package cache.
Listing of All Available Packages with the following command
root@linuxhelp:~# apt-cache pkgnames
account-plugin-yahoojp
ceph-fuse
dvd+rw-tools
.
.
.
postgresql-9.4-pllua
python3-power
vtkdata
Finding Out Name of the Package and Software Description
Utilize the ‘ search‘ flag.
root@linuxhelp:~# apt-cache search vlc
libdvd-pkg - download and install software necessary to play video DVDs
browser-plugin-vlc - multimedia plugin for web browsers based on VLC
cubemap - scalable video reflector, designed to be used with VLC
dvblast - Simple and powerful dvb-streaming application
.
.
.
vlc-plugin-svg - SVG plugin for VLC
vlc-plugin-vlsub - VLC extension to download subtitles from opensubtitles.org
vlc-plugin-zvbi - VBI teletext plugin for VLC
x264 - video encoder for the H.264/MPEG-4 AVC standard
Use the following command for finding and listing the packages, which are starting with ‘ vsftpd' .
root@linuxhelp:~# apt-cache pkgnames vsftpd
vsftpd
vsftpd-dbg
To Check Package Information
Use ‘ show‘ flag with apt-cache command as follows.
root@linuxhelp:~# apt-cache show vlc
Package: vlc
Priority: optional
Section: universe/graphics
Installed-Size: 4711
Maintainer: Ubuntu Developers < ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Multimedia Maintainers < pkg-multimedia-maintainers@lists.alioth.debian.org>
Architecture: amd64
Version: 2.2.1-3
.
.
.
vlc-plugin-notify, vlc-plugin-samba, vlc-plugin-sdl, vlc-plugin-svg,
vlc-plugin-zvbi).
Description-md5: c3a7a10e39c9ddd30da6653ec2238442
Homepage: http://www.videolan.org/vlc/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Task: mythbuntu-frontend, mythbuntu-desktop, mythbuntu-backend-slave, mythbuntu-backend-master, ubuntu-mate-desktop, ubuntu-mate-cloudtop
To Check Dependencies for particular Packages
Use the ‘ showpkg‘ flag.
root@linuxhelp:~# apt-cache showpkg apache2
Package: apache2
Versions:
2.4.12-2ubuntu2 (/var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_wily_main_binary-amd64_Packages)
Description Language:
File: /var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_wily_main_binary-amd64_Packages
MD5: d02426bc360345e5acd45367716dc35c
Description Language: en
File: /var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_wily_main_i18n_Translation-en
MD5: d02426bc360345e5acd45367716dc35c
Reverse Depends:
squid-cgi,apache2
.
.
.
apache2-doc,apache2
apache2-dbg,apache2 2.4.12-2ubuntu2
Dependencies:
2.4.12-2ubuntu2 - lsb-base (0 (null)) procps (0 (null)) perl (0 (null)) mime-support (0 (null)) apache2-bin (5 2.4.12-2ubuntu2) apache2-utils (2 2.4) apache2-data (5 2.4.12-2ubuntu2) dpkg (2 1.17.14) www-browser (0 (null)) apache2-doc (0 (null)) apache2-suexec-pristine (16 (null)) apache2-suexec-custom (0 (null)) ufw (0 (null)) ssl-cert (0 (null)) apache2.2-common (3 2.3~) apache2.2-common:i386 (3 2.3~) apache2.2-common (0 (null)) apache2.2-common:i386 (0 (null)) apache2:i386 (0 (null))
Provides:
2.4.12-2ubuntu2 - httpd-cgi httpd
Reverse Provides:
To Check the statistics of Cache
Use the ‘ stats‘ flag to check statistics.
root@linuxhelp:~# apt-cache stats
Total package names: 65990 (1,320 k)
Total package structures: 110767 (6,203 k)
Normal packages: 76420
Pure virtual packages: 1423
Single virtual packages: 9348
Mixed virtual packages: 2017
Missing: 21559
Total distinct versions: 81708 (5,883 k)
Total distinct descriptions: 101834 (2,444 k)
Total dependencies: 630746 (17.7 M)
Total ver/file relations: 85913 (2,062 k)
Total Desc/File relations: 101834 (2,444 k)
Total Provides mappings: 18563 (371 k)
Total globbed strings: 163 (2,123 )
Total dependency version space: 3,046 k
Total slack space: 33.1 k
Total space accounted for: 32.2 M
To Update System Package
For the synchronization of the package index files, use ‘ update‘ command.
root@linuxhelp:~# apt-get update
Hit http://in.archive.ubuntu.com wily InRelease
Hit http://in.archive.ubuntu.com wily-updates InRelease
Hit http://security.ubuntu.com wily-security InRelease
.
.
.
Hit http://in.archive.ubuntu.com wily-backports/multiverse Translation-en
Hit http://in.archive.ubuntu.com wily-backports/restricted Translation-en
Hit http://in.archive.ubuntu.com wily-backports/universe Translation-en
Reading package lists... Done
To Upgrade Software Packages
For upgrading all the presently installed system software packages, use the ‘ upgrade‘ command.
root@linuxhelp:~# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... The following packages were automatically installed and are no longer required:
libntdb1 python-ntdb
Use ' apt-get autoremove' to remove them.
Done
The following packages have been kept back:
liboxideqt-qmlplugin liboxideqtcore0 liboxideqtquick0 linux-generic
linux-headers-generic linux-image-generic oxideqt-codecs
The following packages will be upgraded:
apport apport-gtk apt apt-transport-https apt-utils bind9-host binutils
ca-certificates compiz compiz-core compiz-gnome compiz-plugins-default cpio
.
.
.
Get:24 http://in.archive.ubuntu.com/ubuntu/ wily-updates/main systemd-sysv amd64 225-1ubuntu9.1 [13.0 kB]
Get:25 http://in.archive.ubuntu.com/ubuntu/ wily-updates/main libpam-systemd amd64 225-1ubuntu9.1 [113 kB]
Software packages will be added or removed to fulfill dependencies, use the ‘ dist-upgrade‘ .
root@linuxhelp:~# apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... The following packages were automatically installed and are no longer required:
libntdb1 python-ntdb
Use ' apt-get autoremove' to remove them.
Done
The following NEW packages will be installed:
fonts-stix libandroid-properties1 linux-headers-4.2.0-38
linux-headers-4.2.0-38-generic linux-image-4.2.0-38-generic
linux-image-extra-4.2.0-38-generic
The following packages will be upgraded:
apport apport-gtk apt apt-transport-https apt-utils bind9-host binutils
ca-certificates compiz compiz-core compiz-gnome compiz-plugins-default cpio
.
.
.
Get:1 http://in.archive.ubuntu.com/ubuntu/ wily-updates/main systemd amd64 225-1ubuntu9.1 [3,331 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu/ wily-updates/main libldap-2.4-2 amd64 2.4.41+dfsg-1ubuntu2.1 [161 kB]
Installing or Upgrading particular Packages
Use the ‘ install‘ flag with the specific package name to install.
root@linuxhelp:~# apt-get install apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
Suggested packages:
apache2-doc apache2-suexec-pristine apache2-suexec-custom
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
.
.
.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Processing triggers for libc-bin (2.21-0ubuntu4) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (225-1ubuntu9) ...
Processing triggers for ufw (0.34-2) ...
Installation of Multiple Packages
Use the below command for installing one or more packages like ‘ goaccess‘ and ‘ nethogs‘ .
root@linuxhelp:~# apt-get install nethogs goaccess
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
goaccess nethogs
0 upgraded, 2 newly installed, 0 to remove and 244 not upgraded.
Need to get 93.7 kB of archives.
After this operation, 308 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu/ wily/universe nethogs amd64 0.8.0-1 [28.3 kB]
.
.
.
Unpacking goaccess (1:0.8.3-1) ...
Processing triggers for man-db (2.7.4-1) ...
Setting up nethogs (0.8.0-1) ...
Setting up goaccess (1:0.8.3-1) ...
Installation of some Packages using Wildcard
root@linuxhelp:~# apt-get install ' *test*'
This command will install all the packages name that contains ' test' word.
Installation of Packages without Upgrading
Use sub ‘ --no-upgrade‘ command.
root@linuxhelp:~# apt-get install apache2 --no-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
apache2-doc apache2-suexec-pristine apache2-suexec-custom
.
.
.
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (225-1ubuntu9) ...
Processing triggers for ufw (0.34-2) ...
Setting up apache2 (2.4.12-2ubuntu2) ...
To Upgrade particular Packages
Use ‘ --only-upgrade‘ command .
root@linuxhelp:~# apt-get install vsftpd --only-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
vsftpd is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 244 not upgraded.
Installation of particular Package Version
Utilize the ‘ =‘ with the name of the package and append required version. If the correct version is not mentioned, the following error will appear.
root@linuxhelp:~# apt-get install apache2=2.2* Reading package lists... Done Building dependency tree Reading state information... Done E: Version ' 2.2*' for ' apache2' was not found root@linuxhelp:~# apt-get install apache2=2* Reading package lists... Done Building dependency tree Reading state information... Done Selected version ' 2.4.12-2ubuntu2' (Ubuntu:15.10/wily [amd64]) for ' apache2' Suggested packages: apache2-doc apache2-suexec-pristine apache2-suexec-custom The following NEW packages will be installed: apache2 . . . Processing triggers for systemd (225-1ubuntu9) ... Processing triggers for ufw (0.34-2) ... Setting up apache2 (2.4.12-2ubuntu2) ...
Removal of Packages Without Configuration
Utilize the ‘ remove‘ command.
root@linuxhelp:~# apt-get remove apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
Use ' apt-get autoremove' to remove them.
The following packages will be REMOVED:
apache2
0 upgraded, 0 newly installed, 1 to remove and 244 not upgraded.
After this operation, 484 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 180430 files and directories currently installed.)
Removing apache2 (2.4.12-2ubuntu2) ...
Processing triggers for man-db (2.7.4-1) ...
Processing triggers for ufw (0.34-2) ...
Complete Removal of Packages
Use the ‘ purge‘ sub command.
root@linuxhelp:~# apt-get purge apache2 Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0 Use ' apt-get autoremove' to remove them. The following packages will be REMOVED: apache2* 0 upgraded, 0 newly installed, 1 to remove and 244 not upgraded. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] y (Reading database ... 180389 files and directories currently installed.) Removing apache2 (2.4.12-2ubuntu2) ... Purging configuration files for apache2 (2.4.12-2ubuntu2) ...
Combination of both the commands is as follows
root@linuxhelp:~# apt-get remove --purge vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
Use ' apt-get autoremove' to remove them.
The following packages will be REMOVED:
vsftpd*
0 upgraded, 0 newly installed, 1 to remove and 244 not upgraded.
After this operation, 331 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 180231 files and directories currently installed.)
Removing vsftpd (3.0.2-20ubuntu1) ...
Purging configuration files for vsftpd (3.0.2-20ubuntu1) ...
Processing triggers for man-db (2.7.4-1) ...
Cleaning Up of Disk Space
Use the ‘ clean‘ command.
root@linuxhelp:~# apt-get clean
Downloading Package Source Code
Utilize ‘ --download-only source‘ with ‘ package-name’ .
root@linuxhelp:~# apt-get --download-only source vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
NOTICE: ' vsftpd' packaging is maintained in the ' Git' version control system at:
git://anonscm.debian.org/collab-maint/vsftpd.git
Need to get 189 kB of source archives.
Get:1 http://in.archive.ubuntu.com/ubuntu/ wily/main vsftpd 3.0.2-20ubuntu1 (dsc) [1,727 B]
Get:2 http://in.archive.ubuntu.com/ubuntu/ wily/main vsftpd 3.0.2-20ubuntu1 (tar) [153 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu/ wily/main vsftpd 3.0.2-20ubuntu1 (diff) [34.7 kB]
Fetched 189 kB in 1s (144 kB/s)
Download and Unpack of a Package with the following command.
root@linuxhelp:~# apt-get source vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
NOTICE: ' vsftpd' packaging is maintained in the ' Git' version control system at:
git://anonscm.debian.org/collab-maint/vsftpd.git
Skipping already downloaded file ' vsftpd_3.0.2-20ubuntu1.dsc'
Skipping already downloaded file ' vsftpd_3.0.2.orig.tar.xz'
Skipping already downloaded file ' vsftpd_3.0.2-20ubuntu1.debian.tar.xz'
Need to get 0 B of source archives.
gpgv: Signature made Friday 07 August 2015 02:32:08 AM IST using RSA key ID 67884CF6
gpgv: Can' t check signature: public key not found
dpkg-source: warning: failed to verify signature on ./vsftpd_3.0.2-20ubuntu1.dsc
.
.
.
dpkg-source: info: applying 0050-CVE-2015-1419.patch
dpkg-source: info: applying 0055-set_default_listen.patch
dpkg-source: info: applying 0060-seccomp_sandbox.patch
Downloading, Unpacking and Compiling of a Package
Use ‘ --compile‘ option with ' source' to unpack and compile the package.
root@linuxhelp:~# apt-get --compile source goaccess
Reading package lists... Done
Building dependency tree
Reading state information... Done
Skipping already downloaded file ' goaccess_0.8.3-1.dsc'
Skipping already downloaded file ' goaccess_0.8.3.orig.tar.gz'
Skipping already downloaded file ' goaccess_0.8.3-1.debian.tar.xz'
Need to get 0 B of source archives.
Skipping unpack of already unpacked source in goaccess-0.8.3
dpkg-buildpackage: source package goaccess
dpkg-buildpackage: source version 1:0.8.3-1
dpkg-buildpackage: source distribution unstable
dpkg-buildpackage: source changed by Chris Taylor < ctaylor@debian.org>
dpkg-buildpackage: host architecture amd64
dpkg-source --before-build goaccess-0.8.3
dpkg-checkbuilddeps: Unmet build dependencies: debhelper (> = 9) autotools-dev libncurses5-dev libglib2.0-dev libgeoip-dev autoconf
dpkg-buildpackage: warning: build dependencies/conflicts unsatisfied aborting
dpkg-buildpackage: warning: (Use -d flag to override.)
Downloading of a Package Without Installation
Use ‘ download‘ option.
root@linuxhelp:~# apt-get download nethogs
Get:1 http://in.archive.ubuntu.com/ubuntu/ wily/universe nethogs amd64 0.8.0-1 [28.3 kB]
Fetched 28.3 kB in 5s (5,027 B/s)
To Check Package Change Log
The installed package version is shown as below.
root@linuxhelp:~# apt-get changelog apache2
Get:1 Changelog for apache2 (http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.4.12-2ubuntu2/changelog) [208 kB]
Fetched 208 kB in 3s (52.7 kB/s)
To Check Broken Dependencies
Use the diagnostic tool called ‘ check‘ command.
root@linuxhelp:~# apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done
Searching and Building of Dependencies
Use the ‘ build-dep‘ command.
root@linuxhelp:~# apt-get build-dep netcat
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
debhelper po-debconf
0 upgraded, 2 newly installed, 0 to remove and 244 not upgraded.
Need to get 966 kB of archives.
.
.
.
Processing triggers for doc-base (0.10.6) ...
Processing 1 added doc-base file...
Setting up po-debconf (1.0.18) ...
Setting up debhelper (9.20150811ubuntu2) ...
Auto cleaning of Apt-Get Cache
Use the ‘ autoclean‘ command.
root@linuxhelp:~# apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done
Auto removal of Installed Packages
Use the ‘ autoremove‘ sub command.
root@linuxhelp:~# apt-get autoremove vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package ' vsftpd' is not installed, so not removed
The following packages will be REMOVED:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
.
.
.
Removing libapr1:amd64 (1.5.2-3) ...
Removing liblua5.1-0:amd64 (5.1.5-8) ...
Processing triggers for man-db (2.7.4-1) ...
Processing triggers for libc-bin (2.21-0ubuntu4) ...
# apt-cache show vlc
Install is to install the packages in the repository
# apt-get dist-upgrade
#apt-get install apache2 --no-upgrade
# apt-cache showpkg apache2