install-specific-version-package-yum

Install a Package With YUM: A Basic Reference Guide

What is YUM?

Yum is the main tool used on the Red Hat Enterprise Linux distribution to manage software packages.

It’s not only used on Red Hat but also on CentOs and Fedora.

The way it works is consistent across those Linux distributions, so this tutorial won’t refer specifically to any of the three distributions.

The packages you can install via yum are available on remote repositories that can be queried using the yum command.

Some of the things you can use yum for are:

  • List packages from repositories.
  • Search for packages that match a specific term.
  • List installed packages.
  • Install a package on your system from a repository.
  • Update packages on your system.

Let’s say we want to install an Apache HTTP Server on our Linux machine…

First of all, we will use the yum search command to see the packages available for the Apache HTTP Server.

[ec2-user@ip-172-1-2-3 ~]$ yum search apache http server
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
================================================================ N/S matched: apache, http, server =================================================================
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP Server
httpd-filesystem.noarch : The basic directory layout for the Apache HTTP Server
httpd-manual.noarch : Documentation for the Apache HTTP Server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_auth_openidc.x86_64 : OpenID Connect auth module for Apache HTTP Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
mod_ldap.x86_64 : LDAP authentication modules for the Apache HTTP Server
mod_md.x86_64 : Certificate provisioning using ACME for the Apache HTTP Server
mod_nss.x86_64 : SSL/TLS module for the Apache HTTP server
mod_proxy_html.x86_64 : HTML and XML content filters for the Apache HTTP Server
mod_revocator.x86_64 : CRL retrieval module for the Apache HTTP server
mod_revocator.i686 : CRL retrieval module for the Apache HTTP server
mod_security.x86_64 : Security module for the Apache HTTP Server
mod_session.x86_64 : Session interface for the Apache HTTP Server
mod_ssl.x86_64 : SSL/TLS module for the Apache HTTP Server

The package we are interested in is the one in bold, let’s install it using the yum install command:

[ec2-user@ip-172-1-2-3 ~]$ yum install httpd
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
You need to be root to perform this command.

I’m running the yum install command as the ec2-user and as you can see Linux is suggesting that I need to be root to run this command.

So, let’s try again using the sudo command

[ec2-user@ip-172-1-2-3 ~]$ sudo yum install httpd
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                | 2.4 kB  00:00:00     
amzn2extra-docker                                         | 1.8 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.41-1.amzn2.0.1 for package: httpd-2.4.41-1.amzn2.0.1.x86_64
--> Processing Dependency: httpd-filesystem = 2.4.41-1.amzn2.0.1 for package: httpd-2.4.41-1.amzn2.0.1.x86_64
--> Processing Dependency: system-logos-httpd for package: httpd-2.4.41-1.amzn2.0.1.x86_64
--> Processing Dependency: mod_http2 for package: httpd-2.4.41-1.amzn2.0.1.x86_64
--> Processing Dependency: httpd-filesystem for package: httpd-2.4.41-1.amzn2.0.1.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.41-1.amzn2.0.1.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.41-1.amzn2.0.1.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.41-1.amzn2.0.1.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.6.3-5.amzn2.0.2 will be installed
---> Package apr-util.x86_64 0:1.6.1-5.amzn2.0.2 will be installed
--> Processing Dependency: apr-util-bdb(x86-64) = 1.6.1-5.amzn2.0.2 for package: apr-util-1.6.1-5.amzn2.0.2.x86_64
---> Package generic-logos-httpd.noarch 0:18.0.0-4.amzn2 will be installed
---> Package httpd-filesystem.noarch 0:2.4.41-1.amzn2.0.1 will be installed
---> Package httpd-tools.x86_64 0:2.4.41-1.amzn2.0.1 will be installed
---> Package mailcap.noarch 0:2.1.41-2.amzn2 will be installed
---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be installed
--> Running transaction check
---> Package apr-util-bdb.x86_64 0:1.6.1-5.amzn2.0.2 will be installed
--> Finished Dependency Resolution 

Dependencies Resolved

====================================================================================================================================================================
Package                  Arch       Version             Repository         Size
====================================================================================================================================================================
Installing:
 httpd                   x86_64     2.4.41-1.amzn2.0.1  amzn2-core         1.3 M
