Table of Contents
In this tutorial, I will take you through Top 22 YUM Command Examples in RedHat/CentOS 7. YUM command is the most widely used command in RedHat and CentOS environment to download and install packages from Repository. It is also able to detect and install the dependent packages which otherwise will be a very difficult to do if we have to do it manually. So in a way yum command makes our life way too easy in that sense.
Prerequisites
You need to login as either root user or any other user with sudo access to run all yum commands. Here I am using root user for running all the below yum commands.
YUM Command Examples
Also Read: How to Install or Enable ssh on Ubuntu
1. Update Packages using yum update
To update all the currently installed packages in the system, run yum update
command. This command is a daily use yum command which you will mostly use before installing any new packages to update your system.
[root@localhost ~]# yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 9.5 kB 00:00:00
* base: centos.excellmedia.net
* epel: repos.del.extreme-ix.org
* extras: centos.excellmedia.net
* openstack-rocky: centos.excellmedia.net
* rdo-qemu-ev: centos.excellmedia.net
* updates: centos.excellmedia.net
2. Install Packages Silently
If you want to install packages without displaying the output in CLI window, then you can use -q
option with yum install
command to quietly install packages as shown below.
[root@localhost ~]# yum install cups -y -q
NOTE:
3. Complete all remaining transactions
Sometimes it might happen that while running yum update, system went to shutdown state. In that case you need to run yum-complete-transaction
command to complete all remaining transactions.
[root@localhost john]# yum-complete-transaction No unfinished transactions left.
4. Skip Broken Packages during yum update
Sometimes you might have encountered error like broken packages while running yum update command, to resolve those error you might want to use --skip-broken
option with yum update
command to skip the broken packages as shown below. This is another very important yum command which you will use in the event of any disaster when your system suddenly shutdown while updating Linux packages.
[root@localhost ~]# yum update --skip-broken Resolving Dependencies --> Running transaction check ---> Package audit.x86_64 0:2.8.4-4.el7 will be updated ---> Package audit.x86_64 0:2.8.5-4.el7 will be an update ...........................................................................................................
5. Check all the installed packages through yum list installed packages
To List all currently installed packages, you need to use yum list installed
command. This yum command is generally used to check all the Linux packages currently available in your server.
[root@localhost ~]# yum list installed Installed Packages GeoIP.x86_64 1.5.0-14.el7 @base NetworkManager.x86_64 1:1.18.0-5.el7_7.1 @updates NetworkManager-libnm.x86_64 1:1.18.0-5.el7_7.1 @updates NetworkManager-team.x86_64 1:1.18.0-5.el7_7.1 @updates NetworkManager-tui.x86_64 1:1.18.0-5.el7_7.1 @updates PyYAML.x86_64 3.10-11.el7 @base acl.x86_64 2.2.51-14.el7 @anaconda adobe-mappings-cmap.noarch 20171205-3.el7 @base adobe-mappings-cmap-deprecated.noarch 20171205-3.el7 @base adobe-mappings-pdf.noarch 20180407-1.el7 @base .........................................................................................................
6. Check History through yum history
To check all the commands used with yum in the past, you can run yum history
command.
[root@localhost ~]# yum history Loaded plugins: fastestmirror ID | Command line | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 79 | install pssh | 2020-01-12 07:27 | Install | 1 78 | update | 2020-01-12 07:25 | O, U | 17 E< 77 | install java-11-openjdk- | 2019-12-12 08:08 | Install | 1 > 76 | install java-11-openjdk | 2019-12-12 08:03 | Install | 6 75 | install -y epel-release | 2019-12-11 06:31 | Install | 1 74 | remove -y epel-release | 2019-12-11 06:31 | Erase | 1 73 | install -y mariadb-serve | 2019-12-11 05:42 | Install | 1 72 | install -y rabbitmq-serv | 2019-12-11 05:42 | Install | 1 71 | install -y epel-release | 2019-12-11 05:40 | Install | 1 70 | remove -y epel-release | 2019-12-11 05:39 | Erase | 1 history list
7. Clean up Repo using yum clean all
If you want to clean up all repo, you can do that by using yum clean all
command. There may be an instance where you might face some issues while running any of the yum command, the first thing you will think to do is to clean up your repo through yum clean command as shown below.
[root@localhost ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base epel extras kubernetes openstack-rocky puppetlabs-pc1 rdo-qemu-ev updates Cleaning up list of fastest mirrors Other repos take up 38 M of disk space (use --verbose for details)
8. Install Packages using yum install
To install any packages like python3 in your system, you need to use yum install python3
command.
[root@localhost ~]# yum install python3 Loaded plugins: fastestmirror Determining fastest mirrors epel/x86_64/metalink | 9.5 kB 00:00:00 * base: mirrors.piconets.webwerks.in * epel: mirrors.piconets.webwerks.in * extras: mirrors.piconets.webwerks.in * openstack-rocky: mirrors.piconets.webwerks.in * rdo-qemu-ev: centos.excellmedia.net * updates: mirrors.piconets.webwerks.in .....................................................................................................
9. Remove packages using yum remove
If you want remove any package say python3 in our case, then to do that you need to run yum remove python3
command. This will remove python3 package from your system.
[root@localhost ~]# yum remove python3 Loaded plugins: fastestmirror Resolving Dependencies --> Running transaction check ---> Package python3.x86_64 0:3.6.8-10.el7 will be erased --> Processing Dependency: python(abi) = 3.6 for package: python3-setuptools-39.2.0-10.el7.noarch --> Processing Dependency: python(abi) = 3.6 for package: python3-libs-3.6.8-10.el7.x86_64 --> Processing Dependency: python(abi) = 3.6 for package: python3-pip-9.0.3-5.el7.noarch --> Processing Dependency: python(abi) = 3.6 for package: python3-setuptools-39.2.0-10.el7.noarch --> Processing Dependency: python(abi) = 3.6 for package: python3-libs-3.6.8-10.el7.x86_64 --> Processing Dependency: python(abi) = 3.6 for package: python3-pip-9.0.3-5.el7.noarch --> Running transaction check ...............................................................................................................................
10. Check Repolist Using yum repolist
To check the total number of repolist, you can execute yum repolist
command and check.
[root@localhost ~]# yum repolist repo id repo name status base/7/x86_64 CentOS-7 - Base 10,097 epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,509 extras/7/x86_64 CentOS-7 - Extras 307 kubernetes Kubernetes 451 openstack-rocky/x86_64 OpenStack Rocky Repository 2,535 puppetlabs-pc1/x86_64 Puppet Labs PC1 Repository el 7 - x86_64 192 rdo-qemu-ev/x86_64 RDO CentOS-7 - QEMU EV 87 updates/7/x86_64 CentOS-7 - Updates 1,012 repolist: 28,190
11. Check update through yum check-update
If you want to check if any update is available any of the installed packages in your system, then you can check it through by running yum check-update
command.
[root@localhost ~]# yum check-update Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.piconets.webwerks.in * epel: mirrors.piconets.webwerks.in * extras: mirrors.piconets.webwerks.in * openstack-rocky: mirrors.piconets.webwerks.in * rdo-qemu-ev: centos.excellmedia.net * updates: mirrors.piconets.webwerks.in kubeadm.x86_64 1.17.1-0 kubernetes kubectl.x86_64 1.17.1-0 kubernetes kubelet.x86_64 1.17.1-0 kubernetes
12. Upgrade packages using yum upgrade
To upgrade packages in your system, you need to use yum upgrade
command. Since I have the latest python version already installed hence it is not showing any latest updates to install.
[root@localhost ~]# yum upgrade python3
No packages marked for update
13. Show UpdateInfo Summary using yum updateinfo
To show all the latest security fixes and bug fixes available, you need to run yum updateinfo summary
command. Since i have the latest security patches already installed hence it is not showing anything to me.
[root@localhost ~]# yum updateinfo summary
updateinfo summary done
You might want to see other commands available to check installed and available advisories. For example, if you want to see all the installed and available advisories, then you check it by running below command.
yum updateinfo list all
If you want list all available advisories, then you need to run below command.
yum updateinfo list available
If you want list all installed advisories, then you need to use execute below command.
yum updateinfo list installed
14. Reinstall Package using yum reinstall
If you want to reinstall any packages, then you need to use yum reinstall
command.
[root@localhost ~]# yum reinstall python3
Resolving Dependencies
--> Running transaction check
---> Package python3.x86_64 0:3.6.8-10.el7 will be reinstalled
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================================
Reinstalling:
python3 x86_64 3.6.8-10.el7 base 69 k
Transaction Summary
========================================================================================================================================================================
Reinstall 1 Package
Total download size: 69 k
Installed size: 39 k
Is this ok [y/d/N]:
...................................................................................................................
15. Download a Package without Installing through yum-plugin-downloadonly
In some cases, you do not want to install the package just download it. For those purposes there is an option --downloadonly
with yum which will only download the package and not install it. Here I have downloaded all the packages related to cups in /home/john
directory as you can see below.
[root@localhost ~]# yum install --downloadonly --downloaddir=/home/john cups
Resolving Dependencies
--> Running transaction check
---> Package cups.x86_64 1:1.6.3-40.el7 will be installed
--> Processing Dependency: cups-filesystem = 1:1.6.3-40.el7 for package: 1:cups-1.6.3-40.el7.x86_64
--> Processing Dependency: ghostscript-cups for package: 1:cups-1.6.3-40.el7.x86_64
--> Running transaction check
---> Package cups-filesystem.noarch 1:1.6.3-40.el7 will be installed
--> Processing Dependency: cups-filters for package: 1:cups-filesystem-1.6.3-40.el7.noarch
---> Package ghostscript-cups.x86_64 0:9.25-2.el7_7.3 will be installed
--> Processing Dependency: ghostscript = 9.25-2.el7_7.3 for package: ghostscript-cups-9.25-2.el7_7.3.x86_64
--> Running transaction check
---> Package cups-filters.x86_64 0:1.0.35-26.el7 will be installed
--> Processing Dependency: cups-filters-libs(x86-64) = 1.0.35-26.el7 for package: cups-filters-1.0.35-26.el7.x86_64
....................................................................................................................................
Check download Packages in /home/john directory if it is downloaded or not.
[root@localhost john]# ls -lrt
total 5892
-rw-r--r-- 1 root root 2254884 Jul 4 2014 poppler-data-0.4.6-3.el7.noarch.rpm
-rw-r--r-- 1 root root 335992 Jul 4 2014 qpdf-libs-5.0.1-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 25576 Apr 25 2018 avahi-glib-0.6.31-19.el7.x86_64.rpm
-rw-r--r-- 1 root root 27672 Apr 25 2018 liberation-fonts-common-1.07.2-16.el7.noarch.rpm
-rw-r--r-- 1 root root 232864 Apr 25 2018 liberation-mono-fonts-1.07.2-16.el7.noarch.rpm
-rw-r--r-- 1 root root 88128 Nov 12 2018 openjpeg-libs-1.5.1-18.el7.x86_64.rpm
-rw-r--r-- 1 root root 1343440 Aug 22 17:21 cups-1.6.3-40.el7.x86_64.rpm
16. Check Installed and Available Kernel Packages
If you want to check all the Installed and available Kernel Packages, you can check it through yum list kernel
command.
[root@localhost john]# yum list kernel Installed Packages kernel.x86_64 3.10.0-957.el7 @anaconda kernel.x86_64 3.10.0-1062.4.3.el7 @updates kernel.x86_64 3.10.0-1062.9.1.el7 @updates
17. Create Metadata Cache through yum makecache
If you want to build your metadata cache, you can do it by running yum makecache
command. You usually use this yum command when you want your cache to be fully updated with all the metadata.
[root@localhost ~]# yum makecache (1/10): extras/7/x86_64/other_db | 100 kB 00:00:00 (2/10): epel/x86_64/prestodelta | 453 B 00:00:00 (3/10): openstack-rocky/x86_64/other_db | 418 kB 00:00:00 (4/10): puppetlabs-pc1/x86_64/other_db | 13 kB 00:00:00 (5/10): base/7/x86_64/other_db | 2.6 MB 00:00:01 (6/10): rdo-qemu-ev/x86_64/other_db | 61 kB 00:00:00 (7/10): updates/7/x86_64/other_db | 368 kB 00:00:00 (8/10): kubernetes/other | 40 kB 00:00:01 (9/10): epel/x86_64/other_db | 3.3 MB 00:00:02 (10/10): epel/x86_64/updateinfo_zck | 1.5 MB 00:00:06 kubernetes 451/451 Metadata Cache Created
18. Install Packages Locally using yum localinstall
If you want to install some package which is available locally in your system rather than download and install from the Repo, then you can do that by using yum localinstall
command. This yum command is specifically useful where you do not have any internet connection in your server and you wanted to install from local rpm only.
[root@localhost john]# yum localinstall cups-1.6.3-40.el7.x86_64.rpm Loaded plugins: fastestmirror Examining cups-1.6.3-40.el7.x86_64.rpm: 1:cups-1.6.3-40.el7.x86_64 Marking cups-1.6.3-40.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package cups.x86_64 1:1.6.3-40.el7 will be installed --> Processing Dependency: cups-filesystem = 1:1.6.3-40.el7 for package: 1:cups-1.6.3-40.el7.x86_64 --> Processing Dependency: ghostscript-cups for package: 1:cups-1.6.3-40.el7.x86_64 --> Running transaction check ---> Package cups-filesystem.noarch 1:1.6.3-40.el7 will be installed --> Processing Dependency: cups-filters for package: 1:cups-filesystem-1.6.3-40.el7.noarch ---> Package ghostscript-cups.x86_64 0:9.25-2.el7_7.3 will be installed --> Processing Dependency: ghostscript = 9.25-2.el7_7.3 for package: ghostscript-cups-9.25-2.el7_7.3.x86_64 --> Running transaction check ---> Package cups-filters.x86_64 0:1.0.35-26.el7 will be installed .....................................................................................................................................................
19. Search Packages through yum search
If you want to search a package let's say cups package from repository you need to run yum search cups
command to do that. It will display all the packages relating to cups package. From there you can select the package you need and install it.
[root@localhost ~]# yum search cups ========================================================================== N/S matched: cups =========================================================================== apcupsd-cgi.x86_64 : Web interface for apcupsd apcupsd-gui.x86_64 : GUI interface for apcupsd bluez-cups.x86_64 : CUPS printer backend for Bluetooth printers cups.x86_64 : CUPS printing system cups-bjnp.x86_64 : CUPS backend for the Canon BJNP network printers cups-client.x86_64 : CUPS printing system - client programs cups-devel.i686 : CUPS printing system - development environment cups-devel.x86_64 : CUPS printing system - development environment cups-filesystem.noarch : CUPS printing system - directory layout cups-filters.x86_64 : OpenPrinting CUPS filters and backends
20. Search Package Name of a Command
Sometimes you are not sure of the package name, only aware of the command that you wanted to use. yum command will search the package name for you if you provide the command name. In this example to search the netstat package name you need to execute yum provides netstat
command. It will provide you the complete package name.
[root@localhost ~]# yum provides netstat net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools Repo : @base Matched from: Filename : /usr/bin/netstat
21. Check Package Information through yum info
If you want to know about some package, you need to use yum info
command. For example, if you have some package net-tools and you want to know about this package, then you need to use yum info net-tools
command.
[root@localhost ~]# yum info net-tools Installed Packages Name : net-tools Arch : x86_64 Version : 2.0 Release : 0.25.20131004git.el7 Size : 917 k Repo : installed From repo : base Summary : Basic networking tools URL : http://sourceforge.net/projects/net-tools/ License : GPLv2+ Description : The net-tools package contains basic networking tools, : including ifconfig, netstat, route, and others. : Most of them are obsolete. For replacement check iproute package
22. Check Package Groups through yum grouplist
If you want to check the available Environment grouplist in which all packages are grouped together, you need to run yum grouplist
command.
[root@localhost ~]# yum grouplist Available Environment Groups: Minimal Install Compute Node Infrastructure Server File and Print Server Desktop MATE Desktop Basic Web Server Virtualization Host Server with GUI GNOME Desktop KDE Plasma Workspaces Development and Creative Workstation Available Groups: Cinnamon Compatibility Libraries Console Internet Tools Development Tools Done
If you want to install any package of a Particular Group say you wanted to install Basic web server group packages, then you need to use yum groupinstall "Basic web server"
command to do that.
[root@localhost ~]# yum groupinstall "Basic web server"
Warning: Group core does not have any packages to install.
Resolving Dependencies
--> Running transaction check
---> Package abrt-addon-ccpp.x86_64 0:2.1.11-55.el7.centos will be installed
--> Processing Dependency: abrt-libs = 2.1.11-55.el7.centos for package: abrt-addon-ccpp-2.1.11-55.el7.centos.x86_64
--> Processing Dependency: abrt = 2.1.11-55.el7.centos for package: abrt-addon-ccpp-2.1.11-55.el7.centos.x86_64
--> Processing Dependency: gdb >= 7.6.1-63 for package: abrt-addon-ccpp-2.1.11-55.el7.centos.x86_64
--> Processing Dependency: libreport-python for package: abrt-addon-ccpp-2.1.11-55.el7.centos.x86_64
--> Processing Dependency: elfutils for package: abrt-addon-ccpp-2.1.11-55.el7.centos.x86_64
--> Processing Dependency: abrt-retrace-client for package: abrt-addon-ccpp-2.1.11-55.el7.centos.x86_64
...............................................................................................................................................................................................
Also Read: How to install and configure ClamAV in Linux
Popular Searches
- yum download only
- yum clean cache
- yum package manager
- yum install specific version
- yum linux
- yum command