The Ultimate Apt-Get Package Management Cheat Sheet for Debian Linux or Ubuntu

There are a number of package management tools available to you if you’re running either Ubuntu Linux or Debian.

apt-get

Advanced Package Tool (apt) supports the installation of packages over the Internet using HTTP or FTP protocols, scripting and the upgrade of all packages with a single operation.
""

dpkg

Debian Packaging Tool (dpkg) can be used to install, query and uninstall packages.
If you prefer tools that have a user interface, you have the option to use many, including the text-based aptitude or synaptic which is a GUI front end for the advanced packaging tool.
Red Hat Linux packages end with the prefix .rpm, in the same way, Debian packages would end in .deb. Therefore,

apache _ 1.3.31-6 _ i386.deb

Represents:

Package name: Apache

Version Number: 1.3.31-6

Hardware Platform i386 (Intel x86)

.deb: extension that suggests it is a Debian package.

Using the .deb prefix implies a complete file, where the first part of the .deb file refers to the package. For instance, when I refer to a package sudo, it means sudo only and not the .bed file associated with it.

If you are not the root user, you will have to add sudo before any of the commands listed.

Find Your Debian Package Name

Begin by opening your terminal with:

Ctrl+Alt+T

Then run the following commands:

apt-cache search {package-name}

apt-cache search apache

How To Add A New Package

apt-get install {package-name}

How To Search A Package Name

To find software packages use the apt-cache command:

apt-cache search {package-name}

To find vim package list, enter:

apt-cache search vim

OR

apt-cache search vim | more

OR

apt-cache search vim | grep 'word'

If you’d like to show all vim packages starting with vim word only:

apt-cache search ^vim

How To Remove The Package but Keep Configuration Files

apt-get remove {package-name}

How To Remove Both Package and Configuration Files

apt-get --purge remove {package-name}

This syntax will also work for config files stored in /etc/ directory.

How To Remove Automatically Installed Packages

To satisfy the dependencies for other packages and are now no longer needed. For instance, if you need to remove unwanted kernel on a Debian or Ubuntu Linux.

sudo apt-get autoremove

OR

sudo apt-get --purge autoremove

How To Update My System

apt-get update

apt-get upgrade

How To Upgrade Individual Packages

Whether it is sudo or bash, run:

apt-get install sudo

apt-get install bash

How To Display Available Software Updates

Displays the full list of all the available upgrades to packages already installed.

apt-get update

apt-get -u upgrade

You will be shown the full list and if you want to run an upgrade on each package, enter ‘y’ when prompted

To view the full list of upgraded packages, run:
apt-get -u upgrade --assume-no

How To Upgrade an Individual Package

apt-get install {package-name}

How To Upgrade Debian or Ubuntu Linux Distro

According to Canonical:

The dist-upgrade option to apt-get in addition to performing the function of upgrade, also intelligently handles changing dependencies with new versions of packages; apt-get has a “smart” conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary. The dist-upgrade command may, therefore, remove some packages.

sudo apt-get update
sudo apt-get dist-upgrade

How To Show Package Information Using dpkg

If you require showing the description of the package or the version etc.

dpkg --info {.deb-package-name}

dpkg --info sudo_1.6.7p5-2_i386.deb | less

To list all the installed packages, run:

dpkg -l

How To List Individual Packages To Verify Their Installation

Packages such as Apache or Sudo. If the package is installed, the name will be displayed followed by a short description.

dpkg -l apache

dpkg -l | grep -i 'sudo'

How To List All Packages Associated With Apache

dpkg -l '*apache*'

If you would like to list all the files owned by the installed package, run:

dpkg -L {package-name}

To list files provided by the package once uninstalled, run:

dpkg --contents {.deb-package-name}

To find out what package owns the file /bin/netstat, run:

dpkg -S {/path/to/file}

How To Search For A Package Or Package Description

In the rare occurrence that you don't know the package name but you would like to search for the given keywords in a package, you are welcome to take the following approach:

apt-cache search "Text-to-search"

apt-cache search "https"

apt-cache search "web server"

apt-cache search "web server"| grep something

How To Find All The Debian Packages Used For Intrusion Detection

code>$ apt-cache search "Intrusion Detection"

How To Find Sniffer Packages

apt-cache search sniffer

How To Find a Debian Package Status

dpkg -s {package-name} | grep Status

How To List Each Dependency In A Package

If you’d like to display a list of each dependency a package has and all the other possible packages that would fulfill that dependency. This is command seldom used because apt-get does a decent job in fulfilling package dependencies.

apt-cache depends {package-name}

For each of these, replace {package-name} with the appropriate package, you are working with.

Share your experiences with us in the comments section provided for you below. Thank you for visiting Base64!

RELATED: The Ultimate Debian Apt-Get Command Cheat Sheet