Useful Apt-Get and Apt-Cache commands for Ubuntu/Debian/Linux Mint

apt-get is a  package management command line tool. It is used to download, install & remove and update software packages that are on online repositories. On the other hand apt-cache is used to to search and get information about the packages available in the repository.

1. Update Software sources.

This is one of the very common APT commands. It is used to update software repositories. It updates the database of available packages.

aman@vostro:~$ sudo apt-get update
[sudo] password for aman:
Ign http://dl.google.com stable InRelease
Get:1 http://dl.google.com stable Release.gpg [198 B]
Get:2 http://deb.opera.com stable InRelease [2,590 B]
Ign http://ppa.launchpad.net vivid InRelease
Get:3 http://dl.google.com stable Release [1,347 B]
Ign http://ppa.launchpad.net vivid InRelease
Get:4 http://dl.google.com stable/main amd64 Packages [1,182 B]
Get:5 http://deb.opera.com stable/non-free amd64 Packages [1,768 B]
Get:6 http://dl.google.com stable/main i386 Packages [1,193 B]....

2. Update all the installed software packages

the above update command should be performed before entering this upgrade command.

aman@vostro:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
gcc-5-base libegl1-mesa libgbm1 libgcc1 libgl1-mesa-dri libgl1-mesa-glx
libglapi-mesa libgles1-mesa libgles2-mesa libosmesa6 libwayland-egl1-mesa
linux-generic linux-headers-generic linux-image-generic linux-tools-generic
linux-tools-virtual wine1.6 wine1.6-amd64
The following packages will be upgraded:
apport apport-gtk bind9-host chromium-browser chromium-browser-l10n
chromium-codecs-ffmpeg-extra dkms dnsutils evolution-data-server
evolution-data-server-common evolution-data-server-online-accounts firefox
flashplugin-installer gir1.2-networkmanager-1.0 google-chrome-stable
indicator-appmenu irqbalance jayatana libapache2-mod-php5 libbind9-90
libcamel-1.2-49 libdns-export100 libdns100 libebackend-1.2-7 libebook-1.2-14
....

3. Download and Install/Upgrade a particular software package.

 you can also specify multiple packages to install, by giving spaces in between them.

