yum 更新如果安装,否则安装

Joh*_*nal 1 redhat centos yum update packages

是否有一个命令可以做到这一点:如果一个包已经安装,更新它,否则安装最新版本

现在我正在执行两个命令:

yum install mypackage
yum update mypackage
Run Code Online (Sandbox Code Playgroud)

也许有更有效的方法?

Mad*_*ter 6

至少对我来说,yum它足够聪明,如果我告诉它安装已经安装的东西,并且有可用的更新,它只会应用更新。例如:

[root@risby ~]# rpm -qa|grep openvpn
openvpn-2.2.2-7.fc17.x86_64
Run Code Online (Sandbox Code Playgroud)

安装了 openvpn。

[root@risby ~]# yum update
[...]
--> Running transaction check
---> Package openvpn.x86_64 0:2.2.2-7.fc17 will be updated
---> Package openvpn.x86_64 0:2.3.1-2.fc17 will be an update
Run Code Online (Sandbox Code Playgroud)

有可用的更新。

[root@risby ~]# yum install openvpn
[...]
--> Running transaction check
---> Package openvpn.x86_64 0:2.2.2-7.fc17 will be updated
---> Package openvpn.x86_64 0:2.3.1-2.fc17 will be an update
Run Code Online (Sandbox Code Playgroud)

yum install无论如何都做正确的事。顺便说一下,yum 版本是 3.4.3。