Installing for dependencies:
 apr                     x86_64     1.6.3-5.amzn2.0.2   amzn2-core         118 k
 apr-util                x86_64     1.6.1-5.amzn2.0.2   amzn2-core          99 k
 apr-util-bdb            x86_64     1.6.1-5.amzn2.0.2   amzn2-core          19 k
 generic-logos-httpd     noarch     18.0.0-4.amzn2      amzn2-core          19 k
 httpd-filesystem        noarch     2.4.41-1.amzn2.0.1  amzn2-core          23 k
 httpd-tools             x86_64     2.4.41-1.amzn2.0.1  amzn2-core          87 k
 mailcap                 noarch     2.1.41-2.amzn2      amzn2-core          31 k
 mod_http2               x86_64     1.15.3-2.amzn2      amzn2-core         146 k

Transaction Summary
====================================================================================================================================================================
Install  1 Package (+8 Dependent packages)

Total download size: 1.8 M
Installed size: 5.1 M
Is this ok [y/d/N]: y
Downloading packages:
(1/9): apr-util-1.6.1-5.amzn2.0.2.x86_64.rpm              |  99 kB  00:00:00     
(2/9): apr-1.6.3-5.amzn2.0.2.x86_64.rpm                   | 118 kB  00:00:00     
(3/9): apr-util-bdb-1.6.1-5.amzn2.0.2.x86_64.rpm          |  19 kB  00:00:00     
(4/9): generic-logos-httpd-18.0.0-4.amzn2.noarch.rpm      |  19 kB  00:00:00     
(5/9): httpd-filesystem-2.4.41-1.amzn2.0.1.noarch.rpm     |  23 kB  00:00:00     
(6/9): httpd-tools-2.4.41-1.amzn2.0.1.x86_64.rpm          |  87 kB  00:00:00     
(7/9): httpd-2.4.41-1.amzn2.0.1.x86_64.rpm                | 1.3 MB  00:00:00     
(8/9): mailcap-2.1.41-2.amzn2.noarch.rpm                  |  31 kB  00:00:00     
(9/9): mod_http2-1.15.3-2.amzn2.x86_64.rpm                | 146 kB  00:00:00     
---------------------------------------------------------------------------------
Total                                            9.5 MB/s | 1.8 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.6.3-5.amzn2.0.2.x86_64                                  1/9 
  Installing : apr-util-bdb-1.6.1-5.amzn2.0.2.x86_64                         2/9 
  Installing : apr-util-1.6.1-5.amzn2.0.2.x86_64                             3/9 
  Installing : httpd-tools-2.4.41-1.amzn2.0.1.x86_64                         4/9 
  Installing : generic-logos-httpd-18.0.0-4.amzn2.noarch                     5/9 
  Installing : mailcap-2.1.41-2.amzn2.noarch                                 6/9 
  Installing : httpd-filesystem-2.4.41-1.amzn2.0.1.noarch                    7/9 
  Installing : mod_http2-1.15.3-2.amzn2.x86_64                               8/9 
  Installing : httpd-2.4.41-1.amzn2.0.1.x86_64                               9/9 
  Verifying  : apr-util-1.6.1-5.amzn2.0.2.x86_64                             1/9 
  Verifying  : apr-util-bdb-1.6.1-5.amzn2.0.2.x86_64                         2/9 
  Verifying  : httpd-2.4.41-1.amzn2.0.1.x86_64                               3/9 
  Verifying  : httpd-filesystem-2.4.41-1.amzn2.0.1.noarch                    4/9 
  Verifying  : mod_http2-1.15.3-2.amzn2.x86_64                               5/9 
  Verifying  : apr-1.6.3-5.amzn2.0.2.x86_64                                  6/9 
  Verifying  : mailcap-2.1.41-2.amzn2.noarch                                 7/9 
  Verifying  : generic-logos-httpd-18.0.0-4.amzn2.noarch                     8/9 
  Verifying  : httpd-tools-2.4.41-1.amzn2.0.1.x86_64                         9/9 
 
Installed:
  httpd.x86_64 0:2.4.41-1.amzn2.0.1                                                                                                                                 
Dependency Installed:
  apr.x86_64 0:1.6.3-5.amzn2.0.2
  apr-util.x86_64 0:1.6.1-5.amzn2.0.2
  apr-util-bdb.x86_64 0:1.6.1-5.amzn2.0.2           
  generic-logos-httpd.noarch 0:18.0.0-4.amzn2
  httpd-filesystem.noarch 0:2.4.41-1.amzn2.0.1
  httpd-tools.x86_64 0:2.4.41-1.amzn2.0.1           
  mailcap.noarch 0:2.1.41-2.amzn2
  mod_http2.x86_64 0:1.15.3-2.amzn2                      

