66

I want to list all packages I have installed on a system from a given repo using yum. Usually to do this I use yum list installed | grep "something". But now I am faced with a problem. The repo I am interested in does not have that "something" for me to grep. The packages from that repo do not have any distinctive characteristics. How do I list them?

I looked through yum man pages but did not find anything. I wonder if there are other commands I could use.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Mike Starov
  • 7,000
  • 7
  • 36
  • 37
  • 6
    this should be migrated to Unix and Linux,this is a decent question. – fedvasu Dec 26 '12 at 18:21
  • 2
    Unix Exchange already has [a question](http://unix.stackexchange.com/questions/22560/list-all-rpm-packages-installed-from-repo-x) that's very similar, if not the same. @fedvasu, I agree; just wrong forum, but good question, albeit with a simple answer:D – ILMostro_7 Jun 17 '14 at 06:54

2 Answers2

67

Try

yum list installed | grep reponame

On one of my servers:

yum list installed | grep remi
ImageMagick2.x86_64                       6.6.5.10-1.el5.remi          installed
memcache.x86_64                          1.4.5-2.el5.remi             installed
mysql.x86_64                              5.1.54-1.el5.remi            installed
mysql-devel.x86_64                        5.1.54-1.el5.remi            installed
mysql-libs.x86_64                         5.1.54-1.el5.remi            installed
mysql-server.x86_64                       5.1.54-1.el5.remi            installed
mysqlclient15.x86_64                      5.0.67-1.el5.remi            installed
php.x86_64                                5.3.5-1.el5.remi             installed
php-cli.x86_64                            5.3.5-1.el5.remi             installed
php-common.x86_64                         5.3.5-1.el5.remi             installed
php-domxml-php4-php5.noarch               1.21.2-1.el5.remi            installed
php-fpm.x86_64                            5.3.5-1.el5.remi             installed
php-gd.x86_64                             5.3.5-1.el5.remi             installed
php-mbstring.x86_64                       5.3.5-1.el5.remi             installed
php-mcrypt.x86_64                         5.3.5-1.el5.remi             installed
php-mysql.x86_64                          5.3.5-1.el5.remi             installed
php-pdo.x86_64                            5.3.5-1.el5.remi             installed
php-pear.noarch                           1:1.9.1-6.el5.remi           installed
php-pecl-apc.x86_64                       3.1.6-1.el5.remi             installed
php-pecl-imagick.x86_64                   3.0.1-1.el5.remi.1           installed
php-pecl-memcache.x86_64                  3.0.5-1.el5.remi             installed
php-pecl-xdebug.x86_64                    2.1.0-1.el5.remi             installed
php-soap.x86_64                           5.3.5-1.el5.remi             installed
php-xml.x86_64                            5.3.5-1.el5.remi             installed
remi-release.noarch                       5-8.el5.remi                 installed

It works.

floyd
  • 836
  • 1
  • 5
  • 3
  • 7
    Unfortunately this only works for repos that put something like "remi" on the end. rpmforge does work (they use "rf") but atrpms don't put anything on the end :/ – Hamish Downer Sep 08 '11 at 16:49
  • 4
    Also, re-reading the question, he says he normally does that, but can't in this case. – Hamish Downer Sep 08 '11 at 16:55
  • 3
    Another problem: If package names/version strings are too long (e.g. Solr from Cloudera) then the "@origin-repo" part gets pushed down to a new line, resulting in a line that is "[blank space]@origin-repo". – IBBoard Aug 08 '16 at 12:43
  • 2
    @IBBoard what about "export COLUMNS=999 yum..." – Massimo Aug 20 '18 at 20:04
  • @massimo , does not work. On RHEL 7.7 only thing that helped me was ` sed '/^[^@]*$/{N;s/\n` which appends next line if first one lacked `@` character. This will break though in case RPM is in no repo and only `installed` is printed. – akostadinov Mar 18 '20 at 19:34
  • @akostadinov Sorry I cannot edit my previous comment. The correct syntax is "export COLUMNS=999 && yum.." or "COLUMNS=999 yum.." – Massimo Apr 01 '20 at 22:18
  • @Massimo, I know correct syntax. The thing is that this env variable doesn't have effect for `yum-3.4.3-163.el7` as presently available in RHEL 7.7. It is possible that other versions do. – akostadinov Apr 03 '20 at 10:23
  • 1
    @Massimo, too bad I didn't look earlier at the second comment on the question which points at another answer. The best answer is actually `yum repo-pkgs repo-id list installed` which works on RHEL7.7 and is mych more sound than grepping. Link to proper answer: https://unix.stackexchange.com/a/233966/14907 – akostadinov Apr 07 '20 at 13:12
42

On newer versions of yum, this information is stored in the "yumdb" when the package is installed. This is the only 100% accurate way to get the information, and you can use:

yumdb search from_repo repoid

(or repoquery and grep -- don't grep yum output). However the command "find-repos-of-install" was part of yum-utils for a while which did the best guess without that information:

http://james.fedorapeople.org/yum/commands/find-repos-of-install.py

As floyd said, a lot of repos. include a unique "dist" tag in their release, and you can look for that ... however from what you said, I guess that isn't the case for you?

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
James Antill
  • 2,825
  • 18
  • 16