How can I efficiently list installed and available packages on Cent OS?
I have already tried yum list installed, which is supposed to output the list of all installed while rpm -qa produces a different result in size.
Which one should I trust? Or am I omitting something?
My understanding is: rpm -qa is better to know what is installed (RPM packages, right! ). Whereas yum is better to know what could be installed and find required dependencies. It is usually fine to use yum for both purposes.
I tested on a CentOS 7 system. They have almost identical list, except that rpm also reports some gpg-pubkey pseudo packages (try rpm -qa gpg-pubkey\*).
If you want to compare the lists on your system, first get the rpm's list:
$ rpm -q -a --qf '%{NAME}\t%{ARCH}\t%{VERSION}\t%{RELEASE}\n' | sort > /tmp/rpm-qa.lst
Then extract YUM's list (using repoquery which is part of package yum-utils:
$ repoquery -q -a --installed --qf '%{NAME}\t%{ARCH}\t%{VERSION}\t%{RELEASE}' | sort > /tmp/repo-qa.lst
Then compare:
$ diff -u0 /tmp/rpm-qa.lst /tmp/repo-qa.lst
--- /tmp/rpm-qa.lst 2015-03-08 16:07:38.297325253 +0100
+++ /tmp/repo-qa.lst 2015-03-08 16:07:43.281438369 +0100
## -143,1 +142,0 ##
-gpg-pubkey (none) 352c64e5 52ae6884
(See also question https://unix.stackexchange.com/q/190203/16640)
Both commands works in the same way only difference is 'yum list installed' output maybe bigger than 'rpm -qa' because yum will show package dependencies also in its output.
While installing a package using rpm, we need to manually install the dependencies whereas yum will do that automatically. So in this case if you want to list the packages only use, 'rpm -qa' or if you need to list all the packages and dependencies associated with it use 'yum list installed'
Related
There are plenty of perl packages missing in Centos 8 and Rocky Linux. So, I try to get the rpm spec by cpanspec and build rpm by myself. But, it seems like that rpmbuild could not find the rpm I built.
This is the script for me to build rpm.
cd /root/rpmbuild
cpanspec --packer 'Example <example#example.com>' <Perl-Package-Name>
mkdir SOURCES
cp <Perl-Package-Name>.tar.gz SOURCES
rpmbuild -ba perl-<Package-Name>.spec
Let's say we have two package A and B. A is needed by B.
I try to build both of the packages through the script above. I build A first, switch into /root/rpmbuild/RPMS/noarch and install A.rpm. Then, I try to build package B.
I got
error: Failed build dependencies:
perl(A) is needed by perl-<B>
I try to check the existence of package A.
yum list installed | grep A
and
perldoc -l A
Both of the commands show that A exists.
Did I miss something?
update 2022/06/07
I just gave up and commented the BuildRequires: A in B package. This is not a good approach but it works.
At present time Devtoolset-5 (and earlier) cannot be istalled from Software Collection Repository (centos-release-scl) using yum (only Devtoolset-6 and 7 are available). Nevertheless, this collection can be downloaded as a list of rpm-packages. Is it possible to enable such EOL collections for yum, or maybe there is another way to install them correctly?
There was no DTS 5 release. It was skipped to align the DTS version with the GCC major release, once GCC switched to a yearly increasing version number.
DTS versions 3 and 4 are available from the centos-release-scl repository.
While Devtoolset-3 and 4 are located on the Centos mirror site, yum will not be able to find them as they were not included in the repodata on the site. These were probably excluded because they are EOL (end-of-life), and have dependency bugs (Bug 1410152). Try using the older Devtoolset-3 packages here, which do not have the dependency issues:
https://copr.fedorainfracloud.org/coprs/rhscl/devtoolset-3/
If you really want the packages from the centos.org site, I went with wget to download all the RPMs, then recreated a local yum repo. However, you'll see the dependency issues and yum install devtoolset-3 will fail.
$ wget -r -p -e robots=off --directory-prefix="/mnt/local-devtoolset3-repo" --recursive --no-clobber --no-parent http://mirror.centos.org/centos/6/sclo/x86_64/rh/devtoolset-3/
$ sudo yum install createrepo
$ cd /mnt/local-devtoolset3-repo
$ createrepo --database .
You can install the obsolete devtoolset-3 in this way:
sudo yum --obsolete install devtoolset-3
When I try running yum update on a CentOS 6.3 box, I am getting errors, and says to run yum check. The output of yum check is:
➜ ~ yum check
Loaded plugins: fastestmirror
glibc-2.12-1.107.el6_4.5.x86_64 is a duplicate with glibc-2.12-1.107.el6_4.4.x86_64
glibc-common-2.12-1.107.el6_4.5.x86_64 is a duplicate with glibc-common-2.12-1.107.el6_4.4.x86_64
glibc-devel-2.12-1.107.el6_4.5.x86_64 is a duplicate with glibc-devel-2.12-1.107.el6_4.4.x86_64
glibc-devel-2.12-1.107.el6_4.5.x86_64 has missing requires of glibc-headers = ('0', '2.12', '1.107.el6_4.5')
iputils-20071127-17.el6_4.2.x86_64 is a duplicate with iputils-20071127-17.el6_4.x86_64
nspr-4.9.5-2.el6_4.x86_64 is a duplicate with nspr-4.9.2-1.el6.x86_64
nss-3.14.3-4.el6_4.x86_64 is a duplicate with nss-3.14.0.0-12.el6.x86_64
nss-softokn-3.14.3-3.el6_4.x86_64 is a duplicate with nss-softokn-3.12.9-11.el6.x86_64
nss-util-3.14.3-3.el6_4.x86_64 is a duplicate with nss-util-3.14.0.0-2.el6.x86_64
tzdata-2013g-1.el6.noarch is a duplicate with tzdata-2013c-2.el6.noarch
2:xinetd-2.3.14-39.el6_4.x86_64 is a duplicate with 2:xinetd-2.3.14-38.el6.x86_64
Error: check all
Any idea how to fix these packages? I tried yum reinstall xinetd tzdata nss-util nss-softokn nss nspr iputils glibc glibc-common glibc-devel but got:
Error: Multilib version problems found. This often means that the
root
cause is something else and multilib version checking is just
pointing out that there is a problem.
For me it looks like you rebooted your computer (or it crashed) while you where in the process of upgrading packages. So new packages where installed, but old packages where not removed.
First look if you have any uncomplete transactions with: yum-complete-transaction
If this doesn't help then take a look at the package-cleanup tool which is part of the yum-utils package.
package-cleanup --dupes lists duplicate packages
package-cleanup --cleandupes removes duplicate packages
But be carefull with the command and create a backup before removing duplicates.
This is the way I did fix one CentOS 7 server with 471 dupes.
First I had to install yum utils:
yum install yum-utils
Have tried yum-complete-transaction and other stuff without luck, I gave up the transaction with:
yum-complete-transaction --cleanup-only
Then I got a sorted list of duplicated packages so I could identify older versions to remove filtering even and odd lines later:
package-cleanup --dupes | sort -u > dupes.out
Then I got a uninstall list from this sorted file this way:
cat dupes.out | grep -v 'Loaded plugins:' | sort -u | awk 'NR % 2 == 1' > uninstall.in
Then I removed from rpm database the old versions:
for f in `cat uninstall.in`; do rpm -e --nodeps -f --justdb $f; done
Finally I could continue on regular system upgrade:
yum upgrade
Some things to pay attention:
On this case, I have carefully reviewed the "package-cleanup --dupes" output to make sure how to generate the uninstall list.
I have tried a "reinstall the newer" approach inverting the list (awk 'NR % 2 == 0') but there where lots of packages not available anymore at that version (server was left this way for an year).
I thought about removing from rpmdb the newer packages, so upgrade later should reinstall everything, but after checking on filesystem installed files, it was clear for me that new versions were in place, with only older rpm entries still in rpmdb. Maybe your case is different.
I was able to remove all duplicates by using yum shell:
I first ordered it to remove all packages using remove foo-package-*
Then order it to install previous version by specifying the exact version install foo-package-3.14.1-5.i386 foo-package-3.14.1-5.x86_64
Committing the transaction by run
After that, the duplicates were gone and I could update the system to current packages without problem and without introducing any new duplicates.
This works even for system packages like nss or yum.
Try running:
yum reinstall [package-new.version]
It is mean, if you get the output of yum check is:
# yum check
Loaded plugins: fastestmirror
nss-3.14.3-4.el6_4.x86_64 is a duplicate with nss-3.14.0.0-12.el6.x86_64
Do reinstall:
yum reinstall nss-3.14.3-4.el6_4.x86_64
A minor upgrade was interrupted by SSH disconnection. After handholding a few packages while trying to get other fixes to work, I ended up fixing the rest like so:
sudo yum reinstall --skip-broken $(/usr/bin/package-cleanup --dupes -q |sort)
First install yum utils and run cleanup afterwards to remove old duplicated packages
yum install yum-utils &&
package-cleanup –-cleandupes -y
hint:
sometimes you need to run package-cleanup –-cleandupes few times
A couple of months ago I also ran into this problem after upgrading my fedora.
I also tried the package-cleanup utility and it started removing required libs rendering my workstation unworkable. Luckily I could reinstall Fedora not deleting my home partition.
Yesterday the same problem occured and I fixed it removing the older version of the duplicate.
For example:
I got these duplicates:
oxygen-icon-theme-4.8.3-1.fc16.noarch is a duplicate with oxygen-icon-theme-4.8.2-1.fc16.noarch
sane-backends-libs-1.0.22-10.fc16.i686 is a duplicate with sane-backends-libs-1.0.22-8.fc16.i686
What I did is I used the yum remove sane-backends-libs-1.0.22-8.fc16.i686 and afterwards a yum update.
Everything is now working fine.
from http://forums.fedoraforum.org/showthread.php?t=268328
In my case nothing above has worked.
So after having the Duplicates list, I copied it to a Text Editor ...
And i did
yum upgrade {package name}
As I edited the whole list, I did it continuously ...
Example: yum upgrade sudo nano came mariadb, etc ...
what worked for me is :
1) getting the list of duplicated packages : package-cleanup --dupes
2) deleting manually old duplicates : rpm -e --justdb --nodeps {old-version-duplicated-package}
3) yum update
I am writing a post-install script for Ubuntu in Perl (same script as seen here). One of the steps is to install a list of packages. The problem is that if apt-get install fails in some of many different ways for any one of the packages the script dies badly. I would like to prevent that from happening.
This happens because of the ways that apt-get install fails for packages that it doesn't like. For example when I try to install a nonsense word (i.e. typed in the wrong package name)
$ sudo apt-get install oblihbyvl
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package oblihbyvl
but if instead the package name has been obsoleted (installing handbrake from ppa)
$ sudo apt-get install handbrake
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package handbrake is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'handbrake' has no installation candidate
$ apt-cache search handbrake
handbrake-cli - versatile DVD ripper and video transcoder - command line
handbrake-gtk - versatile DVD ripper and video transcoder - GTK GUI
etc, etc ...
I have tried parsing the results of apt-cache and apt-get -s install to try to catch all possibilities before doing the install, but I seem to keep finding new ways to allow failures to continue to the actual install system command.
My question is, is there some facility either in Perl (e.g. a module, though I would like to avoid installing modules if possible as this is supposed to be the first thing run after a new install of Ubuntu) or apt-* or dpkg that would let me be sure that the packages are all available to be installed before installing and if not fail gracefully in some way that lets the user decide what to do?
N.B. I am doing something along the lines of:
my #list_of_install_candidates = (...);
my #to_install = grep { my $output = qx{ apt-get -s install $_ }; parse_output($output); } #list_of_install_candidates;
system('apt-get', 'install', #to_install);
You might try apt-cache policy. examples:
$ apt-cache policy handbrake
handbrake:
Installed: (none)
Candidate: (none)
Version table:
$ apt-cache policy foo
N: Unable to locate package foo
$ apt-cache policy openbox
openbox:
Installed: 3.4.11.1-1
Candidate: 3.4.11.1-1
Version table:
*** 3.4.11.1-1 0
500 http://mirrors.xmission.com/ubuntu/ maverick/universe i386 Packages
100 /var/lib/dpkg/status
Anything with a non-blank version table should be installable.
As an example, I am looking for a mod_files.sh file which presumably would come with the php-devel package. I guessed that yum would install the mod_files.sh file with the php-devel x86_64 5.1.6-23.2.el5_3 package, but the file appears to not to be installed on my filesystem.
How do I find out which package installs a specific file? I'm looking for where I have not necessarily already locally downloaded the package which may include the file that I'm looking for.
I'm using CentOS 5.
This is an old question, but the current answers are incorrect :)
Use yum whatprovides, with the absolute path to the file you want (which may be wildcarded). For example:
yum whatprovides '*bin/grep'
Returns
grep-2.5.1-55.el5.x86_64 : The GNU versions of grep pattern matching utilities.
Repo : base
Matched from:
Filename : /bin/grep
You may prefer the output and speed of the repoquery tool, available in the yum-utils package.
sudo yum install yum-utils
repoquery --whatprovides '*bin/grep'
grep-0:2.5.1-55.el5.x86_64
grep-0:2.5.1-55.el5.x86_64
repoquery can do other queries such as listing package contents, dependencies, reverse-dependencies, etc.
To know the package owning (or providing) an already installed file:
rpm -qf myfilename
The most popular answer is incomplete:
Since this search will generally be performed only for files from installed packages, yum whatprovides is made blisteringly fast by disabling all external repos (the implicit "installed" repo can't be disabled).
yum --disablerepo=* whatprovides <file>
You go to http://www.rpmfind.net and search for the file.
You'll get results for a lot of different distros and versions, but quite likely Fedora and/or CentOS will pop up too and you'll know the package name to install with yum
Well finding the package when you are connected to internet (repository) is easy however when you only have access to RPM packages inside Redhat or Centos DVD (this happens frequently to me when I have to recover a server and I need an application) I recommend using the commands below which is completely independent of internet and repositories. (supposably you have lots of uninstalled packages in a DVD).
Let's say you have mounted Package folder in ~/cent_os_dvd and you are looking for a package that provides "semanage" then you can run:
for file in `find ~/cent_os_dvd/ -iname '*.rpm'`; do rpm -qlp $file |grep '.*bin/semanage'; if [ $? -eq 0 ]; then echo "is in";echo $file ; fi; done
Using only the rpm utility, this should work in any OS that has rpm:
rpm -q --whatprovides [file name]
Ref. https://www.thegeekdiary.com/how-to-find-which-rpm-package-provides-a-specific-file-or-library-in-rhel-centos/
You can do this alike here but with your package. In my case, it was lsb_release
Run: yum whatprovides lsb_release
Response:
redhat-lsb-core-4.1-24.el7.i686 : LSB Core module support
Repo : rhel-7-server-rpms
Matched from:
Filename : /usr/bin/lsb_release
redhat-lsb-core-4.1-24.el7.x86_64 : LSB Core module support
Repo : rhel-7-server-rpms
Matched from:
Filename : /usr/bin/lsb_release
redhat-lsb-core-4.1-27.el7.i686 : LSB Core module support
Repo : rhel-7-server-rpms
Matched from:
Filename : /usr/bin/lsb_release
redhat-lsb-core-4.1-27.el7.x86_64 : LSB Core module support
Repo : rhel-7-server-rpms
Matched from:
Filename : /usr/bin/lsb_release`
Run to install: yum install redhat-lsb-core
The package name SHOULD be without number and system type so yum packager can choose what is best for him.