How to Install and Manage RPM Packages on CentOS or RHEL Linux
This post will guide you how to install RPM packages with RPM tool on CentOS or RHEL Linux. How do I uninstall a RPM Package with RPM or YUM tool on CentOS 7 or RHEL 7 Linux. How to List all installed packages on your CentOS or RHEL Linux system. This post will introduce two methods of how to install/uninstall RPM packages on CentOS 7.
If you are working in CentOS or RHEL Linux, you may have see downloadable files with the .rpm extension. The .rpm format is the default installable package type for RHEL, Fedora, CentOS, Oracle Linux and Scientific Linux as well. And If you want to install a new application, you need to look for RPM packages that are specifically built for CentOS or RHEL system.
- What is RPM Package
- Downloading RPM Installation File
- Installing RPM Packages with RPM
- Uninstalling RPM Packages with RPM
- Installing RPM Packages with YUM
- Uninstalling RPM Packages with YUM
- Downloading RPM Packages From the Default YUM Repository
- Listing Installed PRM Packages
- Offline Installation of RPM Packages
- Listing RPM Package files
- Get RPM Package Information
What is RPM Package
RPM is the abbreviation for Red Hat Package Manager. You can use this tool to manage all application on your CentOS or RHEL or Fedora Linux. There are two package management tools under CentOS or RHEL Linux, one is a low-level RPM Tool and another is high-level YUM Tool.
RPM Package Manager is also a free and open source package management system for CentOS or RHEL Linux system, and it can be used to install, uninstall and manage all software packages in your Linux system.
The default official CentOS or RHEL repositories contain thousands of RPM packages which can be installed using the YUM tool on your Linux system. If the packages are not included in the default repository, you have to download it form the third download web page where you can download and install the packages. And the extension of downloaded package file should be .rpm.
Downloading RPM Installation File
Firstly, you need to find a suitable RPM package that you want to install on your CentOS system. When you look for RPM package, you also need to make sure that you choose the correct package according to your system’s architecture and CentOS or RHEL version. It means, if your system arch is x86_64 and Linux version is CetnOS 7 or RHEL 7 version, you need to download the corresponding el7.x86_64 package.
Normally, you need to locate and download a rpm file through a web browser. However, if your browser is not available on your Linux system or your are working on terminal mode, you can still download a file if you know where it is located.
For example, you want to download a rpm file for a package called wget, you can use curl command to download it to your local disk.
Type the following command:
$ sudo curl -O https://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/Packages/wget-1.14-18.el7.x86_64.rpm
Outputs:
[root@devops ~]# curl -O https://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/Packages/wget-1.14-18.el7.x86_64.rpm % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 547k 100 547k 0 0 1250k 0 --:--:-- --:--:-- --:--:-- 1251k [root@devops ~]# ls wget* wget-1.14-18.el7.x86_64.rpm
You should see that the curl command will reach out to the website and download the file to your current working directory.
Installing RPM Packages with RPM
Once wget package downloaded on your local disk, and you can install .rpm file by rpm command with -ivh option. And the -i option will tell RPM package manager you want to install the specified file. Type:
$ sudo rpm -ivh wget-1.14-18.el7.x86_64.rpm
Outputs:
[root@devops ~]# sudo rpm -ivh wget-1.14-18.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:wget-1.14-18.el7 ################################# [100%]
If the installed package depends on other packages that you do not have installed on your system, and rpm tool will list all dependencies and exit the installation process. At this time, you have to download and install all dependency packages firstly by manually, then re-install that package.
You can also check the .rpm file for dependencies firstly using the following command:
$ sudo rpm -qpR wget-1.14-18.el7.x86_64.rpm
Then rpm should list all the dependencies.
-q option will tell RMM to query the file
-p option will allow you specify one target package to be queried
-R option will tall RPM to list all requirements for the queried package
Note: To install RPM Packages on your system, you need to make sure that you have logged in as a user with sudo privileges.
If you want to update a package that have installed already on your system, and you can use -U option, type:
$ sudo rpm -Uvh wget-1.14-18.el7.x86_64.rpm
Uninstalling RPM Packages with RPM
If you don’t need a package you installed before, and you can directly remove it from your CentOS or RHEL Linux system. You can still use RPM command to uninstall it. just use a different option, -e. It will instructs RPM Package Manager that you want to erase the software.
Before remove the package, you need to get the file name of that package that you want to uninstall with the -qa option to rpm command, type:
$ sudo rpm -qa | grep wget
Outputs:
[root@devops ~]# rpm -qa | grep wget
wget-1.14-18.el7.x86_64
Then you can use rpm command with -e option to remove it, type:
$ sudo rpm -e wget-1.14-18.el7.x86_64
After removed the package, you can list all installed packages to see that there is no package called wget any more. type:
[devops@devops ~]$ sudo rpm -e wget-1.14-18.el7.x86_64 [sudo] password for devops: [devops@devops ~]$ rpm -qa | grep wget [devops@devops ~]$
Installing RPM Packages with YUM
As YUM is the default Package Manager tool on CentOS or RHEL Linux 6/7, so you can also use yum command to install a downloaded rpm file. or you can use yum to install packages directly from the default YUM repositories. Just using yum command with localinstall subcommand to install rpm package file, type:
$ sudo yum localinstall wget-1.14-18.el7.x86_64.rpm
Outputs:
[devops@devops ~]$ sudo yum localinstall wget-1.14-18.el7.x86_64.rpm [sudo] password for devops: Loaded plugins: fastestmirror Examining wget-1.14-18.el7.x86_64.rpm: wget-1.14-18.el7.x86_64 Marking wget-1.14-18.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package wget.x86_64 0:1.14-18.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================ Installing: wget x86_64 1.14-18.el7 /wget-1.14-18.el7.x86_64 2.0 M Transaction Summary ================================================================================================================================ Install 1 Package Total size: 2.0 M Installed size: 2.0 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : wget-1.14-18.el7.x86_64 1/1 Verifying : wget-1.14-18.el7.x86_64 1/1 Installed: wget.x86_64 0:1.14-18.el7 Complete!
The localinstall subcommand will instructs YUM Package Manager to look at your current working directory for your specified rpm package file. And you need to press y key for confirmation so that the installation can be completed.
YUM Tool should download and install all dependencies required for the package.
Uninstalling RPM Packages with YUM
If you are no longer need a package you installed before, you can also uninstall it by running the following yum command with remove subcommand, type:
$ sudo yum remove wget-1.14-18.el7.x86_64
Outputs:
[devops@devops ~]$ sudo yum remove wget-1.14-18.el7.x86_64 [sudo] password for devops: Loaded plugins: fastestmirror Resolving Dependencies --> Running transaction check ---> Package wget.x86_64 0:1.14-18.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================ Removing: wget x86_64 1.14-18.el7 installed 2.0 M Transaction Summary ================================================================================================================================ Remove 1 Package Installed size: 2.0 M Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : wget-1.14-18.el7.x86_64 1/1 Verifying : wget-1.14-18.el7.x86_64 1/1 Removed: wget.x86_64 0:1.14-18.el7 Complete!
[devops@devops ~]$ rpm -qa | grep wget [devops@devops ~]$
Note: you also need to press y key when Yum prompt you for confirmation. Then the RPM package will be erased from your system.
Downloading RPM Packages From the Default YUM Repository
There is a exciting command of the YUM Package Manager called yumdownloader, it can be used to download .rpm file directly from the default YUM repository.
For example, you want to download wget rpm package from YUM repository, just using yumdownloader command:
$ sudo yumdownloader wget
Outputs:
[devops@devops ~]$ sudo yumdownloader wget Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.njupt.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com wget-1.14-18.el7.x86_64.rpm | 547 kB 00:00:00 [devops@devops ~]$ ls wget-1.14-18.el7.x86_64.rpm
You would see that wget package has been downloaded in your current working directory.
Listing Installed PRM Packages
If you want to check if the package is installed on your system, you can use rpm command with -qa option to list all installed rpm packages.
You still need to combine with grep command to filter out the results to only show your queried package, type:
$ rpm -qa | grep wget
Outputs:
[root@devops ~]# rpm -qa | grep wget wget-1.14-18.el7.x86_64
Offline Installation of RPM Packages
If you have the correct download link of a rpm package, and you do not want to download it with command line tool curl or wget. You can use rpm command with -i option to install it from a remote location, using the following command:
$ sudo rpm -i https://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/Packages/wget-1.14-18.el7.x86_64.rpm
Or you can also use yum install command with downloaded link of rom package, type:
$ sudo yum install https://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/Packages/wget-1.14-18.el7.x86_64.rpm
Outputs:
[devops@devops ~]$ sudo yum install https://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/Packages/wget-1.14-18.el7.x86_64.rpm [sudo] password for devops: Loaded plugins: fastestmirror wget-1.14-18.el7.x86_64.rpm | 547 kB 00:00:00 Examining /var/tmp/yum-root-Hc2w6I/wget-1.14-18.el7.x86_64.rpm: wget-1.14-18.el7.x86_64 Marking /var/tmp/yum-root-Hc2w6I/wget-1.14-18.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package wget.x86_64 0:1.14-18.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================ Installing: wget x86_64 1.14-18.el7 /wget-1.14-18.el7.x86_64 2.0 M Transaction Summary ================================================================================================================================ Install 1 Package Total size: 2.0 M Installed size: 2.0 M Is this ok [y/d/N]: y
Listing RPM Package files
After installed a rpm package on your system, you maybe want to list all the files that are installed with that package, you can use rpm command with -ql option to list package files, type:
$ rpm -ql wget
Outputs:
[devops@devops ~]$ rpm -ql wget /etc/wgetrc /usr/bin/wget /usr/share/doc/wget-1.14 /usr/share/doc/wget-1.14/AUTHORS /usr/share/doc/wget-1.14/COPYING /usr/share/doc/wget-1.14/MAILING-LIST /usr/share/doc/wget-1.14/NEWS /usr/share/doc/wget-1.14/README /usr/share/doc/wget-1.14/sample.wgetrc /usr/share/info/wget.info.gz /usr/share/locale/be/LC_MESSAGES/wget.mo /usr/share/locale/bg/LC_MESSAGES/wget.mo /usr/share/locale/ca/LC_MESSAGES/wget.mo ......
Get RPM Package Information
If you want to get more information about the installed package like package version, package release version, install Date, others. You can use rpm command with -qi option and then followed by an installed package name.
For example, you want to get more information about a installed package called wget, just using the following command:
$ rpm -qi wget
Outputs:
[devops@devops ~]$ rpm -qi wget Name : wget Version : 1.14 Release : 18.el7 Architecture: x86_64 Install Date: Sat 20 Apr 2019 06:15:16 AM EDT Group : Applications/Internet Size : 2055557 License : GPLv3+ Signature : RSA/SHA256, Mon 12 Nov 2018 09:49:08 AM EST, Key ID 24c6a8a7f4a80eb5 Source RPM : wget-1.14-18.el7.src.rpm Build Date : Tue 30 Oct 2018 12:54:41 PM EDT Build Host : x86-01.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : http://www.gnu.org/software/wget/ Summary : A utility for retrieving files using the HTTP or FTP protocols Description : GNU Wget is a file retrieval utility which can use either the HTTP or FTP protocols. Wget features include the ability to work in the background while you are logged out, recursive retrieval of directories, file name wildcard matching, remote file timestamp storage and comparison, use of Rest with FTP servers and Range with HTTP servers to retrieve files over slow or unstable connections, support for Proxy servers, and configurability.
If you want to get more information about a rpm package file whatever it is installed or not, you can use -qip option to rpm command.
$ rpm -qip wget-1.14-18.el7.x86_64.rpm
Conclusion
You should know that how to install/uninstall a rpm file through command line tool like rpm or yum on your CentOS or RHEL Linux 6/7.