How do I use the yum command to update and patch my Red hat Enterprise Linux / CentOS Linux version 5.x/6.x/7.x server via RHN or the Internet? Can I use up2date command under a RHEL v5.x?
up2date command
was part of RHEL v4.x or older version. You need to use yum command to update and patch the system using RHN or Internet. Use yum command to install critical and non-critical security updates as well as binary packages. Login as the root user to install and update the system. This page show examples of common sysadmin tasks that you can perform using yum command on a CentOS or RHEL.How to register my RHEL based system with RHN
To register your RHEL 5.x system with RHN type the following command and just follow on screen instructions (CentOS user skip to the next step):
# rhn_register
To register your RHEL 7.x system with RHN type the folllwong
# subscription-manager register --username tom --password jerry --auto-attach
WARNING! These examples only works with
RHEL / CentOS Linux version 5.x or above. For RHEL 4.x and older version use up2date command.
How to display a list of updated software and security fix
Type the following command at shell prompt:
# yum list updates
Sample outputs:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iitm.ac.in
* epel: repo.ugm.ac.id
* extras: ftp.iitm.ac.in
* updates: ftp.iitm.ac.in
Updated Packages
apr.x86_64 1.3.9-5.el6_9.1 updates
device-mapper.x86_64 1.02.117-12.el6_9.1 updates
device-mapper-libs.x86_64 1.02.117-12.el6_9.1 updates
kernel-devel.x86_64 2.6.32-696.16.1.el6 updates
kernel-headers.x86_64 2.6.32-696.16.1.el6 updates
libblkid.x86_64 2.17.2-12.28.el6_9.1 updates
libuuid.x86_64 2.17.2-12.28.el6_9.1 updates
util-linux-ng.x86_64 2.17.2-12.28.el6_9.1 updates
How to find out whether updates exist for packages that are already installed on my system
# yum check-update
Patch up system by applying all updates
To download and install all updates type the following command:
# yum update
Sample outputs:
Updates all CentOS 6.x packages including packages on which they depend
You can only apply security-related package updates using the following syntax:$ sudo yum update --security
To update specified packages
Updates the specified package. The syntax is
$ yum update {package-name-1}
To check for and update httpd package, enter:
$ sudo yum update httpd
You can update one packages to a particular version say nginx using the following syntax:
$ ## first find a list of all dups ##
$ yum --showduplicates list nginx
$ ## now update to particular version ##
$ sudo yum update-to nginx-version
$ sudo yum update-to nginx-1.12.2-1.el7
List all installed packages
To list all installed packages, enter:
$ rpm -qa ## not recommend just use yum ##
$ yum list installed
Sample outputs:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iitm.ac.in
* epel: mirror1.ku.ac.th
* extras: ftp.iitm.ac.in
* updates: ftp.iitm.ac.in
Installed Packages
GeoIP.x86_64 1.5.0-11.el7 @base
OpenEXR-libs.x86_64 1.7.1-7.el7 @base
SDL.x86_64 1.2.15-14.el7 @base
ShellCheck.x86_64 0.3.5-1.el7 @epel
acl.x86_64 2.2.51-12.el7 @base
alsa-lib.x86_64 1.1.3-3.el7 @base
apr.x86_64 1.4.8-3.el7_4.1 @updates
apr-util.x86_64 1.5.2-6.el7 @base
atk.x86_64 2.22.0-3.el7 @base
atk-devel.x86_64 2.22.0-3.el7 @base
atlas.x86_64 3.10.1-12.el7 @base
audit-libs.x86_64 2.7.6-3.el7 @base
autoconf.noarch 2.69-11.el7 @base
autogen-libopts.x86_64 5.18-5.el7 @base
....
..
...
yum-plugin-fastestmirror.noarch 1.1.31-42.el7 @base
zip.x86_64 3.0-11.el7 @base
zlib.x86_64 1.2.7-17.el7 @base
zlib-devel.x86_64 1.2.7-17.el7 @base
Find out if httpd package installed or not on the system
$ rpm -qa | grep httpd*
$ yum list installed httpd
Sample outputs:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* epel: repo.ugm.ac.id
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
Installed Packages
httpd.x86_64 2.4.6-67.el7.centos.6 @updates
Lists all packages that are available to install all packages that are installed on system
$ yum list
$ yum list
$ yum list | more ## [ Use more command to show info one screen at a time ] ##
$ yum list | grep bash ## [ Use grep command to filter out results ] ##
Lists all packages that are available for installation
$ yum list available
$ yum list available | more
$ yum list available | grep nginx
How to search for packages by name
You can search the package descriptions for the specified string using search command. The list command can be used too. To search httpd and all matching perl packages, enter:
$ yum list {package-name}
$ yum list {regex}
$ yum list httpd
$ yum list perl*
$ yum search {package-name}
$ yum search nginx
$ yum search nginx*
Sample output from yum list perl*:
Loading "installonlyn" plugin
Loading "security" plugin
Setting up repositories
Reading repository metadata in from local files
Installed Packages
perl.i386 4:5.8.8-10.el5_0.2 installed
perl-Archive-Tar.noarch 1.30-1.fc6 installed
perl-BSD-Resource.i386 1.28-1.fc6.1 installed
perl-Compress-Zlib.i386 1.42-1.fc6 installed
perl-DBD-MySQL.i386 3.0007-1.fc6 installed
perl-DBI.i386 1.52-1.fc6 installed
perl-Digest-HMAC.noarch 1.01-15 installed
perl-Digest-SHA1.i386 2.11-1.2.1 installed
perl-HTML-Parser.i386 3.55-1.fc6 installed
.....
.......
..
perl-libxml-perl.noarch 0.08-1.2.1 base
perl-suidperl.i386 4:5.8.8-10.el5_0.2 updates
How to see detailed information about a package
The syntax is:
$ yum info {pkg-1} {pkg-2}
$ yum info htop
$ yum info nginx htop
Sample outputs:
Displays detailed information about a package on a RHEL/CentOS Linux server
How to show dependencies list for a package
The syntax is:
$ yum deplist {pkg}
## show for htop pkg
$ yum deplist htop
Sample outputs:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* epel: repo.ugm.ac.id
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
package: htop.x86_64 2.0.2-1.el7
dependency: libc.so.6(GLIBC_2.15)(64bit)
provider: glibc.x86_64 2.17-196.el7_4.2
dependency: libgcc_s.so.1()(64bit)
provider: libgcc.x86_64 4.8.5-16.el7_4.1
dependency: libgcc_s.so.1(GCC_3.0)(64bit)
provider: libgcc.x86_64 4.8.5-16.el7_4.1
dependency: libgcc_s.so.1(GCC_3.3.1)(64bit)
provider: libgcc.x86_64 4.8.5-16.el7_4.1
dependency: libm.so.6()(64bit)
provider: glibc.x86_64 2.17-196.el7_4.2
dependency: libm.so.6(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.17-196.el7_4.2
dependency: libncursesw.so.5()(64bit)
provider: ncurses-libs.x86_64 5.9-14.20130511.el7_4
dependency: libtinfo.so.5()(64bit)
provider: ncurses-libs.x86_64 5.9-14.20130511.el7_4
dependency: rtld(GNU_HASH)
provider: glibc.x86_64 2.17-196.el7_4.2
provider: glibc.i686 2.17-196.el7_4.2
How to install the specified packages [ RPM(s) ]
To install package called httpd:
# yum install {package-name-1} {package-name-2}
# yum install httpd
# yum install nginx mariadb-server php-fpm
# yum install htop
Sample outputs:
Installs the specified package named htop on a CentOS/RHEL
To install a package from a local file called foo.rpm or http, or ftp mirror:$ sudo yum localinstall foo.rpm
$ sudo yum https://server1.cyberciti.biz/foo.rpm
It is possible to install particular version too. To find or show duplicates, in repos, in list/search commands$ yum --showduplicates list php
$ ## now install to particular version ##
$ sudo yum update-to php-version
$ sudo yum update-to php-7.0.2-1.nix
How to downgrade a package to an earlier version
The syntax is:
# yum downgrade {pkg}
# yum downgrade nginx
How to reinstall a package again
The syntax is:
# yum reinstall {pkg}
# yum reinstall httpd
How to remove / uninstall the specified packages [ RPM(s) ]
Remove package called httpd, enter:
# yum remove {package-name-1} {package-name-2}
# yum erase {package-name-1} {package-name-2}
# yum remove httpd
# yum erase htop
How to remove unneeded/unwanted packages/deps
The syntax is:
# yum autoremove
Sample outputs:
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package tcp_wrappers-libs.x86_64 0:7.6-77.el7 will be erased
--> Finished Dependency Resolution
--> Finding unneeded leftover dependencies
Found and removing 0 unneeded dependencies
Dependencies Resolved
=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Removing:
tcp_wrappers-libs x86_64 7.6-77.el7 @base 131 k
Transaction Summary
=======================================================================================================
Remove 1 Package
Installed size: 131 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : tcp_wrappers-libs-7.6-77.el7.x86_64 1/1
Verifying : tcp_wrappers-libs-7.6-77.el7.x86_64 1/1
Removed:
tcp_wrappers-libs.x86_64 0:7.6-77.el7
Complete!
Display the list of available packages
$ yum list all
Display list of group software
Type the following command:
$ yum grouplist
OR
$ yum groups list
Output:
Installed Groups:
Engineering and Scientific
MySQL Database
Editors
System Tools
Text-based Internet
Legacy Network Server
DNS Name Server
Dialup Networking Support
FTP Server
Network Servers
Legacy Software Development
Legacy Software Support
Development Libraries
Graphics
Web Server
Ruby
Printing Support
Mail Server
Server Configuration Tools
PostgreSQL Database
Available Groups:
Office/Productivity
Administration Tools
Beagle
Development Tools
GNOME Software Development
X Software Development
Virtualization
GNOME Desktop Environment
Authoring and Publishing
Mono
Games and Entertainment
XFCE-4.4
Tomboy
Java
Java Development
Emacs
X Window System
Windows File Server
KDE Software Development
KDE (K Desktop Environment)
Horde
Sound and Video
FreeNX and NX
News Server
Yum Utilities
Graphical Internet
Done
Install all the default packages by group
Install all ‘Development Tools’ group packages, enter:
# yum groupinstall "Development Tools"
OR
# yum groups install "Development Tools"
Update all the default packages by group
Update all ‘Development Tools’ group packages, enter:
# yum groupupdate "Development Tools"
OR
# yum groups update "Development Tools"
Remove all packages in a group
Remove all ‘Development Tools’ group packages, enter:
# yum groupremove "Development Tools"
OR
# yum groups remove "Development Tools"
Display description and contents of a package group
$ yum groupinfo 'Development Tools'
OR
$ yum groups info 'Development Tools'
$ yum groups info 'File and Print Server'
Sample outputs:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: del-mirrors.extreme-ix.org
* epel: ftp.riken.jp
* extras: del-mirrors.extreme-ix.org
* updates: del-mirrors.extreme-ix.org
Environment Group: File and Print Server
Environment-Id: file-print-server-environment
Description: File, print, and storage server for enterprises.
Mandatory Groups:
+base
+core
+file-server
+print-server
Optional Groups:
+backup-client
+backup-server
+debugging
+directory-client
+guest-agents
+ha
+hardware-monitoring
+java-platform
+large-systems
+network-file-system-client
+performance
+remote-system-management
+resilient-storage
Install particular architecture package
If you are using 64 bit RHEL version it is possible to install 32 packages (please note that 32 bit support is dropped in the latest version of CentOS/RHEL 7.x):
# yum install {package-name}.{architecture}
# yum install mysql.i386
Display packages not installed via official RHN subscribed repos
Show all packages not available via subscribed channels or repositories i.e show packages installed via other repos:
$ yum list extras
Sample output:
Loading "installonlyn" plugin
Loading "security" plugin
Setting up repositories
Reading repository metadata in from local files
Extra Packages
DenyHosts.noarch 2.6-python2.4 installed
VMwareTools.i386 6532-44356 installed
john.i386 1.7.0.2-3.el5.rf installed
kernel.i686 2.6.18-8.1.15.el5 installed
kernel-devel.i686 2.6.18-8.1.15.el5 installed
lighttpd.i386 1.4.18-1.el5.rf installed
lighttpd-fastcgi.i386 1.4.18-1.el5.rf installed
psad.i386 2.1-1 installed
rssh.i386 2.3.2-1.2.el5.rf installed
Display what package provides the file
You can easily find out what RPM package provides the file. For example find out what provides the /etc/passwd file:
$ yum whatprovides /etc/passwd
OR
$ yum provides /etc/passwd
Sample output:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* epel: repo.ugm.ac.id
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
setup-2.8.71-7.el7.noarch : A set of system configuration and setup files
Repo : base
Matched from:
Filename : /etc/passwd
setup-2.8.71-7.el7.noarch : A set of system configuration and setup files
Repo : @base
Matched from:
Filename : /etc/passwd
You can use same command to list packages that satisfy dependencies:
$ yum whatprovides {dependency-1} {dependency-2}
$ yum provides string
$ yum provides '*bin/nginx*'
How to clean yum cache
You can delete all cached and downloaded package, headers and other info:
# yum clean all
Sample outputs:
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
Above command can help to clear problems that can result from out-of-date headers, network errors and more. To check the local RPM database for problems:
# yum check
How to list software repositories
$ yum repolist
Sample outputs:
repo id repo name status
base/7/x86_64 CentOS-7 - Base 9591
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12155
extras/7/x86_64 CentOS-7 - Extras 327
nginx/x86_64 nginx repo 313
updates/7/x86_64 CentOS-7 - Updates 1573
repolist: 23959
See information about enabled yum repositories
To get info about nginx repo, run:
$ yum repoinfo nginx
Sample outputs:
Repo-id : nginx/x86_64
Repo-name : nginx repo
Repo-status : enabled
Repo-revision: 1511279401
Repo-updated : Tue Nov 21 15:50:07 2017
Repo-pkgs : 313
Repo-size : 143 M
Repo-baseurl : http://nginx.org/packages/mainline/centos/7/x86_64/
Repo-expire : 21600 second(s) (last: Sat Dec 23 16:49:24 2017)
Filter : read-only:present
Repo-filename: /etc/yum.repos.d/nginx.repo
repolist: 313
How to work with given repository
The syntax is:
# yum repo-pkgs repo_name_id <list|install|remove|upgrade|reinstall> [pkg]
List all packages from nginx repository:
# yum repo-pkgs nginx list
Get info about nginx package from nginx repository:
# yum repo-pkgs nginx info | more
# yum repo-pkgs nginx info nginx
Install a package named ‘nginx’ from nginx repository:
# yum repo-pkgs nginx install nginx
Install ALL PACKAGES from nginx repository:
# yum repo-pkgs nginx install
Erase/remove/delete a package named ‘nginx’ from nginx repository:
# yum repo-pkgs nginx remove nginx
Erase/remove/delete ALL PACKAGES from nginx repository:
# yum repo-pkgs nginx remove
Upgrade nginx package from nginx repository:
# yum repo-pkgs nginx upgrade nginx
Reinstall nginx package from nginx repository:
# yum repo-pkgs nginx reinstall nginx
How to view and use yum history
The syntax is:
# yum history
# yum history list
# yum info ID
# yum undo ID
# yum redo ID
How to see help about yum command
Refer yum command man page for more information:
$ man yum
$ yum help
$ yum help install
$ yum help erase
Sample outputs:
Loaded plugins: fastestmirror
erase PACKAGE...
Remove a package or packages from your system
alias: remove
Summary of yum command
Command name | Description/usage |
---|
yum check-update | Display list of available package updates |
yum update yum update pkg1 | Update all packages or update the pkg1 package |
yum install pkg | Install a package |
yum localinstall pkg.rpm | Install a package from a file named pkg.rpm |
yum erase pkg | Remove a package |
yum remove pkg | Same as above |
yum autoremove | Free disk space by removing unwanted packages |
yum reinstall pkg | Reinstall a package |
yum downgrade pkg | Downgrade a package to an older version |
yum check | Check rpm database for errors/problems |
yum clean packages | Delete cached packages database |
yum clean all | Delete out all packages and meta data from disk cache |
yum list yum list installed yum list php yum list available | List package names |
yum deplist pkg1 | Show dependencies for a pkg1 |
yum info pkg | Show info about a package |
yum search pkg yum search regex | Search package names |
yum provides string yum whatprovides string | List package that provides the given file or other info |
yum history list | Show a list of all yum command history action such as install/update/erase |
yum history info ID | Get info of yum action ID |
yum history undo ID | Undo the yum command action from ID |
yum history redor ID | Redot the yum command action from ID |
yum grouplist | List package groups |
yum groupinstall ‘Group Name’ | Install all packages in the given group name |
yum groupinfo ‘Group Name’ | See packages in the given group name |
yum groupremove ‘Group Name’ | Remove/Delete all packages in the selected group |
yum repolist | Show a list of all enabled repositories |
yum repoinfo repoID | Show info about repoID |
yum repo-pkgs repoID list | Show packages from repoID repo |
yum repo-pkgs repoID install | Install all packages from repoID repo |
yum repo-pkgs repoID remove | Erase all packages from repoID repo |
yum repo-pkgs repoID reinstall | Reinstall all packages from repoID repo |
yum help yum help commandman yum | Show help about yum command or read yum command man page |