How to use yum command on CentOS/RHEL

This forum is for the posting and reading of tutorials.
Post Reply
User avatar
kheny22
Apprentice
Posts: 8
Joined: Fri May 01, 2020 8:37 pm

How to use yum command on CentOS/RHEL

Post by kheny22 »

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?

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):

Code: Select all

# rhn_register
To register your RHEL 7.x system with RHN type the follwing

Code: Select all

# subscription-manager register --username tom --password jerry --auto-attach
How to display a list of updated software and security fix

Type the following command at shell prompt:

Code: Select all

# yum list updates
How to find out whether updates exist for packages that are already installed on my system

Code: Select all

# yum check-update
Patch up system by applying all updates

To download and install all updates type the following command:

Code: Select all

# yum update
You can only apply security-related package updates using the following syntax:

Code: Select all

$ sudo yum update --security
To update specified packages

Updates the specified package. The syntax is

Code: Select all

$ yum update {package-name-1}
To check for and update httpd package, enter:

Code: Select all

$ sudo yum update httpd
You can update one packages to a particular version say nginx using the following syntax:

Code: Select all

$ ## 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:

Code: Select all

$ rpm -qa ## not recommend just use yum ##
$ yum list installed
Find out if httpd package installed or not on the system

Code: Select all

$ rpm -qa | grep httpd*
$ yum list installed httpd
Lists all packages that are available to install all packages that are installed on system

Code: Select all

$ 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 ] ##

Code: Select all

Lists all packages that are available for installation

Code: Select all

$ 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:

Code: Select all

$ yum list {package-name}
$ yum list {regex}
$ yum list httpd
$ yum list perl*
$ yum search {package-name}
$ yum search nginx
$ yum search nginx*
How to see detailed information about a package

The syntax is:

Code: Select all

$ yum info {pkg-1} {pkg-2}
$ yum info htop
$ yum info nginx htop
How to show dependencies list for a package

The syntax is:

Code: Select all

$ yum deplist {pkg}
## show for htop pkg
$ yum deplist htop
How to install the specified packages [ RPM(s) ]

To install package called httpd:

Code: Select all

# yum install {package-name-1} {package-name-2}
# yum install httpd
# yum install nginx mariadb-server php-fpm
# yum install htop
To install a package from a local file called foo.rpm or http, or ftp mirror:

Code: Select all

$ 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

Code: Select all

$ 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:

Code: Select all

# yum downgrade {pkg}
# yum downgrade nginx
How to reinstall a package again

The syntax is:

Code: Select all

# yum reinstall {pkg}
# yum reinstall httpd
How to remove / uninstall the specified packages [ RPM(s) ]

Remove package called httpd, enter:

Code: Select all

# 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:

Code: Select all

# yum autoremove
Display the list of available packages

Code: Select all

$ yum list all
Display list of group software

Type the following command:

Code: Select all

$ yum grouplist
OR

Code: Select all

$ yum groups list
Install all the default packages by group

Install all ‘Development Tools’ group packages, enter:

Code: Select all

# yum groupinstall "Development Tools"
OR

Code: Select all

# yum groups install "Development Tools"
Update all the default packages by group

Update all ‘Development Tools’ group packages, enter:

Code: Select all

# yum groupupdate "Development Tools"
OR

Code: Select all

# yum groups update "Development Tools"
Remove all packages in a group

Remove all ‘Development Tools’ group packages, enter:

Code: Select all

# yum groupremove "Development Tools"
OR

Code: Select all

# yum groups remove "Development Tools"
Display description and contents of a package group

Code: Select all

$ yum groupinfo 'Development Tools'
OR

Code: Select all

$ yum groups info 'Development Tools'
$ yum groups info 'File and Print Server'
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):

Code: Select all

# 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:

Code: Select all

$ yum list extras
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:

Code: Select all

$ yum whatprovides /etc/passwd
OR

Code: Select all

$ yum provides /etc/passwd
You can use same command to list packages that satisfy dependencies:

Code: Select all

$ 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:

Code: Select all

# yum clean all
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:

Code: Select all

# yum check
How to list software repositories

Code: Select all

$ yum repolist
See information about enabled yum repositories

To get info about nginx repo, run:

Code: Select all

$ yum repoinfo nginx
How to work with given repository

The syntax is:

Code: Select all

# yum repo-pkgs repo_name_id <list|install|remove|upgrade|reinstall> [pkg]
List all packages from nginx repository:

Code: Select all

# yum repo-pkgs nginx list
Get info about nginx package from nginx repository:

Code: Select all

# yum repo-pkgs nginx info | more
# yum repo-pkgs nginx info nginx
Install a package named ‘nginx’ from nginx repository:

Code: Select all

# yum repo-pkgs nginx install nginx
Install ALL PACKAGES from nginx repository:

Code: Select all

# yum repo-pkgs nginx install
Erase/remove/delete a package named ‘nginx’ from nginx repository:

Code: Select all

# yum repo-pkgs nginx remove nginx
Erase/remove/delete ALL PACKAGES from nginx repository:

Code: Select all

# yum repo-pkgs nginx remove
Upgrade nginx package from nginx repository:

Code: Select all

# yum repo-pkgs nginx upgrade nginx
Reinstall nginx package from nginx repository:

Code: Select all

# yum repo-pkgs nginx reinstall nginx
How to view and use yum history

The syntax is:

Code: Select all

# 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:

Code: Select all

$ man yum
$ yum help
$ yum help install
$ yum help erase
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 command
man yum - Show help about yum command or read yum command man page

Post Reply