Javatpoint Logo
Javatpoint Logo

Introduction to Ubuntu Packages

The Ubuntu packages are a group of items (libraries, scripts, text files, license, a manifest, etc) that enable us to install a segment of software ordered in a way that a package manager will be able to unpack it and bring it into our system.

Several packages are installed on our Linux system. We might be wondering where the packages come from. Many packages come pre-installed in a newly installed Linux system. Also, we have probably installed other packages for enhancing the functionalities of the system.

We might sometimes want to list the packages installed on our system. We will learn how we can list the packages installed on our system in this article. We will use the Ubuntu Terminal windows to execute the commands. We can use the keyword shortcuts, i.e., Ctrl+Alt+T to start the Terminal.

Ubuntu Package Management

Package management is one of the essential aspects of a Linux system. The package management tools and the packaging format differ from one distribution to another, but almost all distributions apply one of two tool sets.

The RPM packaging tools and packaging formats such as yum and rpm are common for Red Hat Enterprise Linux-based distros (like Rocky Linux and RHEL itself). The other big family, used by Ubuntu, Debian, and related distros, uses the packaging format, i.e., .deb, and tools like dpkg and apt.

There have been more package managers created for running in parallel along with the core dpkg and apt tooling: for instance, snap offers more sandboxing and portability, and Homebrew, which shifted from macOS, offers command-line tools which could be installed by single users to ignore conflicts with system packages.

Listing Installed Packages with apt Command

The apt command is a packages manager (built-in) in Ubuntu that aids us to install, update, and uninstall packages from our Ubuntu system. This command can be used for displaying the installed package list on our system. To run the apt command, we need to open the terminal window and execute the following command:


Ubuntu Packages

The above command will list every package that has been installed on our system and installed packages as dependencies.

The result shows the names of the packages with the installed releases and the architecture.

We can run the following command to see whether a package has been installed or not:

We can enter the following command to check the details of a particular package:

Listing Installed Packages with dpkg command

The dpkg command is used for installing, building, and uninstalling packages in the Debian operating system and its derivates. Dpkg-query can be used for listing every installed package in a system.

We need to type the below command in the command-line window to list every installed package on our system:

The result shows the names of the packages with the installed releases and the architecture.

We can run the following command to see whether a package has been installed or not:

Listing Installed Snap Packages

The dpkg-query and apt commands don't list every package that is installed as snaps. We can separately list these packages using the snap command.

We need to type the below command in the command-line window to list every installed as snaps on our system:


Ubuntu Packages

Introduction to Debian Package Management Tools

The Ubuntu/Debian ecosystem occupies some distinct package management tools for managing software in the system. Almost all of these packages are correlated and work on similar package databases. A few of these tools try to give high-level interfaces while some other utilities focus on offering low-level functionality.

Apt

Probably, the apt command is most often applied member of the packaging tool's apt suite. Its main aim is to focus on remote repositories managed by the packaging team of the distribution and performing tasks on the existed packages.

In general, the apt suite works by pulling details from remote repositories to a cache managed on a local system. Apt is used for refreshing the local cache. Also, it is used to change the package state. It means to install or uninstall a package through the system. The apt command in general will be used for updating the local cache and for making changes to the live system

Important: In previous Ubuntu versions, the apt command was called the apt-get command. It has been up to date, but we can still know it as the apt-get command for backward compatibility or out of habit.

apt-cache

apt-cache is another essential member of the suite, i.e., apt. This utility applies the local cache for querying details of the existed packages and their features.

For example, any time we want to find a particular tool or a package that will implement a certain task, apt-cache can be a good choice to begin. Also, it can be descriptive of what exact version of a package will be targeted via a procedure. Reverse dependency and dependency details are another place in which apt-cache is helpful.

Dpkg

While other tools were concentrated on handling packages managed in repositories, the dpkg command could also be used to work on the .deb packages. Actually, the dpkg tool is liable for almost all behind-the-scenes implementation of the above commands; apt offers extra housekeeping and dpkg collaborates with the packages themselves.

The dpkg command can't automatically resolve dependencies, unlike apt. Its main aspect is the capability to implement directly with .deb packages, disjoint a package, and search for other things about its design. However, it can collect some details of the installed packages in the system, we should not utilize it as the main package manager.

Update Package Cache and System

The Ubuntu and Debian package management tools aid to keep the available package list of our system up-to-date. Also, they offer several methods to update packages we have installed over our system.

Update Local Package Cache

For package information, the remote repositories, that our packaging tools depend on, are updated every time. However, almost all tools of Linux package management are created for many historical reasons, working directly on this information's local cache. That cache requires to be refreshed periodically.

It's a good thing to update our local cache of all sessions before working on other commands of the package. It will ensure that we are working on up-to-date information on the available software. A few installation commands will abort if we are working on stale package information.

We can run the below apt command along with the sub-command, i.e., update for updating the local cache:


Ubuntu Packages

The above command will show the available package's updated list inside the repositories we are tracking.

Update Packages

