341

If there are two (or more) versions of a given RPM available in a YUM repository, how can I instruct yum to install the version I want?

Looking through the Koji build service I notice that there are several versions.

    ss #1

slm
  • 369,824

2 Answers2

483

To see what particular versions are available to you via yum you can use the --showduplicates switch . It gives you a list like "package name.architecture     version":

$ yum --showduplicates list httpd | expand
Loaded plugins: fastestmirror, langpacks, refresh-packagekit
Loading mirror speeds from cached hostfile
 * fedora: mirror.steadfast.net

Available Packages
httpd.x86_64                        2.4.6-6.fc20                         fedora 
httpd.x86_64                        2.4.10-1.fc20                        updates

As far as installing a particular version? You can append the version info to the name of the package, removing the architecture name, like so:

$ sudo yum install <package name>-<version info>

For example in this case if I wanted to install the older version, 2.4.6-6 I'd do the following:

$ sudo yum install httpd-2.4.6-6

You can also include the release info when specifying a package. In this case since I'm dealing with Fedora 20 (F20) the release info would be "fc20", and the architecture info too.

$ sudo yum install httpd-2.4.6-6.fc20
$ sudo yum install httpd-2.4.6-6.fc20.x86_64

repoquery

If you're ever unsure that you're constructing the arguments right you can consult with repoquery too.

$ sudo yum install yum-utils  # (to get `repoquery`)
$ repoquery --show-duplicates httpd-2.4*
httpd-0:2.4.6-6.fc20.x86_64
httpd-0:2.4.10-1.fc20.x86_64

downloading & installing

You can also use one of the following options to download a particular RPM from the web, and then use yum to install it.

$ yum --downloadonly <package>
-or-
$ yumdownloader <package>

And then install it like so:

$ sudo yum localinstall <path to rpm>

What if I want to download everything that package X requires?

$ yumdownloader --resolve <package>

Example

$ yumdownloader --resolve vim-X11
Loaded plugins: langpacks, presto, refresh-packagekit
Adding en_US to language list
--> Running transaction check
---> Package vim-X11.x86_64 2:7.3.315-1.fc14 set to be reinstalled
--> Finished Dependency Resolution
vim-X11-7.3.315-1.fc14.x86_64.rpm                              | 1.1 MB     00:01

Notice it's doing a dependency check, and then downloading the missing pieces. See my answer that covers it in more details here: How to download a file from repo, and install it later w/o internet connection?.

References

rogerdpack
  • 1,715
slm
  • 369,824
  • 2
    I don't think it work for packages between the latest version located @updates and the initial version for the OS located @fedora. For example if you try to install httpd-2.4.8-1, yum would say package not available. – Question Overflow Aug 23 '14 at 08:51
  • 1
    @QuestionOverflow - not following. That version doesn't show as being available in the repo. – slm Aug 23 '14 at 12:38
  • 1
    Let me try again with a real example from my yum log. python-libs-2.7.5-12.fc20.x86_64 was once installed on my computer but has since been replaced. Assuming now I want to install this specific package, yumdownloader python-libs-2.7.5-12* would say No Match for argument python-libs-2.7.5-12* Nothing to download. What I am trying to say is that once a new package arrive, the old one would no longer be accessible from yum. You can only install the latest package or the initial version, but not versions in between. – Question Overflow Aug 24 '14 at 04:13
  • 2
    @QuestionOverflow - In that scenario I think you have to use yum downgrade ... if the package was already installed and you're attempting to go back to it later. In my Q I was attempting to show how one would hand select a particular version of a package that hadn't been installed yet. http://docs.fedoraproject.org/en-US/Fedora/14/html/Software_Management_Guide/ch05s06s03.html – slm Aug 24 '14 at 07:53
  • No, it doesn't work even when upgrading to a specific package. I have experimented this with a fresh installation just a few days ago. You can only yum update to the latest package and not any version you desire. – Question Overflow Aug 24 '14 at 08:05
  • @QuestionOverflow - I'm not using yum update, I used yum install. – slm Aug 24 '14 at 08:07
  • Yes, it applies to yum install too. I got a list of installed programs with rpm -qa | sort > installed. Then after setting up the OS on my test server, I did yum install $(cat /tmp/installed). Some of the packages did not get installed because they are no longer available. – Question Overflow Aug 24 '14 at 08:12
  • @QuestionOverflow - in my scenario of this Q I'm installing package X which had never been installed before. We actually just used this method for my day job so I know that this whole thing worked in that scenario. Let me think about how to incorporate the scenario of "packageX was already installed" into this Q. I might rephrase the Q so that it's more specific to cut out your particular point. – slm Aug 24 '14 at 08:15
  • I am not sure how it is possible to install an older version of a package using yum even when you have not installed the package previously. I thought the mirror @updates do not keep older versions of the same software. Am I missing some repository? – Question Overflow Aug 24 '14 at 08:21
  • @QuestionOverflow - in my 20+ years of using RH (RPM + YUM) I'd generally discourage you from ever doing a rpm -qa | sort > /tmp/installed and then trying to replay that list into a new server. That's just not the appropriate way to make use of rpm or yum, IMO. – slm Aug 24 '14 at 08:21
  • Ok, what do you suggest is the proper way to get the same packages installed? – Question Overflow Aug 24 '14 at 08:23
  • @QuestionOverflow - I answered that Q before, at least have memories of it here. Search for it, I will as well, but it's 4:30am in the morning where I live and I'm trying to go to bed now 8-). – slm Aug 24 '14 at 08:24
  • @QuestionOverflow - here's one of the Q's that I remembered: http://unix.stackexchange.com/questions/146159/centos-rpm-qa-vs-yum-list-installed/146398#146398 – slm Aug 24 '14 at 08:34
  • @QuestionOverflow - there's this Q too that could use some updating with the method shown in the other Q, if you're looking for something to do 8-) http://unix.stackexchange.com/questions/71/duplicating-a-linux-installation-yum-based – slm Aug 24 '14 at 08:44
  • @slm - this worked great for httpd, but didn't work when I tried to install a specific version of OpenJDK using yum install java-1.7.0-openjdk-devel-1:1.7.0.65-2.5.1.2.el6_5. Is it due to the hyphens in the package name? – coderplus Mar 05 '15 at 17:46
  • @coderplus I think you need to omit the 1: prefix from the version string. – Jesse Glick Nov 07 '17 at 19:41
  • In my case yum didn't accept version with the release, e. g. yum install MariaDB-server-10.3.5-1 did not work while yum install MariaDB-server-10.3.5 worked well. – dimir Jun 19 '18 at 11:21
  • if you have the package installed and want to install a previous version of the package - yum install won't work, yum downgrade should be used instead. – Andrey Regentov Jan 10 '19 at 08:30
12

Another option, you can download rpm file then instruct yum to do a localinstall:

yum localinstall /path/to/package.rpm

A good place to get the packages you need is rpmfind.com and search the package name.

cuonglm
  • 153,898