2023-02-22 08:44:08 +08:00
|
|
|
|
[#]: subject: "Downgrading a Package via apt-get"
|
|
|
|
|
[#]: via: "https://itsfoss.com/downgrade-apt-package/"
|
|
|
|
|
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
|
|
|
|
|
[#]: collector: "lkxed"
|
|
|
|
|
[#]: translator: "geekpi"
|
2023-02-27 12:04:04 +08:00
|
|
|
|
[#]: reviewer: "wxy"
|
|
|
|
|
[#]: publisher: "wxy"
|
|
|
|
|
[#]: url: "https://linux.cn/article-15580-1.html"
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
|
|
|
|
通过 apt-get 降级一个软件包
|
|
|
|
|
======
|
|
|
|
|
|
2023-02-27 12:04:04 +08:00
|
|
|
|
![][0]
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
2023-02-27 12:04:04 +08:00
|
|
|
|
最近升级的软件引起问题了?虽然你总是可以调查问题以解决它,但有时,回到以前的工作版本可以节省时间和精力。如果新的版本引入了一个 bug,你可以在你这一边什么都不做,对吗?
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
|
|
|
|
好消息是,你可以在 Ubuntu 和 Debian 中轻松地降级 apt 软件包。
|
|
|
|
|
|
2023-02-27 12:04:04 +08:00
|
|
|
|
你所要做的就是像这样使用 `apt` 命令:
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo apt install package_name=package-version-number
|
|
|
|
|
```
|
|
|
|
|
|
2023-02-27 12:04:04 +08:00
|
|
|
|
这似乎很容易,但你如何获得确切的版本号?还有哪些旧版本被支持?你可以通过以下方式获得这个细节:
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo apt-cache policy package_name
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
让我用一个现实生活中的例子来解释这些。
|
|
|
|
|
|
|
|
|
|
### 降级 apt 包
|
|
|
|
|
|
|
|
|
|
最近,我正在更新承载 It's FOSS 社区论坛的 Ubuntu 服务器。
|
|
|
|
|
|
2023-02-27 12:04:04 +08:00
|
|
|
|
我做了通常的 `apt update && apt upgrade`,在更新安装时,事情变得糟糕。
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
|
|
|
|
很明显,最新版本的 Docker 不支持 aufs 存储驱动。为了减少停机时间,我选择了降级到以前的 Docker 版本。
|
|
|
|
|
|
2023-02-27 12:04:04 +08:00
|
|
|
|
检查当前安装的软件包版本:
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
|
|
|
|
![Installed Docker version][1]
|
|
|
|
|
|
|
|
|
|
然后检查可以安装的可用版本:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo apt-cache policy package_name
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
它可能会抛出一个巨大的列表,或者只是一个小列表:
|
|
|
|
|
|
|
|
|
|
![All installable versions of an apt package][2]
|
|
|
|
|
|
|
|
|
|
如果它显示至少有一个比当前版本更早的版本,你就很幸运了。
|
|
|
|
|
|
|
|
|
|
现在,你可能认为一个软件包的版本号将只由数字组成。但情况可能并不总是这样。
|
|
|
|
|
|
|
|
|
|
基本上,你复制 500(优先级数字)之前的全部内容。
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
brave-browser:
|
|
|
|
|
Installed: 1.48.158
|
|
|
|
|
Candidate: 1.48.164
|
|
|
|
|
Version table:
|
|
|
|
|
1.48.164 500
|
|
|
|
|
500 https://brave-browser-apt-release.s3.brave.com stable/main amd64 Packages
|
|
|
|
|
*** 1.48.158 500
|
|
|
|
|
500 https://brave-browser-apt-release.s3.brave.com stable/main amd64 Packages
|
|
|
|
|
100 /var/lib/dpkg/status
|
|
|
|
|
1.47.186 500
|
|
|
|
|
500 https://brave-browser-apt-release.s3.brave.com stable/main amd64 Packages
|
|
|
|
|
1.47.171 500
|
|
|
|
|
500 https://brave-browser-apt-release.s3.brave.com stable/main amd64 Packages
|
|
|
|
|
1.46.153 500
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
当你得到了软件包的编号,用它来降级已安装的软件包,像这样:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo apt install package_name=package-version-number
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![Downgrading an installed package via apt-get command][3]
|
|
|
|
|
|
|
|
|
|
当然,你会看到一个关于降级软件包的警告。
|
|
|
|
|
|
|
|
|
|
![Downgrading apt package][4]
|
|
|
|
|
|
|
|
|
|
但是当这个过程完成,你的软件包就会被降级到给定的旧版本。
|
|
|
|
|
|
2023-02-27 12:04:04 +08:00
|
|
|
|
### 所以,也许要保留它?
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
|
|
|
|
所以,你刚刚学会了降级 apt 软件包。但如果你不注意的话,该软件包会在下一次系统更新时再次升级。
|
|
|
|
|
|
2023-02-27 12:04:04 +08:00
|
|
|
|
不希望这样吗?你可以 [阻止一个软件包被更新][5]。像这样使用 `apt-mark` 命令:
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo apt-mark hold package_name
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
我希望这个快速技巧能帮助你在需要时降级 apt 软件包。如果你有问题或建议,请告诉我。
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
via: https://itsfoss.com/downgrade-apt-package/
|
|
|
|
|
|
|
|
|
|
作者:[Abhishek Prakash][a]
|
|
|
|
|
选题:[lkxed][b]
|
|
|
|
|
译者:[geekpi](https://github.com/geekpi)
|
2023-02-27 12:04:04 +08:00
|
|
|
|
校对:[wxy](https://github.com/wxy)
|
2023-02-22 08:44:08 +08:00
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
|
|
|
|
|
|
|
|
[a]: https://itsfoss.com/author/abhishek/
|
|
|
|
|
[b]: https://github.com/lkxed/
|
|
|
|
|
[1]: https://itsfoss.com/content/images/2023/02/installed-docker-version.png
|
|
|
|
|
[2]: https://itsfoss.com/content/images/2023/02/available-docker-versions.png
|
|
|
|
|
[3]: https://itsfoss.com/content/images/2023/02/downgrading-installed-packages.png
|
|
|
|
|
[4]: https://itsfoss.com/content/images/2023/02/downgrading-installed-package.png
|
|
|
|
|
[5]: https://itsfoss.com/prevent-package-update-ubuntu/
|
2023-02-27 12:04:04 +08:00
|
|
|
|
[0]: https://img.linux.net.cn/data/attachment/album/202302/27/115623ifb79v4pi4v0z991.jpg
|