Unable to Install RPM's from a Text File
I have a text file that contains a list of RPM's that my RHEL 6.7 servers should match.
So I would like to install any RPM's in the text file that are not already installed on my server.
A web search found the following command that should work.
yum -y install $(cat file_name)
When I run the command, I get a list of all the RPM's with 'available.' in front.
Then it finishes with 'Error: Nothing to do'
If I run the yum command with a single RPM listed. It will install, but no luck using the text file.
How do I get the RPM's to install from the text file?
Responses
It can be done in other way using a loop condition as shown using 'for' command
for i in $(cat file_name);do yum install $i -y;done
Package names should be lined up one above another in that file.
I've done this, and it works. If it is a new system, doing the requisite "rpm --import /etc/pki/rpm-gpg/*" prior helps as well (I've found from my own experience)
If you are sending that out to a bunch of systems, you might want to add a redirect of the output to some file so you can see if it failed for something unanticipated.
Oof... That's brutal: you're firing off a yum process for each RPM in your list. That might be ok if your list is really small, but as the file grows, it becomes more and more punishing to your system. As a further bad side-effect, it's a really great way to crap up your yum history db.
If you want to install from the contents of a file - and don't want one yum invocation per item in the file - you can do something like yum install -y $(awk '{printf("%s ",$1)}' rpm.lst) instead (where rpm.lst is your text-file containing your desired RPMs). There's a few other ways to do it, too, obviously - that's just the first off the top of my head.
I agree with Tom. As I mentioned in my earlier post, I think looping through a file of packages spawns a lot of unnecessary yum processes. The example given by Tom is far better for the given reasons.
@Mark I tried the command you mentioned in your starting post. This works for me just fine:
echo tmux >packages.lst
echo clustershell >>packages.lst
yum install $(cat packages.lst)
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
Resolving Dependencies
--> Running transaction check
---> Package clustershell.noarch 0:1.7.3-1.el7 will be installed
---> Package tmux.x86_64 0:1.8-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
clustershell noarch 1.7.3-1.el7 epel 365 k
tmux x86_64 1.8-4.el7 rhel-7-server-rpms 243 k
Transaction Summary
================================================================================
Install 2 Packages
Total download size: 608 k
Installed size: 2.2 M
Is this ok [y/d/N]: N
Exiting on user command
Your transaction was saved, rerun it with:
yum load-transaction /tmp/yum_save_tx.2017-02-11.13-49.QSzpn3.yumtx
As you could see, yum reads the contents of the file and is going to install the packages. So your command should have worked unless you did something different.
Yes, agree with Tom. Instead of spawning multiple yum threads, it would be technically valid point to trigger one yum call with whatever packages to be installed.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
