mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
1b71884834
@ -1,191 +0,0 @@
|
||||
[#]: subject: "Install Specific Package Version With Apt Command in Ubuntu"
|
||||
[#]: via: "https://itsfoss.com/apt-install-specific-version-2/"
|
||||
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "robsean"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Install Specific Package Version With Apt Command in Ubuntu
|
||||
======
|
||||
|
||||
Want to install a specific version of a package in Ubuntu? You can do that ‘easily’ in the following manner:
|
||||
|
||||
```
|
||||
sudo apt install package_name=package_version
|
||||
```
|
||||
|
||||
How do you know which versions are available for a certain package? Use this command:
|
||||
|
||||
```
|
||||
apt list --all-versions package_name
|
||||
```
|
||||
|
||||
In the screenshot below, you can see that I have two versions of VLC available and I use the command to install the older version:
|
||||
|
||||
![install specific versions apt ubuntu][1]
|
||||
|
||||
Sounds like a simple task, right? But things are not as simple as they look. There are several ifs and buts involved here.
|
||||
|
||||
This tutorial will cover all the important aspects of installing a specific program version using apt or apt-get commands.
|
||||
|
||||
### Things to know about installing a specific version of a program
|
||||
|
||||
You need to know a few things about how APT and repositories work in Ubuntu and Debian-based distributions.
|
||||
|
||||
#### No older versions from the same source
|
||||
|
||||
Ubuntu doesn’t keep older versions of packages in the repository. You may see more than one version in specific cases, temporarily. For example, you run the apt update (but not upgrade), and a new version is available. You may see two versions for the same package in the apt cache. But as soon as the package is upgraded to the new version, the older version is removed from the cache as well as the repositories.
|
||||
|
||||
#### Use multiple sources for different versions
|
||||
|
||||
To get multiple versions of the same package, you’ll have to add multiple sources. For example, VLC is in version 3.x. Adding the [VLC daily build PPA][2] will give the (unstable) version 4.x.
|
||||
|
||||
Similarly, **you can download a DEB file with a different version and install it**.
|
||||
|
||||
#### The higher version always gets the priority
|
||||
|
||||
If you have the same package available from more than one source, by default, Ubuntu will install the highest available version.
|
||||
|
||||
In the previous example, if I install VLC, it will install version 4.x, not 3.x.
|
||||
|
||||
#### The older version gets upgraded to the available newer version
|
||||
|
||||
That’s another potential problem. Even if you install the older version of a package, it gets upgraded to the newer version (if available). You have to [hold the package and stop it from upgrading][3].
|
||||
|
||||
#### Dependencies also need to be installed
|
||||
|
||||
If the package has dependencies, you’ll have to install the required version of the dependent packages as well.
|
||||
|
||||
Now that you know a few potential issues let’s see how to tackle them.
|
||||
|
||||
### Installing specific version of a package
|
||||
|
||||
I am taking the example of VLC in this tutorial. VLC version 3.0.16 is available in Ubuntu’s repositories. I added the daily build PPA and that gives me the release candidate of VLC version 4.0.
|
||||
|
||||
As you can see, I have two VLC versions available in the system right now:
|
||||
|
||||
![install specific versions apt ubuntu][4]
|
||||
|
||||
```
|
||||
[email protected]:~$ apt list -a vlc
|
||||
Listing... Done
|
||||
vlc/jammy 4.0.0~rc1~~git20220516+r92284+296~ubuntu22.04.1 amd64
|
||||
vlc/jammy 3.0.16-1build7 amd64
|
||||
vlc/jammy 3.0.16-1build7 i386
|
||||
```
|
||||
|
||||
Since the higher version takes priority, using ‘apt install vlc’ will result in the installation of VLC 4.0. But I want to install the older version 3.0.16 for the sake of this tutorial.
|
||||
|
||||
```
|
||||
sudo apt install vlc=3.0.16-1build7
|
||||
```
|
||||
|
||||
But here’s the thing. The vlc package has several dependencies and those dependencies also need specific versions. However, Ubuntu tries to install the available higher versions for them, and thus, you get the classic ‘[you have held broken packages][5]‘ error.
|
||||
|
||||
![problem installing specific version apt ubuntu][6]
|
||||
|
||||
To fix this, you have to provide specific versions of all the dependent packages it complains about. So that command becomes something like this:
|
||||
|
||||
```
|
||||
sudo apt install vlc=3.0.16-1build7 \
|
||||
vlc-bin=3.0.16-1build7 \
|
||||
vlc-plugin-base=3.0.16-1build7 \
|
||||
vlc-plugin-qt=3.0.16-1build7 \
|
||||
vlc-plugin-video-output=3.0.16-1build7 \
|
||||
vlc-l10n=3.0.16-1build7 \
|
||||
vlc-plugin-access-extra=3.0.16-1build7 \
|
||||
vlc-plugin-notify=3.0.16-1build7 \
|
||||
vlc-plugin-samba=3.0.16-1build7 \
|
||||
vlc-plugin-skins2=3.0.16-1build7 \
|
||||
vlc-plugin-video-splitter=3.0.16-1build7 \
|
||||
vlc-plugin-visualization=3.0.16-1build7
|
||||
```
|
||||
|
||||
In case you are wondering, the trailing \ at the end of each line is just a way to write a single command over multiple lines.
|
||||
|
||||
**Does it work? In many cases, it will.** But I have chosen a complicated example of VLC, which has lots of dependencies. Even the mentioned dependencies have dependencies on other packages. It gets messy.
|
||||
|
||||
An alternative is to specify the source while installing.
|
||||
|
||||
#### Alternatively, specify the repository source
|
||||
|
||||
You have added multiple sources, so you should have some idea about the sources the package comes from.
|
||||
|
||||
Use the command below and search for the repository:
|
||||
|
||||
```
|
||||
apt-cache policy | less
|
||||
```
|
||||
|
||||
Focus on the lines that come after the repository name:
|
||||
|
||||
```
|
||||
500 http://security.ubuntu.com/ubuntu jammy-security/multiverse i386 Packages
|
||||
release v=22.04,o=Ubuntu,a=jammy-security,n=jammy,l=Ubuntu,c=multiverse,b=i386
|
||||
origin security.ubuntu.com
|
||||
```
|
||||
|
||||
You can specify the o,l,a, etc parameters.
|
||||
|
||||
In my original example, I want to install VLC from Ubuntu’s repository (to get 3.16) instead of the PPA (which gives me 4).
|
||||
|
||||
So the command below will install VLC 3.16 along with all the dependencies:
|
||||
|
||||
```
|
||||
sudo apt install -t "o=ubuntu" vlc
|
||||
```
|
||||
|
||||
![install from repository source][7]
|
||||
|
||||
Looks good? But the problem comes when you have to update the system. Then it complains about not finding the specified version.
|
||||
|
||||
**What else can be done?**
|
||||
|
||||
To install an older version, remove the source of the newer version from your system (if possible). It helps get rid of the dependencies hell issues.
|
||||
|
||||
If that’s not possible, check if you can get it in some other packaging formats like Snap, Flatpak, AppImage, etc. In fact, Snap and Flatpak also allow you to choose and install from available versions. Since the applications are sandboxed, it’s easier to manage the dependencies for different versions.
|
||||
|
||||
#### Hold the package and prevent upgrade
|
||||
|
||||
If you manage to install a specific program version, you may want to avoid accidentally upgrading to the newer version. It’s not too complicated to achieve this.
|
||||
|
||||
```
|
||||
sudo apt-mark hold package_name
|
||||
```
|
||||
|
||||
You can remove the hold so that it can be upgraded later:
|
||||
|
||||
```
|
||||
sudo apt-mark unhold package_name
|
||||
```
|
||||
|
||||
Note that dependencies of a package are not automatically held. They need to be individually mentioned.
|
||||
|
||||
### Conclusion
|
||||
|
||||
As you can see, there is a provision to install the selected version of a program. Things only get complicated if the package has dependencies. Then you get into the dependency hell.
|
||||
|
||||
I hope you learned a few new things in this tutorial. If you have questions or suggestions to improve it, please let me know in the comment section.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/apt-install-specific-version-2/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [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/wp-content/uploads/2022/05/install-specific-versions-apt-ubuntu.png
|
||||
[2]: https://launchpad.net/~videolan/+archive/ubuntu/master-daily
|
||||
[3]: https://itsfoss.com/prevent-package-update-ubuntu/
|
||||
[4]: https://itsfoss.com/wp-content/uploads/2022/05/install-specific-versions-apt-ubuntu.png
|
||||
[5]: https://itsfoss.com/held-broken-packages-error/
|
||||
[6]: https://itsfoss.com/wp-content/uploads/2022/05/problem-installing-specific-version-apt-ubuntu-800x365.png
|
||||
[7]: https://itsfoss.com/wp-content/uploads/2022/05/install-from-repository-source-800x578.png
|
@ -0,0 +1,191 @@
|
||||
[#]: subject: "Install Specific Package Version With Apt Command in Ubuntu"
|
||||
[#]: via: "https://itsfoss.com/apt-install-specific-version-2/"
|
||||
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "robsean"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
在 Ubuntu 中使用 apt 命令来安装具体指定的软件包版本
|
||||
======
|
||||
|
||||
在 Ubuntu 中想安装一个软件包的一个具体指定的软件包版本?你可以通过下面的方式来轻松地完成:
|
||||
|
||||
```
|
||||
sudo apt install package_name=package_version
|
||||
```
|
||||
|
||||
你如何知道某个软件包有哪些可用的版本?使用这个命令:
|
||||
|
||||
```
|
||||
apt list --all-versions package_name
|
||||
```
|
||||
|
||||
在下面的屏幕截屏中,你可以看到,我有两个可用的 VLC 版本,我使用命令来安装较旧的版本:
|
||||
|
||||
![install specific versions apt ubuntu][1]
|
||||
|
||||
听起来像一个简单的任务,对吧?但是事情并非看起来那么简单。这里有一些不确定是否会出现,但是可能会涉及的东西。
|
||||
|
||||
这篇教程将涵盖使用 apt 或 apt-get 命令来安装一个具体指定的程序的版本的所有的重要的方面。
|
||||
|
||||
### 关于安装一个具体指定版本的程序而所需要知道的事
|
||||
|
||||
在基于 Ubuntu 和 Debian 发行版中,你需要知道一些关于 APT 和 存储库 是如何工作的知识
|
||||
|
||||
#### 同一个的软件包源没有较旧的版本
|
||||
|
||||
Ubuntu 在其存储库中不保留较旧版本的软件包。在特殊的情况下,你可以暂时性地看到多个版本。例如,你运行 apt 更新 (但不升级),那么会用一个可用的新的版本。在 apt 缓存中,你可以看到同一个软件包的两个版本。但是,一旦软件包被升级到了新的版本,较旧版本的软件包将从 **apt 缓存** 和 存储库 中移除。
|
||||
|
||||
#### 使用多个软件包源来使用不同的版本
|
||||
|
||||
为获取同一个的软件包的多个版本,你将必需条件多个软件包源。例如,VLC 是版本 3.x 系列。添加 [VLC 每日构建 PPA][2] 将会提供 (不稳定是) 版本 4.x 系列。
|
||||
|
||||
同样,**你可以下载不同版本的 DEB 文件,并安装它**。
|
||||
|
||||
#### 较高版本编号的版本通常获取优先权
|
||||
|
||||
如果你有来自多个软件包源的相同名称的软件,默认情况下,Ubuntu 将安装可用的最高版本编号的版本。
|
||||
|
||||
在前面的示例中,如果我安装 VLC ,那么它将会安装 4.x 系列的版本,而不是 3.x 系列的版本。
|
||||
|
||||
#### 较旧版本将升级到可用的较新版本
|
||||
|
||||
这是另外一个可能存在的问题。即使你安装较旧版本的软件包,它也会升级到较新的版本 (如果存在可用的较新的版本)。你必须 [监禁软件包来防止其升级][3] 。
|
||||
|
||||
#### 依赖关系也需要安装
|
||||
|
||||
如果软件包有依赖关系,你也需要安装必要的依赖关系软件包版本。
|
||||
|
||||
现在,你已经知道一些可能存在的问题,让我们看看如何解决它们。
|
||||
|
||||
### 安装一个软件包的具体指定版本
|
||||
|
||||
在这篇教程中,我将以 VLC 为例。在 Ubuntu 的存储库中可获得 VLC 版本。我添加了每日构建 PPA ,它将向我提供 VLC 的 4.0 版本的候选版本。
|
||||
|
||||
如你所见,在现在的系统中,我有两个可用的 VLC 版本:
|
||||
|
||||
![install specific versions apt ubuntu][4]
|
||||
|
||||
```
|
||||
[email protected]:~$ apt list -a vlc
|
||||
Listing... Done
|
||||
vlc/jammy 4.0.0~rc1~~git20220516+r92284+296~ubuntu22.04.1 amd64
|
||||
vlc/jammy 3.0.16-1build7 amd64
|
||||
vlc/jammy 3.0.16-1build7 i386
|
||||
```
|
||||
|
||||
因为较高版本编号版本获取优先权,使用 ‘apt install vlc’ 命令将会导致安装 VLC 的 4.0 版本。但是,因为这篇教程的缘由,我想安装较旧的版本 3.0.16 。
|
||||
|
||||
```
|
||||
sudo apt install vlc=3.0.16-1build7
|
||||
```
|
||||
|
||||
但是,这里会有这样的事。vlc 软件包有一些依赖关系,并且这些依赖关系也需要具体指定的版本。因此,在 Ubuntu 为其尝试安装最新的版本时,你将会遇到经典的 [<ruby>你已持有残缺软件包<rt>you have held broken packages</rt></ruby>][5] 错误。
|
||||
|
||||
![problem installing specific version apt ubuntu][6]
|
||||
|
||||
为修复这个错误,你需要为其提供它所投诉的所有依赖关系的软件包的具体指定版本。因此,该命令会变成这样:
|
||||
|
||||
```
|
||||
sudo apt install vlc=3.0.16-1build7 \
|
||||
vlc-bin=3.0.16-1build7 \
|
||||
vlc-plugin-base=3.0.16-1build7 \
|
||||
vlc-plugin-qt=3.0.16-1build7 \
|
||||
vlc-plugin-video-output=3.0.16-1build7 \
|
||||
vlc-l10n=3.0.16-1build7 \
|
||||
vlc-plugin-access-extra=3.0.16-1build7 \
|
||||
vlc-plugin-notify=3.0.16-1build7 \
|
||||
vlc-plugin-samba=3.0.16-1build7 \
|
||||
vlc-plugin-skins2=3.0.16-1build7 \
|
||||
vlc-plugin-video-splitter=3.0.16-1build7 \
|
||||
vlc-plugin-visualization=3.0.16-1build7
|
||||
```
|
||||
|
||||
以免你瞎琢磨,每行结尾处的 \ 只是用来将多行命令来写入同一个命令的一种方式。
|
||||
|
||||
**它有作用吗?在很多情况下,它是有作用的。** 但是,我选择了一个复杂的 VLC 示例,它有很多依赖关系。甚至这些所涉及的依赖关系也依赖于其它的软件包。所以,它就变得令人难以处理。
|
||||
|
||||
一种可选的方法是在安装时指定软件包源。
|
||||
|
||||
#### 可选,指定存储库软件包源
|
||||
|
||||
你已经添加多个软件包源,因此,你应该对这些软件包的来源有一些了解。
|
||||
|
||||
使用下面的命令来搜索存储库:
|
||||
|
||||
```
|
||||
apt-cache policy | less
|
||||
```
|
||||
|
||||
聚焦于存储库名称后面的行:
|
||||
|
||||
```
|
||||
500 http://security.ubuntu.com/ubuntu jammy-security/multiverse i386 Packages
|
||||
release v=22.04,o=Ubuntu,a=jammy-security,n=jammy,l=Ubuntu,c=multiverse,b=i386
|
||||
origin security.ubuntu.com
|
||||
```
|
||||
|
||||
你可以具体指定 o、l、a 等参数。
|
||||
|
||||
在我原来的示例中,我想安装来自 Ubuntu 存储库的 VLC (获取版本 3.16) ,而不是安装来 PPA 的版本 (它将向我提供版本 4)。
|
||||
|
||||
因此,下面的命令将安装 VLC 版本 3.16 及其所有的依赖关系:
|
||||
|
||||
```
|
||||
sudo apt install -t "o=ubuntu" vlc
|
||||
```
|
||||
|
||||
![install from repository source][7]
|
||||
|
||||
看起来令人满意?但是,当你必须更新系统时,问题就来了。它接下来会控诉找不到指定的软件包版本。
|
||||
|
||||
**还能做什么?**
|
||||
|
||||
为安装较旧的软件包版本,从你的系统中移除较新版本的软件包源 (如果可能的话)。它将有助于逃脱这些依赖关系的地狱。
|
||||
|
||||
如果不能这么做,检查你是否可以从其它一些打包软件包的格式来获取,像 Snap、Flatpak、AppImage 等等。事实上,Snap 和 Flatpak 也允许你从可用的版本中选择和安装。因为这些应用程序是沙盒模式的,所以它很容易管理不同版本的依赖关系。
|
||||
|
||||
#### 保留软件包,防止升级
|
||||
|
||||
如果你完成安装一个指定的程序版本,你可能想避免意外地升级到较新的版本。实现这一点并不太复杂。
|
||||
|
||||
```
|
||||
sudo apt-mark hold package_name
|
||||
```
|
||||
|
||||
你可以移除保留软件包,以便它能稍后升级:
|
||||
|
||||
```
|
||||
sudo apt-mark unhold package_name
|
||||
```
|
||||
|
||||
注意,软件包的依赖关系不会自动地保持。它们需要单独地提及。
|
||||
|
||||
### 结论
|
||||
|
||||
如你所见,这里有一条安装选定软件包版本的条文。只要软件包有依赖关系,那么事情就会变得复杂。接下来,你将进入依赖关系的地狱。
|
||||
|
||||
我希望你在这篇教程中学到一些新的东西。如果你有问题或建议来改善它,请在评论区告诉我。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/apt-install-specific-version-2/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[robsean](https://github.com/robsean)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [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/wp-content/uploads/2022/05/install-specific-versions-apt-ubuntu.png
|
||||
[2]: https://launchpad.net/~videolan/+archive/ubuntu/master-daily
|
||||
[3]: https://itsfoss.com/prevent-package-update-ubuntu/
|
||||
[4]: https://itsfoss.com/wp-content/uploads/2022/05/install-specific-versions-apt-ubuntu.png
|
||||
[5]: https://itsfoss.com/held-broken-packages-error/
|
||||
[6]: https://itsfoss.com/wp-content/uploads/2022/05/problem-installing-specific-version-apt-ubuntu-800x365.png
|
||||
[7]: https://itsfoss.com/wp-content/uploads/2022/05/install-from-repository-source-800x578.png
|
Loading…
Reference in New Issue
Block a user