aman@vostro:~$ sudo apt-get install vlc
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
videolan-doc
The following NEW packages will be installed:
vlc
0 upgraded, 1 newly installed, 0 to remove and 114 not upgraded.
Need to get 1,495 kB of archives.
After this operation, 4,898 kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
vlc
Install these packages without verification? [y/N] y
0% [Waiting for headers]Get:1 http://in.archive.ubuntu.com/ubuntu/ vivid/universe vlc amd64 2.2.0-1 [1,495 kB]Fetched 1,495 kB in 1min 20s (18.6 kB/s)
Selecting previously unselected package vlc.
(Reading database ... 465318 files and directories currently installed.)
Preparing to unpack .../archives/vlc_2.2.0-1_amd64.deb ...
Unpacking vlc (2.2.0-1) ...
Processing triggers for mime-support (3.58ubuntu1) ...
Processing triggers for vlc-nox (2.2.0-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
Processing triggers for gnome-menus (3.10.1-0ubuntu5) ...
Processing triggers for bamfdaemon (0.5.1+15.04.20150202-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Setting up vlc (2.2.0-1) ...

4. Download a package.

 you can download a package without installing it. It will be downloaded to your current directory. And you can install it later using the dpkg utility.

aman@vostro:~$sudo apt-get download vlc
[sudo] password for aman:
Get:1 http://in.archive.ubuntu.com/ubuntu/ vivid/universe vlc amd64 2.2.0-1 [1,495 kB]Fetched 1,495 kB in 19s (77.0 kB/s)

5. Remove a particular sofware 

here also you can also specify multiple software packages to be removed

aman@vostro:~$ sudo apt-get remove vlc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
vlc
0 upgraded, 0 newly installed, 1 to remove and 114 not upgraded.
After this operation, 4,898 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 465375 files and directories currently installed.)
Removing vlc (2.2.0-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
Processing triggers for mime-support (3.58ubuntu1) ...
Processing triggers for gnome-menus (3.10.1-0ubuntu5) ...
Processing triggers for bamfdaemon (0.5.1+15.04.20150202-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for vlc-nox (2.2.0-1) ...

6. Remove a package along with its configuration files.

aman@vostro:~$ sudo apt-get --purge remove vlc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
vlc*
0 upgraded, 0 newly installed, 1 to remove and 114 not upgraded.
After this operation, 4,898 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 465375 files and directories currently installed.)
Removing vlc (2.2.0-1) ...
Purging configuration files for vlc (2.2.0-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
Processing triggers for mime-support (3.58ubuntu1) ...
Processing triggers for gnome-menus (3.10.1-0ubuntu5) ...
Processing triggers for bamfdaemon (0.5.1+15.04.20150202-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for vlc-nox (2.2.0-1) ...

7. Remove a package with its dependencies

while installing a software package certain software are automatically installed to satisfy dependencies of that software and are no longer needed. remove the software along with its dependencies with this command

aman@vostro:~$ sudo apt-get autoremove vlc
[sudo] password for aman:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
vlc
0 upgraded, 0 newly installed, 1 to remove and 127 not upgraded.
After this operation, 4,898 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 465375 files and directories currently installed.)
Removing vlc (2.2.0-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
Processing triggers for mime-support (3.58ubuntu1) ...
Processing triggers for gnome-menus (3.10.1-0ubuntu5) ...
Processing triggers for bamfdaemon (0.5.1+15.04.20150202-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for vlc-nox (2.2.0-1) ...

8. Clean up package archieves 

when you install a package using apt-get install command. it is downloaded in /var/cache/apt/archives directory to speed up installation, if it is needed again. But after installing a lot of software, a lot of space is occupied. If you want to free up space used by those packages use the following command to clean the archives.

aman@vostro:~$ sudo apt-get clean

9. clean unused downloaded packages

This command is similar to the above clean command. The difference is that unlike clean, which clears all the archives. autoclean removes only those packages which are useless and will not be needed anymore.

aman@vostro:~$ sudo apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done

10. Fix broken packages

This command searches for broken dependencies and tries to fix them.

aman@vostro:~$ sudo apt-get install -f

11. Search package database for a software

This command searches the package database (repository) for the keyword given. The package name and descriptions are shown wherever the keyword is found. For example to search the all packages containing ‘vlc’ keyword, give the following command

aman@vostro:~$ apt-cache search vlc
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
freeplayer - wrapper around vlc for French ADSL FreeBox
freetuxtv - Internet television and radio player
getstream - DVB streaming application
gnome-media-player - A simple media player for GNOME
hdhomerun-config - Configuration utility for Silicon Dust HD HomeRun
hdhomerun-config-gui - GUI Configuration utility for Silicon Dust HD HomeRun
laditools - Linux Audio Desktop Integration Tools
libavbin0 - cross-platform media decoding library
libbluray-bdj - Blu-ray Disc Java support library (BD-J library)
libbluray-bin - Blu-ray disc playback support library (tools)
libbluray-dev - Blu-ray disc playback support library (development files)
libbluray-doc - Blu-ray disc playback support library (documentation)
libbluray1 - Blu-ray disc playback support library (shared library)
libbluray1-dbg - Blu-ray disc playback support library (debug symbols)
libhdhomerun-dev - Development library for Silicon Dust HD HomeRun
libhdhomerun1 - Library for Silicon Dust HD HomeRun
libvcdinfo-dev - library to extract information from VideoCD (development files)
libvcdinfo0 - library to extract information from VideoCD
....

12. Display information about a software

Get details about the software like installation size, category, version, architechture….

aman@vostro:~$ apt-cache show vlc
Package: vlc
Priority: optional
Section: universe/graphics
Installed-Size: 4783
Maintainer: Ubuntu Developers
Original-Maintainer: Debian Multimedia Maintainers
Architecture: amd64
Version: 2.2.0-1
Replaces: vlc-data (<< 1.1.5), vlc-nox (<< 2.2.0~pre2-2~), vlc-plugin-pulse (<< 2.2.0~pre2-2~)
Provides: mp3-decoder
Depends: fonts-freefont-ttf, vlc-nox (= 2.2.0-1), libaa1 (>= 1.4p5), libavcodec56 (>= 6:11~beta1) | libavcodec-extra-56 (>= 6:11.2), libavutil54 (>= 6:11~beta1), libc6 (>= 2.16), libcaca0 (>= 0.99.beta17-1), libegl1-mesa (>= 7.8.1) | libegl1-x11, libfreerdp-client1.1 (>= 1.1.0~beta1+git20130629), libfreerdp-core1.1 (>= 1.1.0~beta1+git20130629), libfreerdp-gdi1.1 (>= 1.1.0~beta1+git20130629), libfreetype6 (>= 2.2.1), libfribidi0 (>= 0.19.2), libgcc1 (>= 1:4.1.1), libgl1-mesa-glx | libgl1, libgles1-mesa (>= 7.8.1) | libgles1, libgles2-mesa (>= 7.8.1) | libgles2, libpulse0 (>= 0.99.4), libqtcore4 (>= 4:4.8.0), libqtgui4 (>= 4:4.8.0), libsdl-image1.2 (>= 1.2.10), libsdl1.2debian (>= 1.2.11), libstdc++6 (>= 4.9), libva-drm1 (>= 1.1.0), libva-x11-1 (>= 1.0.3), libva1 (>= 1.2.0), libvlccore8 (>= 2.2.0~pre1), libvncclient0 (>= 0.9.9), libx11-6, libxcb-composite0, libxcb-keysyms1 (>= 0.4.0), libxcb-randr0 (>= 1.1), libxcb-shm0, libxcb-xv0 (>= 1.2), libxcb1 (>= 1.6), libxext6, libxinerama1, libxpm4, zlib1g (>= 1:1.2.3.3)
Recommends: vlc-plugin-notify (= 2.2.0-1), vlc-plugin-samba (= 2.2.0-1), xdg-utils
Suggests: videolan-doc
Breaks: vlc-data (<< 1.1.5), vlc-nox (<< 2.2.0~pre2-2~), vlc-plugin-pulse (<< 2.2.0~pre2-2~)
Filename: pool/universe/v/vlc/vlc_2.2.0-1_amd64.deb
Size: 1495386
MD5sum: 2a97c11c25fec794d27abac4b559e0b0
SHA1: a33f0b60d75a8331d502ff9322b90d9ff71fea46
SHA256: 51017ece2f6fcff81822f98eda38d06761703e3b4509bdc046837e45065cdecc
Description-en: multimedia player and streamer
VLC is the VideoLAN project's media player. It plays MPEG, MPEG-2, MPEG-4,
DivX, MOV, WMV, QuickTime, WebM, FLAC, MP3, Ogg/Vorbis files, DVDs, VCDs,
podcasts, and multimedia streams from various network sources.
.
VLC can also be used as a streaming server that duplicates the stream it
reads and multicasts them through the network to other clients, or serves
them through HTTP.
.
VLC has support for on-the-fly transcoding of audio and video formats, either
for broadcasting purposes or for movie format transformations. Support for
most output methods is provided by this package, but features can be added by
installing additional plugins (vlc-plugin-fluidsynth, vlc-plugin-jack,
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

13. Check for dependencies 

Dependencies are extra software needed for a particular software to run (vlc in this case)

aman@vostro:~$ apt-cache depends vlc
vlc
Depends: fonts-freefont-ttf
Depends: vlc-nox
Depends: libaa1
|Depends: libavcodec56
Depends: libavcodec-extra-56
Depends: libavutil54
Depends: libc6
Depends: libcaca0
|Depends: libegl1-mesa
Depends:
libegl1-mesa
Depends: libfreerdp-client1.1
Depends: libfreerdp-core1.1
Depends: libfreerdp-gdi1.1
Depends: libfreetype6
Depends: libfribidi0
Depends: libgcc1
|Depends: libgl1-mesa-glx
Depends:
libgl1-mesa-glx
|Depends: libgles1-mesa
Depends:
libgles1-mesa
|Depends: libgles2-mesa
Depends:
libgles2-mesa
Depends: libpulse0
Depends: libqtcore4
Depends: libqtgui4
Depends: libsdl-image1.2
Depends: libsdl1.2debian
Depends: libstdc++6
Depends: libva-drm1
Depends: libva-x11-1
Depends: libva1
Depends: libvlccore8
Depends: libvncclient0
Depends: libx11-6
Depends: libxcb-composite0
Depends: libxcb-keysyms1
Depends: libxcb-randr0
Depends: libxcb-shm0
Depends: libxcb-xv0
Depends: libxcb1
Depends: libxext6
Depends: libxinerama1
Depends: libxpm4
Depends: zlib1g
Suggests: videolan-doc
Recommends: vlc-plugin-notify
Recommends: vlc-plugin-samba
Recommends: xdg-utils
Breaks: vlc-data
Breaks:
Breaks: vlc-nox
Breaks: vlc-nox:i386
Breaks: vlc-plugin-pulse
Breaks:
Replaces: vlc-data
Replaces:
Replaces: vlc-nox
Replaces: vlc-nox:i386
Replaces: vlc-plugin-pulse
Replaces:
Conflicts: vlc:i386

14. Get info about all installed packages.

aman@vostro:~$ apt-cache stats
Total package names: 63438 (1,269 k)
Total package structures: 106711 (5,976 k)
Normal packages: 74162
Pure virtual packages: 1231
Single virtual packages: 9344
Mixed virtual packages: 1908
Missing: 20066
Total distinct versions: 79551 (5,728 k)
Total distinct descriptions: 98244 (2,358 k)
Total dependencies: 610885 (17.1 M)
Total ver/file relations: 84426 (2,026 k)
Total Desc/File relations: 98244 (2,358 k)
Total Provides mappings: 17628 (353 k)
Total globbed strings: 187 (2,499 )
Total dependency version space: 2,908 k
Total slack space: 50.5 k
Total space accounted for: 31.2 M

15. List all available software packages

aman@vostro:~$ apt-cache pkgnames
account-plugin-yahoojp
ceph-fuse
dvd+rw-tools
e3
gnome-commander-data
grub-gfxpayload-lists
gweled
libannotation-indexer-java-doc
libboost-timer-dev
libdune-istl-dev
libfile-keepass-perl
libghc-configfile-dev
libgnome-desktop-3-dev
libphat-dev
libsimple-http-java-doc
libsslcommon2-dev
libtag1-dev
mobyle
ntopng-dbg
pxlib1
python3-doc
python3-tz
r-bioc-preprocesscore
redmine-plugin-recaptcha
unity-control-center-signon
unity-webapps-lastfm-radio
bind9-host
cvm-mysql
gadmin-samba
...

Leave a Reply

Your email address will not be published.