Apt-Get & Apt-Cache commands to manage packages on Debian Based Systems

Apt-Get stands for Advanced Packaging Tool (APT). apg-get is a powerful command-line tool which is used to automatically download and install new software packages, upgrade existing software packages, update the package list index, and to upgrade the entire Debian based systems. Some other package manger utilities which are being used widely in Linux are yum, dnf, apt-get, dpkg, rpm, Zypper, pacman, etc.,

Now, i’m going to play on our Ubuntu 15.10 box to explain and cover mostly used Apt-Get commands with examples.

1) Common syntax/file location for Apt-Get

See below for common syntax/ file location of apt-get.

# General syntax for apt-get #
apt-get [options] [pkg1] [pkg2] ...

# most popular apt-get commands #
[install remove update upgrade dist-upgrade purge clean]

# apt-get config file location #
/etc/apt/apt.conf

# apt-get Package file location #
/etc/apt/sources.list
/etc/apt/sources.list.d/

# apt-get cached file location #
/var/cache/apt

# apt-get history file location #
/var/log/apt/history.log

2) Install a Package or packages

Use the below command to install any package or packages on your system. In this case i’m going to install apache, MariaDB-server, MariaDB-client. Every time zypper ask your confirmation to install the corresponding package. if you want to avoid the confirmation you can do by this adding -y option with zypper.

# Install a single package #
$ sudo apt-get install apache2
or
$ sudo apt-get -y install apache2

# Install more than one packages #
$ sudo apt-get install MariaDB-server MariaDB-client
or
$ sudo apt-get -y install MariaDB-server MariaDB-client

3) Remove a Package or packages

Use the below command to remove/erase any package or packages on your system. In this case I’m going to remove apache, MariaDB-server, MariaDB-client.

# Remove a single package #
$ sudo apt-get remove apache2

# Remove more than one packages #
$ sudo apt-get remove MariaDB-server MariaDB-client

# Remove a package with all files #
$ sudo apt-get purge apache2

# Alternate command to Remove a package with all files #
$ sudo apt-get remove --purge apache2

# This command removes packages that were installed by other packages and are no longer needed #
$ sudo apt-get autoremove

# This command removes an installed package and dependencies #
$ sudo apt-get autoremove nano

4) update a Package or packages

Use the below command to update any package or packages on your system. In this case I’m going to update nano, MariaDB-server, MariaDB-client to latest version.

# update single package #
$ sudo apt-get install --only-upgrade nano

# update more than one packages #
$ sudo apt-get install --only-upgrade MariaDB-server MariaDB-client nano

5) Check Change Log of Package

If you want to know, what are the changes made on the packages before upgrading you can check using below command.

# Check Change Log of Package #
$ sudo apt-get changelog nano

7) Search a package

If you don’t know the exact package name which you want to install, Use the search option it will return the matching string. In this case I’m going to search vsftpd.

# Search a package #
$ sudo apt-cache search vsftpd
vsftpd - lightweight, efficient FTP server written for security
vsftpd-dbg - lightweight, efficient FTP server written for security (debug)
ccze - A robust, modular log coloriser
ftpd - File Transfer Protocol (FTP) server
yasat - simple stupid audit tool

I’m not satiesfied the above search tearm because its not clear, how yum, dnf & zypper work.

$ sudo apt-cache policy vsftpd
vsftpd:
  Installed: (none)
  Candidate: 3.0.2-20ubuntu1
  Version table:
     3.0.2-20ubuntu1 0
        500 http://in.archive.ubuntu.com/ubuntu/ wily/main amd64 Packages

The above output clearly shows matching string for vsftpd.

8) Check package information

If you want to know the package detailed information before proceeding with the installation. Use the below command, it will give full information about the package like package version, size, repo name, etc..

# print package info #
$ sudo apt-cache show apache2
Package: apache2
Priority: optional
Section: web
Installed-Size: 473
Maintainer: Ubuntu Developers 
Original-Maintainer: Debian Apache Maintainers 
Architecture: amd64
Version: 2.4.12-2ubuntu2
Replaces: apache2.2-common
Provides: httpd, httpd-cgi
Depends: lsb-base, procps, perl, mime-support, apache2-bin (= 2.4.12-2ubuntu2), apache2-utils (>= 2.4), apache2-data (= 2.4.12-2ubuntu2)
Pre-Depends: dpkg (>= 1.17.14)
Recommends: ssl-cert
Suggests: www-browser, apache2-doc, apache2-suexec-pristine | apache2-suexec-custom, ufw
Conflicts: apache2.2-common (<< 2.3~)
Filename: pool/main/a/apache2/apache2_2.4.12-2ubuntu2_amd64.deb
Size: 91348
MD5sum: ab0ee0b0d1c6b3d19bd87aa2a9537125
SHA1: 350c9a1a954906088ed032aebb77de3d5bb24004
SHA256: 03f515f7ebc3b67b050b06e82ebca34b5e83e34a528868498fce020bf1dbbe34
Description-en: Apache HTTP Server
 The Apache HTTP Server Project's goal is to build a secure, efficient and
 extensible HTTP server as standards-compliant open source software. The
 result has long been the number one web server on the Internet.
 .
 Installing this package results in a full installation, including the
 configuration files, init scripts and support scripts.
Description-md5: d02426bc360345e5acd45367716dc35c
Homepage: http://httpd.apache.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 9m
Task: lamp-server, mythbuntu-frontend, mythbuntu-desktop, mythbuntu-backend-slave, mythbuntu-backend-master, mythbuntu-backend-master

9) Update Repository Index

Use the below command to Update/Refresh Repository Index file which was mentioned under /etc/apt/sources.list or /etc/apt/preferences.

# Update Repository Index #
$ sudo apt-get update

10) Update Packages

Use the below commands to Upgrade entire system packages or specific package to latest version.

# List the available updates #
$ sudo apt-get -u upgrade

# To upgrade/update particular pacakge #
$ sudo apt-get install --only-upgrade google-chrome-stable

# update entire system packages to latest version #
$ sudo apt-get upgrade

# This will perform like above command also upgrade the system to new Product Version #
$ sudo apt-get dist-upgrade

11) Clean local repository packages

This command removes .deb files for packages that are no longer installed on your system, removing these files from /var/cache/apt/archives may regain a significant amount of diskspace.

# Clean local repository packages #
$ sudo apt-get clean

# Clean all local repository packages #
$ sudo apt-get autoclean

12) Download a Package Without Installing

If you want to download any packages without installation, you can do it by adding "download" option with apt-get command.

# Download a Package Without Installing #
$ sudo apt-get download nano

13) How to Check Broken Dependencies

This command is a diagnostic tool. It does an update of the package lists and checks for broken dependencies.

# Check Broken Dependencies #
$ sudo apt-get check

14) Fix Broken Packages

When you are facing "unmet dependencies" while installing pacakge, run the below command to fix Broken Packages.

# Fix Broken Packages #
$ sudo apt-get -f install

15) How to get help from apt-get

If you want additional options, try below commands.

# man page of apt-get #
$ man apt-get

# apt-get help, page #
$ apt-get --help

Enjoy...)

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...

Close
Please support the site
By clicking any of these buttons you help our site to get better