- LFCA: How to Manage Software Packages in Linux – Part 7
- Debian Package Management
- Install a Package in Debian/Ubuntu Systems
- Search a Package Before Installing
- Show Information of Package
- Upgrade Packages in Ubuntu
- Remove Package in Ubuntu
- The Dpkg Package Manager
- YUM / DNF and RPM Package Management
- Install Software Packages in CentOS
- Search for a Software Package
- Update Software Packages
- Remove Software Package
- The RPM Package Manager
- Install Software Package
- Remove Software Package
- How to Use the RPM Command in Linux
- Prerequisites
- Linux RPM Command Syntax
- RPM Command Options
- RPM Command Examples
- Install RPM Packages
- Upgrade RPM Packages
- Remove RPM Packages
- Display Package Information After Installing
- Display Package Information Before Installing
- Check Package Dependencies Before Installing
- Verify Packages
- Find Manual Pages
- List All Files of an Installed Package
- List Installed Packages
- List Recently Installed Packages
- Where to Find and Download RPM Packages?
LFCA: How to Manage Software Packages in Linux – Part 7
This article is Part 7 of the LFCA series, here in this part, you will acquaint yourself with the general system administration commands to manage software packages in the Linux system.
As a systems administrator, you will be tasked with the responsibility of managing software packages. This includes installing, upgrading, and removing or uninstalling packages from your system.
There are two types of packages in a Linux system:
- Binary packages: These contain configuration files, executables, man pages among other documentation. For Debian, the binary packages have a .deb file extension. For Red Hat, the binary packages bear a .rpm file extension. Binary packages are unpacked using the Debian utility dpkg – For .deb binary files and rpm for .rpm binary packages as we shall see later on.
- Source packages: A source package is a compressed file that contains the source code of the application, a brief description of the package, and instructions on how to build the application.
Different Linux distributions have their own package managers and here, we are going to look at 2 Linux families: Debian and Red Hat.
Debian Package Management
Debian provides APT (Advanced Package Manager) as a front-end package management solution. It’s a powerful command-line utility that works with core libraries and allows you to download, install, update and remove packages from your system.
Install a Package in Debian/Ubuntu Systems
If you are coming from a Windows environment, you are used to downloading a .exe package from a software vendor and running it on your system using an installation Wizard.
In Linux, installing an application is quite different. Software packages are downloaded and installed from online repositories using a package manager. The list of repositories is defined in the /etc/apt/sources.list file and /etc/sources.list.d directory.
On Debian-based distributions, the APT package manager is used to download and install packages from the online repositories. Not only does it install a package but also the dependencies required by the packages
It’s always recommended to update the repositories in the /etc/apt/sources.list file before installing any package. To accomplish this, run the command:
To install a software package, use the syntax:
$ sudo apt install package_name
For example, to install Apache web server, run the command:
Search a Package Before Installing
To search for the availability of a package in the repositories, use the syntax:
For example, to search for the availability of the package called neofetch, run the command:
Show Information of Package
To display more information about a package, use the apt command as follows.
For example, to reveal more information about the neofetch package, run:
Upgrade Packages in Ubuntu
To upgrade the installed packages on your system run the command:
Remove Package in Ubuntu
To remove a software package, say apache2 run the command:
To remove the package alongside the configuration files use the purge option as shown.
The Dpkg Package Manager
Debian-based Linux distributions also offer the dpkg package manager. This is a low-level package manager that handles binary packages that do not require any dependencies during installation. If dpkg detects that a binary package file requires dependencies, it reports the missing dependencies and halts.
To install a package from a .deb file use the dpkg command as follows:
For example, to install the AnyDesk package from its Debian file shown, execute:
$ sudo dpkg -i anydesk_6.1.0-1_amd64.deb OR $ sudo dpkg --unpack anydesk_6.1.0-1_amd64.deb
To check if the package was installed, run the command:
To remove the package, use the -r option as shown:
To remove the package alongside all its configuration files, use the -P option for purging all the files associated with the package.
YUM / DNF and RPM Package Management
Modern RedHat Linux distributions such as RHEL & CentOS 8 and Fedora 21 and later versions use DNF (Dandified YUM) which is an upgrade of the now deprecated YUM package manager, which was the de facto package manager for older versions of Red Hat Linux distributions such as RedHat and CentOS 7.
Just like APT, the DNF or YUM package managers are used to install packages from online repositories.
Install Software Packages in CentOS
To install a package, use the syntax:
$ sudo dnf install package-name OR $ sudo yum install package-name (For older versions)
For instance, to install the Apache httpd package, run the command:
$ sudo dnf install httpd OR $ sudo yum install httpd
Search for a Software Package
You can also search for the availability of a package from the repositories as follows:
Update Software Packages
To update all packages to their latest version execute:
$ sudo dnf update OR $ sudo yum update
Remove Software Package
$ sudo dnf remove package_name OR $ sudo yum remove package_name
For example, to remove the httpd package, run
$ sudo dnf remove httpd OR $ sudo yum remove httpd
The RPM Package Manager
The rpm package manager is another open-source package management tool for handling .rpm binary packages on RedHat Linux distributions. Just like APT package manager rpm manages binary packages.
Install Software Package
To install an application using a .rpm file, use the syntax below:
For instance, to install the AnyDesk application from the .rpm file shown, run the command:
$ sudo rpm -i anydesk-6.1.0-1.el8.x86_64.rpm
To verify or check the presence of a software application on your system use the syntax:
For instance, to check if Anydesk is installed, run the command:
To query all the present software packages, use the command:
Remove Software Package
To uninstall a package using the rpm command use the syntax:
Conclusion
The apt, dpkg, rpm, dnf, and yum commands are handy command-line tools that can help you to install, update and remove software packages on your Linux system.
How to Use the RPM Command in Linux
RPM is a command-line utility for managing packages on Unix/Linux systems. It allows you to install, query, update, verify and remove RPM packages.
It is the default package manager for Red Hat based systems and only works with the .rpm format. You can install such packages using the rpm or the yum command.
In this article, you will learn how to use rpm commands with easy-to-follow examples.
Prerequisites
- A system running Linux.
- Access to the command line/terminal.
- Access to root or an account with sudo privileges.
Linux RPM Command Syntax
The basic syntax for the command is:
sudo rpm [option] [package_name]
To see a full list of command options, run:
RPM Command Options
Below you will find the most popular command options used with the rpm command and their meaning.
-e , —erase | Remove (uninstall) package(s). |
-h , —hash | Print hash marks as the package installs. |
-i , —install | Install package(s). |
-l , —list | List files in a package. |
-q , —query | Query package(s). |
-s , —state | Display the state of the listed files. |
-U , —upgrade | Upgrade package(s). |
-v , —verbose | Provide more detailed output. |
-V , —verify | Verify package(s). |
RPM Command Examples
The rpm command is simple to use and allows combining multiple options to customize each query. Explore some of the most commonly used commands listed below and try out how they work with a sample package.
Install RPM Packages
To install RPM packages with the rpm command, use the syntax:
sudo rpm -ivh package_name
The command includes the options:
Before installing, you need to download the appropriate file. The package has to be compatible with the system architecture of the machine.
Note: To download packages, use the curl or wget command.
For instance, to install the MySQL package, you run:
sudo rpm -ivh mysql80-community-release-el7-5.noarch.rpm
To install an RPM package without previously downloading it, provide the URL:
sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
Note: For a more detailed guide on installing RPM packages, check out our guide on how to install RPM packages on Ubuntu.
Upgrade RPM Packages
RPM upgrades a package by uninstalling the current version and installing the latest one.
The command for upgrading a package is:
sudo rpm -Uvh package_name
- -U (upgrade)
- -v (verbose mode)
- -h (print hash marks to show upgrading process)
sudo rpm -Uvh mysql80-community-release-el7-5.noarch.rpm
If the new version requires additional dependencies, you must install them manually. RPM lists the missing dependencies in the output after running the command.
To ignore the message and update without the dependencies, add the —nodeps option to the command:
sudo rpm -Uvh --nodeps package_name
Remove RPM Packages
Remove RPM packages using the -e ( —erase ) option:
To see the verbose output, add the -v option to the command:
To delete an RPM package without removing dependencies, add —nodeps :
sudo rpm -ev --nodeps package_name
For example, to remove MySQL without removing its dependencies, you run:
sudo rpm -ev --nodeps mysql80-community-release-el7-5.noarch
Note: For a more detailed guide on removing RPM packages, check out our guide on how to remove packages in CentOS.
Display Package Information After Installing
To see available information about an installed RPM package, use the -qi option, which instructs RPM to query info :
The output displays the installed information, package version, and a short description.
sudo rpm -qi mysql89-community-release-el7-5.noarch
Display Package Information Before Installing
The command for displaying information about a package prior to installation is:
sudo rpm -qip package_name
The command includes the options:
To display information before installing the MySQL package, use the command:
sudo rpm -qip mysql89-community-release-el7-5.noarch
Check Package Dependencies Before Installing
RPM allows you to check the dependencies of packages prior to installing them on the system. Bear in mind, you need to have the RPM package downloaded locally to see a list of dependencies.
The command for doing so is:
For example, to list the dependencies for installing the MySQL RPM package, you run:
rpm -qpR mysql80-community-release-el7-5.noarch
Verify Packages
Verifying packages means comparing metadata from the RPM database with the information from the installed files.
You can verify all installed packages using the command:
To verify a specific package run:
Verify the installed MySQL package with:
sudo rpm -Vp mysql80-community-release-el7-5.noarch.rpm
Find Manual Pages
To list available documentation related to an installed RPM package, use the -qdf option:
sudo rpm -qdf package_name
To find manual pages for MySQL, use the command:
sudo rpm -qdf mysql80-comunity-release-el7-5.noarch.rpm
List All Files of an Installed Package
See detailed information about a package by listing all its files, use the -ql option and instructs RPM to query list :
For example, to list files of the sample MySQL package, you run:
sudo rpm -ql mysql80-community-release-el7-5.noarch
List Installed Packages
List all of the installed RPM packages on the system by running the following:
The command includes the -qa option, which instructs RPM to query all.
List Recently Installed Packages
To display a list of all the recently installed packages, use the -qa (query all) option along with the —last attribute:
The output lists all the installed RPM packages, ordering them by the latest package on top.
Where to Find and Download RPM Packages?
You can find and download RPM packages on the following websites:
In this article, you learned how to use the rpm command for installing, verifying, upgrading, and deleting packages. Still, it is recommended to use the yum or dnf command for such actions as they automatically deal with dependencies.