24

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.

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

4 Answers 4

27

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

0
24

Newer versions of yum also have the swap command:

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

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
run

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

2
  • 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, 2018 at 13:43
  • yes, yum shell -y works for me to make the whole operation non-interactive. Dec 6, 2019 at 21:47
2
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.