Ubuntu Package Manager – All about dpkg and apt

Ubuntu Package Manager

Ubuntu uses the same package management system as used by Debian Linux Distribution, as it is a Debian-based distribution.

In this article, we will discuss all about dpkg (Debian Package) and apt (Advanced packaging Tool). And we will also discuss how we can use them.

About the Ubuntu package manager

Debian Package or dpkg is the base of the package management system of Debian-based distribution.

Initially, dpkg was abbreviated for Debian package and is used to refer to deb package format and Debian Policy Manual combined.

dpkg is seen to be as a low-level tool for working with Debian packages. It can be used to install, remove and build .deb packages, but cannot be used to automatically download and install packages or their dependencies.

Advanced Packaging Tool or apt is a high-level tool for interacting and working with Debian packages. It layers additional features over dpkg and makes interacting with dpkg easier.

Ubuntu package manager – dpkg

Ubuntu package manager, dpkg comes with several functionalities for which you can also checkout its man pages.

1. Listing installed packages using dpkg

You can list all the installed packages in Ubuntu, by using the following command:

dpkg -l

After running the command, you will get an output similar to this –

List Installed Packages Using Dpkg
List Installed Packages Using Dpkg

2. Listing files installed by a package using dpkg

We can also list the installed packages by a package with their location using the command below –

dpkg -L <package-name>

You can use above command to list all the installed files by a package, in the way as shown below –

Listing Files Installed By A Package Using Dpkg
Listing Files Installed By A Package Using dpkg

3. Installing a local .deb file using dpkg

We can also use dpkg to install .deb packages. We can simply do that by using its -i mode for installing offline .deb packages. The command is as follows:

sudo dpkg -i <deb-package>

4. Uninstalling a package using dpkg

For uninstalling a package using dpkg , we need to know the exact name of the package that needed to be removed. We use -r mode of dpkg to remove a package. You can use the below command to remove a package using dpkg:

sudo dpkg -r <deb-package>

Alternatively, there are many other ways also to uninstall packages from Ubuntu.

Using the Ubuntu Advanced Packaging Tool (apt)

Advanced Packaging Tool or apt is most widely used to install, remove, upgrade or search a package from the repositories. It wins over dpkg , with the fact that dpkg doesn’t allow searching or automatic download & install of packages from the online repositories.

1. Searching for a package using apt

With apt , we can search for an application in the online repository for its right installation candidate to ease the installation process. If a certain application is not available, it will not give any search result

sudo apt search <package-name>

Here, I searched from chrome , using the above command and it showed me list of various packages that relates to the word “chrome”.

Searching For A Package Using Apt
Searching For A Package Using Apt

After knowing a correct package name, we also check its details in detailed fashion, using the below command:

sudo apt show <package-name>

As you can see, I searched for google-chrome-stable package using above command and it gave me various information about it like version, priority, maintainer and many more things.

Checking Details Of A Package Using Apt
Checking Details Of A Package Using Apt

2. Installing a package using apt

You can install any package from the online repository using the following command:

sudo apt install <package-name>

You just need to make sure to type the right package name, else you will get an error E: Unable to locate package .

A thing to note, above command will also install the dependencies for the package you are installing.

3. Removing a package using apt

Removing a package using apt is quite simple. You can use the below command to remove any package:

sudo apt remove <package-name>

The above command just removes the package, leaving behind its configuration files and the dependencies that were installed with it. There are also many other ways to uninstall packages from Ubuntu.

4. Updating the package index

The apt package index is a database of packages that are available from the repositories defined in /etc/apt/sources.list file and the /etc/apt/sources.list.d directory.

To update local package index with latest updates to repositories, use the following command:

sudo apt update

5. Upgrading installed packages with apt

You can also upgrade all the installed packages and your system using the below command:

sudo apt upgrade

Make sure that, you have first updated your package index or you won’t get the latest upgrades. This is why, for convenience we use both the apt update command just before apt upgrade.

Bonus

  • Debian Package (dpkg) is Open-source and you can find its code here.
  • Advanced Packaging Tool (apt) is also open-source and you can find its code here.

Conclusion

In this article, we discussed about Ubuntu package manager dpkg which it inherited from Debian, being a Debian-based distribution. We also discussed how we can use dpkg, a low-level tool and apt, a high-level tool for installing, removing and listing applications.

How can I manage packages in Ubuntu?

To manage packages in Ubuntu, you can use the apt package manager, which is the default package management system for Debian-based Linux distributions. You can use commands such as apt-get and aptitude to install, upgrade, remove, and update packages.

What is the package manager in Ubuntu?

The package manager in Ubuntu is apt (Advanced Package Tool), which is a command-line tool that allows you to manage software packages on your Ubuntu Linux system. It is used to install, upgrade, remove, and perform other package-related operations.

How do I install packages in Ubuntu?

To install packages in Ubuntu, you can use the apt command followed by the package name you want to install. For example, you can type sudo apt install packagename in the terminal to install a specific package from the repository.

What is a package repository?

A package repository is a collection of software packages that are stored in a central location and can be downloaded and installed using a package manager like apt. Ubuntu has multiple repositories, including main, universe, multiverse, and restricted, each containing different types of software packages.

How do I update the package in Ubuntu?

To update packages in Ubuntu, you can use the apt command with the update flag. For example, you can run sudo apt update in the terminal to update the package list from the repositories, and then use sudo apt upgrade to upgrade the installed packages.

Can I install new packages in Ubuntu?

Yes, you can install new packages in Ubuntu using the apt package manager. Simply use the sudo apt install packagename command in the terminal to download and install the desired package from the repository.