Monday, June 26, 2017

YUM Command For Package Management with Examples

It's very common tasks for user or system administrator to install, uninstall, search and update the software packages on Linux systems by using some kind of package manager utility like apt-get, dpkg, rpm, yum, etc.

In this article, we would discuss about one of the software package management utility i.e. YUM. We would discuss different yum commands to search/install/update/remove different software packages.

Points Of Discussion:
What is YUM ?
Different YUM commands
Different Real World Use Cases


What is YUM ?

YUM (Yellowdog Updater Modified) is an open-source, interactive, command-line, package-management utility for RPM based Linux systems for managing Red Hat Enterprise Linux RPM software packages from official Red Hat software repositories, as well as other third-party repositories. Automatic dependency resolution is done while updating, installing, or removing packages. One can also use plug-ins to enhance and extend its capabilities. yum is used in Red Hat Enterprise Linux versions 5 and later. Versions of Red Hat Enterprise Linux 4 and earlier used up2date.

YUM can be used for below tasks:
  • Querying available package(s) information from repositories
  • Querying all the installed package(s) information in the system
  • Querying dependencies for a specific package
  • Querying repositories for available package updates 
  • Querying information about enabled software repositories
  • Querying information about installed and available package groups
  • Querying description and contents of a package group 
  • Finding which repository a package comes from
  • Installing a package from a repository to the system
  • Installing a package from a local file, http, or ftp
  • Updating one or all packages on the system
  • Upgrading or downgrading one or all packages to a particular version
  • Removing a package (and possibly dependencies) from the system
  • Checking the local RPM database for problems 
  • Clearing out cached package data and metadata

Different YUM Commands

 In this section, YUM commands are grouped in different categories based on the functionalities:

YUM QUERIES

#Individual packages
yum help                      //Show yum subcommands and options
yum list available            //List all available packages
yum list installed            //List all installed packages
yum list all                  //List installed and available packages
yum list kernel               //List installed and available kernel packages
yum info [package name]       //Display information about a package
yum deplist [package name]    //List dependencies and packages providing them
yum provides [package name]   //Find packages that provide the queried file
yum search [package name]     //Search package names and descriptions for a term
yum updateinfo [package name]  //Get information about available package updates

#Groups of packages
yum grouplist          //List names of installed and available package groups
yum groupinfo [package group]  //Display description and contents of a package group
yum check-update               //Query repositories for available package updates

INSTALL, REMOVE AND UPGRADE PACKAGES WITH YUM

yum install [package name/s]   //Install a package from a repository to the system
yum -y install [package name/s]   //Assume yes if prompted & install without asking
yum update                  //Update all packages on the system with available updates
yum update [package name/s]    //Update the specified packages on the system
yum update-to [package name/s]    //Update one or all packages to a particular version 
yum upgrade [package name/s]   //Update packages taking obsoletes into account 
yum localinstall [rpmfile/s]   //Install a package from a local file, http, or ftp
yum downgrade [package name/s] //Downgrade a package to an earlier version
yum reinstall [package name/s] //Reinstall the current version of a package
yum remove [package name/s]    //Erase specified package & dependencies from the system
yum erase [package name/s]     //same as [remove]
yum autoremove [package name]  //Same as erase, + removes additional unneeded packages*
yum groupinstall [group/s]     //Install all packages in the selected group
yum groupupdate [group/s]      //Update all packages in the selected group
yum groupremove [group/s]      //Remove all packages in the selected group

MANAGE YUM REPOSITORIES

yum repolist                      //Display enabled software repositories
yum repoinfo [repo name]          //Display information about enabled yum repositories*
yum repo-pkgs [repo-name] [cmd]   //Work with packages in a particular repository*
yum makecache                     //Download yum repository data to cache

TROUBLESHOOT AND MAINTAIN YUM

yum clean packages          //Delete packages saved in cache
yum clean all               //Clean out all packages and meta data from cache
yum history list            //List all yum install, update and erase actions
yum history info [t_id]     //Show details of yum transaction [t_id]
yum history undo [t_id]     //Undo the yum action from transaction [t_id]
yum history redo [t_id]     //Redo the undone yum action from transaction [t_id]
yum check                   //Check the local RPM database for problems
* New options for RHEL 7

Note:

  • If no package matches the given package name(s), they are assumed to be a shell glob and any matches are then installed/updated/removed accordingly.
  • It's recommended to configure the GPG signature checking (from /etc/yum.conf) on all packages in all repositories, including local package installation so that packages can only be downloaded & installed from trusted source.

Different Real World Use Cases

We would show some real world YUM command examples here:
  • Execute yum commands using YUM Shell 
    Generally developers or system admins creates a text file containing all the commands that they would like to execute in multiple systems and then they execute it using 'yum shell' like
    ~]$cat shell try_yum_shell.txt
    repolist
    info yum
    ~]$yum shell try_yum_shell.txt
    Loaded plugins: fastestmirror
    Setting up Yum Shell
    repo id        repo name                                         status 
    base           CentOS-6 - Base                                   6,706
    *epel          Extra Packages for Enterprise Linux 6 - x86_64    12,264
    extras         CentOS-6 - Extras                                 45
    updates        CentOS-6 - Updates                                383
    Installed Packages
    Name        : yum
    Arch        : noarch
    Version     : 3.2.29
    Release     : 81.el6.centos
    Size        : 4.6 M
    Repo        : installed
    From repo   : base
    Summary     : RPM package installer/updater/manager
    URL         : http://yum.baseurl.org/
    License     : GPLv2+
    Description : Yum is a utility that can check for and automatically download 
                :and install updated RPM packages. Dependencies are obtained and 
                :downloaded automatically, prompting the user for permission as 
                :necessary.
    
    Leaving Shell
    
  • Use YUM to search and install the packages
    Recently I wanted to install Docker in my system (CentOS 6 ) but as per the latest Docker documentation, to install Docker, we need the 64-bit version of CentOS 7. After browsing, I came to know that Docker has been available in EPEL, under the name docker-io. Therefore first I need to validate that if it's really available in the EPEL repo and if yes then install it. This is what I did:
    ~]$sudo yum --enablerepo="epel" list available | grep 'docker-io'
    docker-io.x86_64                            1.7.1-2.el6                  epel
    docker-io-fish-completion.x86_64            1.7.1-2.el6                  epel
    docker-io-logrotate.x86_64                  1.7.1-2.el6                  epel
    docker-io-vim.x86_64                        1.7.1-2.el6                  epel
    docker-io-zsh-completion.x86_64             1.7.1-2.el6                  epel
    ~]$sudo yum install --enablerepo="epel" install 'docker-io.x86_64'
    
Thank you for reading this article. Hope you would like it. If you have any suggestion, question or wanted to share your yum related use case do let us know in the comments and please don’t forget to share this article with your friends. This is the best way to say thanks. Happy Learning!!

No comments:

Post a Comment