Apt differentiates between two distinct update processes. The first update process can be used for upgrading the components that don't need component removal.

It can be very essential when we don't want to delete any installed packages in any circumstances. Some updates however involve substituting system components or deleting conflicting files. This process will avoid any updates that need package removal.


Ubuntu Packages

The second process will update every package, even those that need package removal. Often, it is essential as dependencies for modification of the packages.

The packages usually being deleted will be substituted by functional equivalents at the time of the upgrade process. So, it is generally safe. It is however a good thing for keeping an eye on the packages to be deleted, in case a few necessary components are marked for deletion.

We need to type the following command to implement this action.


Ubuntu Packages

This command will update every package on our system.

Download and Install Packages

Find Packages

The initial step is to find the repositories of our distribution for the packages we are looking for when downloading and installing packages. Finding packages is a single task that points to the package cache for details. To do so, we need to run the apt-cache search command.

Note: Remember that we should ensure that our local cache is already up-to-date with the sudo apt update command before finding the packages.

It doesn't need sudo privileges because this process only queries for details. Any search procedure implemented will check on the package names and the package full descriptions.

Installing Package using the Repos

We can execute the apt command along with the install argument for installing any package through the repository and necessary dependencies. For this command, the arguments should be the name of the package or names because they are labeled inside the repository.

We can also install more than one package at a time that our isolated by a space.

If our requested package needs extra dependencies, these will be printed on the standard output and we will be prompted for confirming the process. In that case, we can continue by clicking the "Y" button or cancel with the "N" button.

Installing a Particular Package Release from Repos

If we want to install a particular release of a package, we can give the release we would like to target with =, as follows:

Performing Package Action Dry Run

We will sometimes want to check the side effects of a process before committing to run the command. The apt command permits us for adding the flag, i.e., -s to "simulate" a process.

For example, to see what will be done if we select to install any package, we can use the following syntax:

It will let us check every dependency and the modifications to our system that will appear if we delete the flag, i.e., -s. One advantage of it is that we can check the outcomes of a process that will normally need root privileges without applying sudo.

We will get every detail about the packages and their versions that will be installed without needing to complete the real process. Also, it works with some other procedures, like implementing system upgrades. The command is as follows:

The command will ask the user for confirmation for several processes by default. It includes installations that need extra dependencies and upgrades of the package. For bypassing these upgrades and default to accept any of these prompts, we can pass the flag, i.e., -y when implementing these operations:

It will install the package and dependencies without further asking the user. It can also be used to upgrade procedures:


Ubuntu Packages

Fixing Broken Package and Dependencies

Sometimes, an installation process may not complete successfully because of dependencies or other issues. One common issue in which it may happen is if installing the .deb package using dpkg which doesn't resolve dependencies. Apt can attempt for sorting out this case by passing it the command, i.e., -f.


Ubuntu Packages

It will find the dependencies that aren't satisfied and try to install them for fixing the dependency tree. If our installation process complained about a dependency issue, it should be our first step in trying to resolve it. If we can't solve a problem this way and we installed any third-party package, we should delete it and find a new version that is more maintained actively.

Downloading Package with Repos

There are primary instances where it might be useful for downloading a package using the repositories without installing it. We can do it by executing the apt command along with the argument, i.e., download. The sudo privileges are needed because it is only downloading the file and not affecting the actual system:

The above command will download the mentioned package to the current directory.

Installing .deb Package

A few vendors ship raw files of .deb package which we can install on our system. Although, almost all distributions suggest installing applications from their organized repositories.

To do so, we can use the dpkg command. Dpkg is primarily used for working with many individual packages. It doesn't try to implement installs through the repository and rather finds .deb packages inside the current directory or path shipped:

Note: The tool doesn't implement the handling of the dependency. It means that when there are unmet dependencies, the installation process will fail.

Although, it marks the dependencies required, so if every dependency is available inside the repositories, we can satisfy them by entering the following command afterward:

It will install unmet dependencies such as those marked with dpkg.

Deleting Packages and Removing Files

In this section, we will explain how to remove packages and files that might be left behind by some package operations.

Uninstalling Packages

We can use the apt remove command for removing the installed packages. It will remove almost all files that this package installed in the system. The command, i.e., apt remove leaves some configuration files in position so that our configuration will be available if we require to reinstall the software at a later time. It is useful because it means that the configuration files that we customized would be deleted if we remove a package accidentally.

We need to give the package name we want to uninstall to finish this operation:

The package will be deleted with the exception of our configuration files.

Uninstalling Packages and Every Related Configuration File

We can use the apt purge command if we want to uninstall a package and every related file from our system like a configuration file. The purge command deletes everything, unlike the command, i.e., remove which is mentioned above. It is helpful if we don't want to store the configuration files or if we are having problems and want to begin from a clean slate.

Note: Once our configuration files are deleted, we can't get them back.

If we ever require reinstalling that package, then the default configuration would be applied.

We can also run the autoremove command to automatically delete the specific packages that were installed and no longer needed by the packages:


Ubuntu Packages
Next TopicCisco Webex Ubuntu





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA