14

I have an existing CentOS installation which I'd like to install extra packages to. The packages to be installed were supplied to me in a list, one package per line, which looks like:

....
Cluster_Administration-en-US.noarch
ElectricFence.x86_64
GConf2.i386
GConf2.x86_64
GConf2-devel.i386
GConf2-devel.x86_64
Global_File_System-en-US.noarch
ImageMagick.i386
...

Using this text file, is there a way to install every package listed? I suspect the list is actually a list of 'all' packages which could have been installed when the operating system was originally set up.

25

Yes, do this:

yum -y install $(cat file_name)

  • This is much nicer, as it will look at all the dependencies at the same time, instead of figuring them out for every single package. – Marcin Sep 6 '12 at 14:01
  • yes, that's true. – tugboat Sep 7 '12 at 13:52
  • This is a really old question, but this certainly helped me. If you have a file with the packages separated by line feeds, you name need to do the following: yum -y install $(cat filename cat | tr '\n' ' ') – SteveM Dec 30 '14 at 21:23
  • Wow. So simple I could only google it instead of think of it myself. – bgStack15 Dec 14 '15 at 20:42
  • 2
    Alas this won't work too well if the list of packages exceeds the command line maximum length. – Chris Cogdon Jun 20 '17 at 21:42
3

Try with xargs:

cat textfile | xargs yum -y install

 

  • 1
    There is nothing to concatenate - thus, < textfile xargs yum -y install is equivalent and saves a fork/exec. – maxschlepzig Jul 8 '17 at 11:55
0

You can also try this in command line.

for i in `cat textfile` ; do yum -y install $i; done

For every i in textfile, it does a yum -y install.

  • 2
    as Mafcin stated above this will do dependency check on every package ie. for each line. – tugboat Sep 7 '12 at 13:54
0

cat YOURFILE | xargs yum -y install

This is almost the same as @daisy's solution, except that if the list of packages is too long for the command line, it will break it up into separate yum install commands.

  • This duplicates @JucaPirama's answer - which was posted 1 year earlier. – maxschlepzig Jul 8 '17 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.