Using Apt Utilities On Ubuntu

Last Updated: Sat, Mar 19, 2016
Debian Linux Guides System Admin Ubuntu

Introduction

This write up summarizes the use of apt-get and apt-cache command line utilities to install, remove, search, and find information on any Ubuntu/Debian system software packages.

apt-get is a package management utility used to install, update, and remove software packages on Ubuntu and Debian based Linux systems.

apt-cache is a utility used for searching and getting information on available software packages on Ubuntu and Debian based Linux systems.

Commands

# update package sources list

sudo apt-get update



# install a package (the -y flag auto answers yes)

sudo apt-get install package name -y



# search for a package

sudo apt-cache search package name



# show information about a package

sudo apt-cache show package-name



# uninstall a package

sudo apt-get remove package-name



# purge a package (will remove package along along with it's files)

sudo apt-get purge package-name



# uninstall unused dependencies (that remove/purge do not)

sudo apt-get autoremove

Personal Package Archives (PPA)

PPAs are software packages provided by the community that generally contain the latest and greatest version of a software, but sometimes come with risks. So for example, at the time of this writing, PHP 7 is out but is not included in Ubuntu's default package source list. To install on a server, one has to add the "ondrej/php" PPA first using the command apt-add-repository ppa:ondrej/php. After doing so, PHP 7 becomes available to install using apt-get after an update (i.e. sudo apt-get update && sudo apt-get install php-7.0).

Below is how you add and remove PPA's on Ubuntu/Debian systems.

# add a PPA

sudo add-apt-repository ppa:author/ppa-name



# remove a PPA

sudo add-apt-repository --remove ppa:author/ppa-name

Handy Aliases

A bash alias is a shortcut/abbreviation that prevents you from typing a long command sequence. Adding below snippet to your ~/.bash_profile allows you to for example install nginx using apti nginx as oppose to sudo apt-get install nginx.

alias apti="sudo apt-get install"

alias aptr="sudo apt-get remove"

alias aptar="sudo apt-get autoremove"

alias aptp="sudo apt-get purge"

alias apts="sudo apt-cache search"

alias aptinfo="sudo apt-cache show"



alias addppa="sudo add-apt-repository"

alias removeppa="sudo add-apt-repository --remove"

Want to contribute?

You could earn up to $600 by adding new articles.