Ubuntu使用apt-get升级或者更新单个软件包

时间:2020-01-09 10:45:41  来源:igfitidea点击:

如何使用apt-get命令或者apt命令升级或者更新单个软件包。
如何在Ubuntu Linux中更新特定的软件包?
如何使用apt-get升级单个软件包?

说明:默认情况下,当您运行apt-get升级或者apt升级时,Ubuntu将更新所有已安装的软件包。
但是,在某些情况下,您可能只想升级特定的软件包,例如Apache或者Nginx。
也可以将Ubuntu Linux上的升级包列入黑名单。
作为Ubuntu Linux系统管理员,您可以完全控制程序包管理。

如何Ubuntu升级或者更新单个软件包

在Ubuntu上更新特定软件包的过程:

  • 打开终端应用程序
  • 通过运行sudo apt update命令获取软件包索引
  • 现在仅通过运行sudo apt install apache2命令更新apache2软件包。
  • 如果已经安装了apache2软件包,它将尝试更新到最新版本。如果您不想安装新软件包;与install结合使用时,only-upgrade将仅安装已安装软件包的升级,而忽略安装新软件包的请求。尝试sudo apt --only-upgrade install apache2

让我们详细查看所有命令和示例。

如何使用apt-get升级单个软件包?

与往常一样,您需要从Internet上获取更新的索引:

$ sudo apt-get update

您需要在apt-get命令/apt命令中使用以下格式:

$ sudo apt-get --only-upgrade install Package
$ sudo apt-get install Package

让我们尝试升级Nginx Web服务器:

$ sudo apt-get install nginx

如果已经安装了nginx软件包,它将尝试更新到最新版本:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
nginx is already the newest version (1.10.3-0ubuntu0.16.04.2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

但是,如果未安装以下内容,则不会安装新的nginx软件包:

$ sudo apt-get --only-upgrade install nginx

在下面的示例中,安装了htop,并且我请求更新。
但是,尚未安装,我仍在请求更新:

$ sudo apt-get install htop
$ sudo apt-get --only-upgrade install atop

例子

首先,从所有配置的源下载软件包信息:

$ sudo apt-get update

运行查看可用更新:

$ sudo apt list --upgradable
Listing... Done
apport-gtk/focal-security,focal-security 2.20.11-0ubuntu27.6 all [upgradable from: 2.20.11-0ubuntu27.4]
apport/focal-security,focal-security 2.20.11-0ubuntu27.6 all [upgradable from: 2.20.11-0ubuntu27.4]
libssh-4/focal-updates,focal-security 0.9.3-2ubuntu2.1 amd64 [upgradable from: 0.9.3-2ubuntu2]
libssh-gcrypt-4/focal-updates,focal-security 0.9.3-2ubuntu2.1 amd64 [upgradable from: 0.9.3-2ubuntu2]
libwhoopsie0/focal-security 0.2.69ubuntu0.1 amd64 [upgradable from: 0.2.69]
ppp/focal-security 2.4.7-2+4.1ubuntu5.1 amd64 [upgradable from: 2.4.7-2+4.1ubuntu5]
python3-apport/focal-security,focal-security 2.20.11-0ubuntu27.6 all [upgradable from: 2.20.11-0ubuntu27.4]
python3-problem-report/focal-security,focal-security 2.20.11-0ubuntu27.6 all [upgradable from: 2.20.11-0ubuntu27.4]
whoopsie/focal-security 0.2.69ubuntu0.1 amd64 [upgradable from: 0.2.69]

我们有9个更新可用,但我们将要更新ppp软件包:

$ sudo apt-get --only-upgrade install ppp
## 或者
$ sudo apt --only-upgrade install ppp
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  ppp
1 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Need to get 328 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://security.ubuntu.com/ubuntu focal-security/main amd64 ppp amd64 2.4.7-2+4.1ubuntu5.1 [328 kB]
Fetched 199 kB in 2s (123 kB/s)
(Reading database ... 288234 files and directories currently installed.)
Preparing to unpack .../ppp_2.4.7-2+4.1ubuntu5.1_amd64.deb ...
Unpacking ppp (2.4.7-2+4.1ubuntu5.1) over (2.4.7-2+4.1ubuntu5) ...
Setting up ppp (2.4.7-2+4.1ubuntu5.1) ...
Processing triggers for systemd (245.4-4ubuntu3.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...