当前位置: 首页>>技术教程>>正文


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

, ,

问题描述

我如何更新单个软件包?至于man apt-get表示apt-get upgrade不会将软件包/软件包列表作为参数:

upgrade

upgrade is used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list. Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. An update must be performed first so that apt-get knows that new versions of packages are available.

最佳解决办法

你只需要做apt-get install --only-upgrade <packagename>。这将仅升级该单个软件包,并且仅在已安装时才升级。

如果您希望在不存在该软件包的情况下安装该软件包,或者如果该软件包进行了升级,则可以省略--only-upgrade

次佳解决办法

为了使用CLI更新单个软件包:

sudo apt-get install --only-upgrade <packagename>

例如sudo apt-get install --only-upgrade ack

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Skipping **ack**, it is not installed and only upgrades are requested.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

第三种解决办法

我可以想到两种可能的方式:

  1. sudo apt-get install nameofpackage

    即使已经安装,这将升级包:

    ~$ sudo apt-get install emesene
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following packages will be upgraded:
      emesene
    1 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
    Need to get 1,486 kB of archives.
    After this operation, 696 kB disk space will be freed.
    Get:1 http://il.archive.ubuntu.com/ubuntu/ natty-updates/universe emesene all 2.11.4+dfsg-0ubuntu1 [1,486 kB]
    
  2. 使用Synaptic Package Manager:右键单击→标记以进行升级:注意:有时它可能会要求额外的软件包或依赖项,这是正常的。

    apt,upgrade,ubuntu

第四种办法

根据我在Ubuntu 12.04 LTS上的经验,如果使用单独的PPA,使用下面的命令不会升级软件包 –

sudo apt-get --only-upgrade install <packagename>

同样,我不想运行升级命令,它会升级服务器上的所有软件包 –

sudo apt-get dist-upgrade

例如,我安装了PHP 5.3,并已将ondrej PPA添加到我的apt.sources中,方法是使用 –

sudo add-apt-repository ppa:ondrej/php5

如果我跑步

sudo apt-get install php5

它只会重新安装PHP 5.3。

我必须首先确定要升级到的版本号

sudo apt-cache policy php5

这将列出所有可用的版本号。您应该找到要升级到的版本号,然后复制引用它的整个字符串。例如,Ubuntu上PHP 5.5的字符串是“5.5.16 + dfsg-1 + deb.sury.org〜precise + 2”。

现在,您可以运行带有特定版本号的apt-get安装命令,瞧!

sudo apt-get install php5=5.5.16+dfsg-1+deb.sury.org~precise+2

我只是添加了这个,因为我无法在其他地方找到这些信息!

第五种办法

在Ubuntu 9.04 Jaunty上,

apt-get --only-upgrade install <package>

收益率:

E: Sense only is not understood, try true or false.

命令

apt-get --only-upgrade true install <package>

在我的情况下工作。

第六种办法

对于如果命令行解决方案尚不存在的情况下不安装它的命令行解决方案:

dpkg -s <package> 2>/dev/null | grep -q Status.*installed && sudo apt-get install <package>

这可以很容易地制成一个脚本,例如:

upgrade-package.sh:

#!/bin/bash

[[ -z $1 ]] && { echo "Usage: $(basename $0) package"; exit 1; }

if dpkg -s "$1" 2>/dev/null | grep -q Status.*installed; then
    echo "Attempting to upgrade $1"
    sudo apt-get install "$1"
else
    echo "Package $1 is not installed"
fi

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/13.html,未经允许,请勿转载。