安装特定的 apt 包

安装特定的 apt 包

我使用的是 ubuntu 16 并且需要低于 5.7.28 的 mysql-server 我尝试了以下步骤:

root@hr:~# apt-cache policy mysql-server-5.7
mysql-server-5.7:
  Installed: (none)
  Candidate: 5.7.28-0ubuntu0.16.04.2
  Version table:
     5.7.28-0ubuntu0.16.04.2 500
        500 http://il.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages
     5.7.11-0ubuntu6 500
        500 http://il.archive.ubuntu.com/ubuntu xenial/main amd64 Packages

所以我想安装 5.7.11-0ubuntu6 包

root@hr:~# apt install mysql-server=5.7.11-0ubuntu6 -V
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
   mysql-client-5.7 (5.7.28-0ubuntu0.16.04.2)
   mysql-client-core-5.7 (5.7.28-0ubuntu0.16.04.2)
   mysql-common (5.7.28-0ubuntu0.16.04.2)
   mysql-server-5.7 (5.7.28-0ubuntu0.16.04.2)
   mysql-server-core-5.7 (5.7.28-0ubuntu0.16.04.2)
Suggested packages:
   mailx
   tinyca (0.7.5-6)
The following NEW packages will be installed:
   mysql-client-5.7 (5.7.28-0ubuntu0.16.04.2)
   mysql-client-core-5.7 (5.7.28-0ubuntu0.16.04.2)
   mysql-common (5.7.28-0ubuntu0.16.04.2)
   mysql-server (5.7.11-0ubuntu6)
   mysql-server-5.7 (5.7.28-0ubuntu0.16.04.2)
   mysql-server-core-5.7 (5.7.28-0ubuntu0.16.04.2)
0 upgraded, 6 newly installed, 0 to remove and 151 not upgraded.
Need to get 17.6 MB of archives.
After this operation, 155 MB of additional disk space will be used.
Do you want to continue? [Y/n]

如果我单击“是”,它将在 apt 完成安装软件包后安装所有这些软件包,我检查 mysql -V,但得到

mysql  Ver 14.14 Distrib 5.7.28, for Linux (x86_64) using  EditLine wrapper

我做错了什么?我该如何安装所需的版本?

正如@BanAnanas 建议的那样,我在 /etc/apt/preferences 文件中添加了以下几行:

Package: mysql-server-5.7
Pin: version 5.7.11-0ubuntu6
Pin-Priority: 1001

++++++++++++++++++++++++++++++++++++++++++++++++++++

root@hr:~# sudo apt-get update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
Hit:2 http://il.archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://il.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:4 http://il.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Fetched 325 kB in 8s (38.8 kB/s)
Reading package lists... Done


root@hr:~# sudo apt-get install mysql-server-5.7
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-server-5.7 : Depends: mysql-server-core-5.7 (= 5.7.11-0ubuntu6) but 5.7.28-0ubuntu0.16.04.2 is to be installed
E: Unable to correct problems, you have held broken packages.


root@hr:~# sudo apt-get install -f
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl
  libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libtimedate-perl liburi-perl
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 151 not upgraded.


root@hr:~# sudo apt-get install mysql-server-5.7
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-server-5.7 : Depends: mysql-server-core-5.7 (= 5.7.11-0ubuntu6) but 5.7.28-0ubuntu0.16.04.2 is to be installed
E: Unable to correct problems, you have held broken packages.


root@hr:~# apt-cache policy mysql-server-5.7
mysql-server-5.7:
  Installed: (none)
  Candidate: 5.7.11-0ubuntu6
  Version table:
     5.7.28-0ubuntu0.16.04.2 500
        500 http://il.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages
     5.7.11-0ubuntu6 1001
        500 http://il.archive.ubuntu.com/ubuntu xenial/main amd64 Packages

我可以在 ubuntu 服务器上使用 synaptic 吗?

答案1

APT 首选项文件 /etc/apt/preferences文件夹中的片段文件/etc/apt/preferences.d/可用于控制选择安装哪些版本的软件包。默认情况下,除非可用版本的优先级超过,否则 atp 永远不会降级1000。要解决这个问题,您必须将版本的优先级设置5.7.11-0ubuntu61001

打开/创建文件:

sudo nano /etc/apt/preferences

将此条目添加到文件并保存:

Package: mysql-server-5.7
Pin: version 5.7.11-0ubuntu6
Pin-Priority: 1001

优先级高于1000会导致安装某个版本,即使这会导致软件包降级。

要应用更改运行:

sudo apt-get install mysql-server-5.7

相关内容