Package Management in Ubuntu

Lets learn how to manage software application on Ubuntu Linux.

An Ubuntu package is a collection of items(scripts, libraries, text files, manifest, license, etc) that enable you to install a piece of software.

A package manager such as APT can manage packages on Ubuntu.

APT requires super-user permissions, as it deals with core aspects of the system, so in Ubuntu you’ll need to preface most commands with “sudo.”

apt command is very similar to apt-get command. apt is introduced to provide a better interface for the end user than apt-get. It is recommended to use apt.

Update Packages

update list of available packages and their versions, but doesn’t install or upgrade the packages.

1
apt update

Install Package

Example to install tree package

1
apt install tree

List Packages

You can use dpkg -l to list packages that are install. Combine with grep command to search for the package installed.

1
dpkg -l

Remove Package

After you get the package name using dpkg -l command, you can remove the package using apt remove command to remove the package.

To remove tree package

1
apt remove tree

apt remove command removes apackage, but doesn’t remove package configuration file. Use apt purge to remove package and configuration file.

Example: to purge virtualbox pacakges

1
apt purge tree

Upgrade

Upgrade the installed packages on Ubuntu

1
apt upgrade

full upgrade

1
apt full-upgrade

upgrade only one package

1
sudo apt upgrade <package_name>...

Search for Package

1
apt-cache search 

Example to serach virtualbox package

1
apt-cache search virtualbox-6.0

You can serach pacakge online using https://packages.ubuntu.com/

Clean the Cahce

1
apt clean

Check what’s Installed

1
sudo dpkg -l

You can use grep to find if a package is installed

1
sudo dpkg -l | grep tree

Adding Repository

When you use apt to install packages, the packages are downloaded from one or more apt software repositories.

Ubuntu stores software repositories are in /etc/apt/sources.list file or individual files under /etc/apt/sources.list.d/ directory.

you can add respository to /etc/apt/sources.list directly

1
sudo vim /etc/apt/sources.list

Here is a sample repository entry in sources.list

1
2
deb http://us.archive.ubuntu.com/ubuntu/ focal universe
deb-src http://us.archive.ubuntu.com/ubuntu/ focal universe

Note that

  • deb means the repository contains binaries or precompiled packages.
  • deb-src means the repository contains source code of the packages. Useful for developers.
  • ‘focal’ is the release name or version of your distribution.
  • ‘universe’ means Community-maintained free and open-source software.

If you don’t want to edit sources.list directly, you can use add-apt-repository to add repository. Docker installation example

1
2
3
4
5
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
sudo apt install docker-ce

To learn more about Respositories, see

Snap

Snap is a software packaging and deployment system developed by Canonical for the operating systems that use the Linux kernel.

1
snap install gedit

list packages installed by snap

1
snap list

remove a snap package

1
snap remove gedit