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
-
1I 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
-
Newer versions of yum also have the swap
command:
# yum swap -- install foo -- remove bar
-
1At least as of now (
yum
on RHEL 7), this can also be written shorter asyum 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
run
Append the -y
switch to assume yes to confirmation prompts.
-
1The
-y
switch gets appended to theyum shell
command, not to commands within the shell, right? I think (but have not tested) that addingconfig 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