Complete!

The yum install command identifies all the dependencies required to install the httpd package and takes care of their installation automatically.

Very handy!

We can confirm that this package is now installed using the yum list command:

[ec2-user@ip-172-1-2-3 ~]$ yum list installed 'httpd'
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Installed Packages
httpd.x86_64                  2.4.41-1.amzn2.0.1                      @amzn2-core

The yum tool has automatically installed version 2.4.41-1.amzn2.0.1 of the httpd package because it automatically selects the latest version.

So, what if we want to install a specific version of a package?

To try that we need to uninstall the httpd package first, we will use yum remove followed by the name of the package:

[ec2-user@ip-172-1-2-3 ~]$ sudo yum remove httpd
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.41-1.amzn2.0.1 will be erased
--> Processing Dependency: httpd-mmn = 20120211x8664 for package: mod_http2-1.15.3-2.amzn2.x86_64
--> Running transaction check
---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be erased
--> Finished Dependency Resolution
amzn2-core/2/x86_64                                       | 2.4 kB  00:00:00     

Dependencies Resolved
 
==================================================================================
Package                  Arch       Version             Repository         Size
==================================================================================
Removing:
 httpd                   x86_64     2.4.41-1.amzn2.0.1  @amzn2-core        4.0 M
Removing for dependencies:
 mod_http2               x86_64     1.15.3-2.amzn2      @amzn2-core        378 k
 
Transaction Summary
==================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 4.3 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : httpd-2.4.41-1.amzn2.0.1.x86_64                               1/2 
  Erasing    : mod_http2-1.15.3-2.amzn2.x86_64                               2/2 
  Verifying  : mod_http2-1.15.3-2.amzn2.x86_64                               1/2 
  Verifying  : httpd-2.4.41-1.amzn2.0.1.x86_64                               2/2 

Removed:
  httpd.x86_64 0:2.4.41-1.amzn2.0.1                                                                                                                                 
Dependency Removed:
  mod_http2.x86_64 0:1.15.3-2.amzn2                                                                                                                                
Complete!

The package has been removed from the system, this is also confirmed by the command below:

[ec2-user@ip-172-1-2-3 ~]$ yum list installed 'httpd'
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Error: No matching Packages to list

Installing a Specific Version of a Package Using YUM

Now we want to see the different versions available for the httpd package…

…unfortunately the following command only returns one version:

[ec2-user@ip-172-1-2-3 ~]$ yum list httpd
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Available Packages
httpd.x86_64                  2.4.41-1.amzn2.0.1                amzn2-core

So, what can we do to see other versions?

The –showduplicates flag can be used to not limit  packages  to their latest versions:

[ec2-user@ip-172-1-2-3 ~]$ yum list httpd --showduplicates
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Available Packages
httpd.x86_64                                2.4.6-67.amzn2.6.1          amzn2-core
httpd.x86_64                                2.4.33-2.amzn2.0.2          amzn2-core
httpd.x86_64                                2.4.33-2.amzn2.0.3          amzn2-core
httpd.x86_64                                2.4.33-2.amzn2.1.0          amzn2-core
httpd.x86_64                                2.4.34-1.amzn2.1.0          amzn2-core
httpd.x86_64                                2.4.34-1.amzn2.1.1          amzn2-core
httpd.x86_64                                2.4.37-1.amzn2.0.1          amzn2-core
httpd.x86_64                                2.4.39-1.amzn2.0.1          amzn2-core
httpd.x86_64                                2.4.41-1.amzn2.0.1          amzn2-core

When we executed the yum install command before, yum automatically selected the latest version 2.4.41-1.amzn2.0.1.

Let’s try to install the previous version: 2.4.39-1.amzn2.0.1.

The command to install a specific package version through yum is:

yum install package-version

And if we run that command:

