阻止特定軟件包的三種方法

從 apt 升級中排除/保留/阻止特定軟件包的三種方法

有時,由於某些應用依賴性,你可能會意外更新不想更新的軟件包。-- Magesh Maruthamuthu(作者)

有時,由於某些應用依賴性,你可能會意外更新不想更新的軟件包。這在全系統更新或自動包升級時經常會發生。如果發生這種情況,可能會破壞應用的功能。這會造成嚴重的問題,你需要花費大量時間來解決問題。

如何避免這種情況?如何從 apt-get 更新中排除軟件包?

如果你要 從 Yum Update 中排除特定軟件包 ,請參考這篇。

是的,可以在 Debian 和 Ubuntu 系統上使用以下三種方法來完成。

  • apt-mark 命令
  • dpkg 命令
  • aptitude 命令

我們將分別詳細展示。

方法 1:如何使用 apt-mark 命令排除 Debian/Ubuntu 系統上的軟件包更新

apt-mark 用於將軟件包標記/取消標記為自動安裝。

hold 選項用於將軟件包標記為保留,以防止軟件包被自動安裝、升級或刪除。

unhold 選項用於取消先前面的設置,以允許重複執行所有操作。

運行以下命令以使用 apt-mark 命令保留指定的軟件包。

<code>$ sudo apt-mark hold nano
nano set on hold./<code>

保留軟件包後,請運行以下 apt-mark 命令查看它們。

<code>$ sudo apt-mark showhold
nano/<code>

這表明在執行完整的系統更新時,不會升級 nano 包。

<code>$ sudo apt update

Reading package lists… Done
Building dependency tree
Reading state information… Done
Calculating upgrade… Done
The following packages have been kept back:
  nano
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded./<code>

運行以下命令,使用 apt-mark 命令取消保留 nano 包。

<code>$ sudo apt-mark unhold nano
Canceled hold on nano./<code>

方法 2:如何使用 dpkg 命令在 Debian/Ubuntu 系統上排除軟件包更新

dpkg 命令是一個 CLI 工具,用於安裝、構建、刪除和管理 Debian 軟件包。dpkg 的主要且更用戶友好的前端是 aptitude。

運行以下命令使用 dpkg 命令阻止給定的軟件包。

語法:

<code>$ echo "package_name hold" | sudo dpkg --set-selections/<code>

運行以下 dpkg 命令以保留 apache2 包。

<code>$ echo "apache2 hold" | sudo dpkg --set-selections/<code>

保留軟件包後,請運行以下命令查看它們。

<code>$ sudo dpkg --get-selections | grep "hold"
apache2                        hold/<code>

它會顯示在執行完整的系統更新時,不會升級 apache2包。

<code>$ sudo apt update

Reading package lists… Done
Building dependency tree
Reading state information… Done
Calculating upgrade… Done
The following packages have been kept back:
  apache2
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded./<code>

運行以下命令,使用 dpkg 命令取消對指定軟件包的保留。

語法:

<code>$ echo "package_name install" | sudo dpkg --set-selections/<code>

運行以下命令,使用 dpkg 命令取消保留 apache2 包。

<code>$ echo "apache2 install" | sudo dpkg --set-selections/<code>

方法 3:如何使用 aptitude 命令排除 Debian/Ubuntu 系統上的軟件包更新

aptitude 命令是 Debian 及其衍生版本的基於文​​本的軟件包管理界面。

它允許用戶查看軟件包列表並執行軟件包管理任務,例如安裝、升級和刪除軟件包。它可以從可視界面或命令行執行操作。

運行以下命令,使用 aptitude 命令保留指定的軟件包。

<code>$ sudo aptitude hold python3/<code>

保留某些軟件包後,請運行以下命令查看它們。

<code>$ sudo dpkg --get-selections | grep "hold"
或者
$ sudo apt-mark showhold

python3/<code>

這表明在執行完整的系統更新時,不會升級 python3 軟件包。

<code>$ sudo apt update

Reading package lists… Done
Building dependency tree
Reading state information… Done
Calculating upgrade… Done
The following packages have been kept back:
  python3
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded./<code>

使用 aptitude 命令運行以下命令以解除對 python3 軟件包的保留。

<code>$ sudo aptitude unhold python3/<code>

via: https://www.2daygeek.com/debian-ubuntu-exclude-hold-prevent-packages-from-apt-get-upgrade/

作者: Magesh Maruthamuthu 選題: lujun9972 譯者: geekpi 校對: wxy

本文由 LCTT 原創編譯, Linux中國 榮譽推出


分享到:


相關文章: