Is there a way to add and remove packages at the same time with a single yum command? For example, installing postfix and removing sendmail without running two separate commands/transactions.

  • Not to my knowledge, but I'm not a daily yum user. Why do you want it in a single command? – jippie Jun 2 '12 at 16:39
  • @jippie Convenience, mostly. And reducing the time to set up multiple transactions. – Michael Ekstrand Jun 2 '12 at 16:43

Yes. Invoking yum shell will allow you to specify multiple commands that will happen simultaneously when run is entered.

  • 2
    Awesome, this is exactly what I was looking for. – Michael Ekstrand Jun 2 '12 at 20:01
  • 1
    I had originally been using Python for this. I've now cut my script down to about 20% the size by using BASH! – quickshiftin Mar 17 '14 at 18:38
  • Learned something new. Thank you, – nullnv0id Apr 20 '20 at 0:36

Newer versions of yum also have the swap command:

# yum swap -- install foo -- remove bar
  • 1
    At least as of now (yum on RHEL 7), this can also be written shorter as yum swap bar foo. – Axel Beckert Jun 25 '18 at 16:44

As the accepted answer already says, you can use yum shell to run multiple commands at once, which is fine for interactive use. But if you want to invoke this command from a script, you can also run it against a file, eg yum shell translist.txt, where the file could contain, for example:

remove squid
install squid34

Append the -y switch to assume yes to confirmation prompts.

  • 1
    The -y switch gets appended to the yum shell command, not to commands within the shell, right? I think (but have not tested) that adding config assumeyes 1 to the top of the shell commands will have the same effect without needing to change the initial command line. – mattdm Jun 19 '18 at 13:43
  • yes, yum shell -y works for me to make the whole operation non-interactive. – RubyTuesdayDONO Dec 6 '19 at 21:47
sudo yum swap postfix sendmail

Although the O/P has his answer, I'm leaving this short one for people who need this in the future

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.