[ec2-user@ip-172-1-2-3 ~]$ sudo yum install httpd-2.4.39-1.amzn2.0.1 
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.39-1.amzn2.0.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.39-1.amzn2.0.1 for package: httpd-2.4.39-1.amzn2.0.1.x86_64
--> Processing Dependency: httpd-filesystem = 2.4.39-1.amzn2.0.1 for package: httpd-2.4.39-1.amzn2.0.1.x86_64
--> Processing Dependency: mod_http2 for package: httpd-2.4.39-1.amzn2.0.1.x86_64
--> Processing Dependency: httpd-filesystem for package: httpd-2.4.39-1.amzn2.0.1.x86_64
--> Running transaction check
---> Package httpd-filesystem.noarch 0:2.4.39-1.amzn2.0.1 will be installed
---> Package httpd-tools.x86_64 0:2.4.39-1.amzn2.0.1 will be installed
---> Package mod_http2.x86_64 0:1.15.3-2.amzn2 will be installed
--> Finished Dependency Resolution 

Dependencies Resolved
==================================================================================
Package                  Arch       Version             Repository         Size
==================================================================================
Installing:
 httpd                   x86_64     2.4.39-1.amzn2.0.1  amzn2-core         1.3 M
Installing for dependencies:
 httpd-filesystem        noarch     2.4.39-1.amzn2.0.1  amzn2-core          23 k
 httpd-tools             x86_64     2.4.39-1.amzn2.0.1  amzn2-core          87 k
 mod_http2               x86_64     1.15.3-2.amzn2      amzn2-core         146 k
 
Transaction Summary

==================================================================================
Install  1 Package (+3 Dependent packages) 

Total download size: 1.6 M
Installed size: 4.6 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): httpd-filesystem-2.4.39-1.amzn2.0.1.noarch.rpm     |  23 kB  00:00:00     
(2/4): httpd-2.4.39-1.amzn2.0.1.x86_64.rpm                | 1.3 MB  00:00:00     
(3/4): httpd-tools-2.4.39-1.amzn2.0.1.x86_64.rpm          |  87 kB  00:00:00     
(4/4): mod_http2-1.15.3-2.amzn2.x86_64.rpm                | 146 kB  00:00:00     
----------------------------------------------------------------------------------
Total                                                                                                                               7.9 MB/s | 1.6 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-tools-2.4.39-1.amzn2.0.1.x86_64                          1/4 
  Installing : httpd-filesystem-2.4.39-1.amzn2.0.1.noarch                     2/4 
  Installing : mod_http2-1.15.3-2.amzn2.x86_64                                3/4 
  Installing : httpd-2.4.39-1.amzn2.0.1.x86_64                                4/4 
  Verifying  : httpd-2.4.39-1.amzn2.0.1.x86_64                                1/4 
  Verifying  : httpd-filesystem-2.4.39-1.amzn2.0.1.noarch                     2/4 
  Verifying  : mod_http2-1.15.3-2.amzn2.x86_64                                3/4 
  Verifying  : httpd-tools-2.4.39-1.amzn2.0.1.x86_64                          4/4 
 
Installed:
  httpd.x86_64 0:2.4.39-1.amzn2.0.1                                                                                                                                 
Dependency Installed:
  httpd-filesystem.noarch 0:2.4.39-1.amzn2.0.1
  httpd-tools.x86_64 0:2.4.39-1.amzn2.0.1
  mod_http2.x86_64 0:1.15.3-2.amzn2              

Complete!

We now have httpd version 2.4.39-1.amzn2.0.1 on our system 🙂

Updating Packages Using YUM

What if at some point we have the requirement to update the httpd package to the latest version?

How can we update the package with yum?

[ec2-user@ip-172-31-28-249 ~]$ sudo yum update httpd
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                | 2.4 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
...
....
......
(few lines removed)
......
....
...
Updated:
  httpd.x86_64 0:2.4.41-1.amzn2.0.1                                                                                                                                
Dependency Updated:
  httpd-filesystem.noarch 0:2.4.41-1.amzn2.0.1                                      httpd-tools.x86_64 0:2.4.41-1.amzn2.0.1                                       

Complete!

As a result, the package has been updated to version 2.4.41-1.amzn2.0.1 that is the latest version for the package.

This is the same version installed by yum when we executed the yum install command without specifying the version.

Conclusion

Here is what we have learned about the yum command. How to:

  • Search for available packages.
  • Install the latest version of a package.
  • List the packages installed on your system.
  • Install a specific version of a package.
  • Update a package to the latest version.

And you? What package are you installing with yum?

Share knowledge with your friends!

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *