无法安装php-mbstring

我正在尝试在已经安装了apache2、php和mariadb的Ubuntu 18.04服务器上安装php-mbstring。我已经尝试了以下命令序列:
jonathan@samuel:~$ sudo apt update
[sudo] password for jonathan:
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://downloads.mariadb.com/MariaDB/mariadb-10.3/repo/ubuntu bionic InRelease
Get:3 http://archive.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Ign:4 http://downloads.mariadb.com/MaxScale/2.2/ubuntu bionic InRelease
Hit:5 http://downloads.mariadb.com/Tools/ubuntu bionic InRelease
Get:6 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Hit:7 http://downloads.mariadb.com/MaxScale/2.2/ubuntu bionic Release
Fetched 172 kB in 2s (91.6 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
jonathan@samuel:~$ sudo apt install php-mbstring
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:
 php-mbstring : Depends: php7.2-mbstring but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
jonathan@samuel:~$ sudo apt -f install php7.2-mbstring
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:
 php7.2-mbstring : Depends: php7.2-common (= 7.2.3-1ubuntu1) but 7.2.7-0ubuntu0.18.04.2 is to be installed
E: Unable to correct problems, you have held broken packages.

看起来涉及到一个无法解决的依赖关系。我该如何纠正这个情况?这个问题正在阻碍我安装phpMyAdmin的尝试。
5个回答

我必须在我的sources.list中启用universe。
sudo vi /etc/apt/sources.list

将文件改成这个样子:
deb http://archive.ubuntu.com/ubuntu bionic main universe
deb http://archive.ubuntu.com/ubuntu bionic-security main universe
deb http://archive.ubuntu.com/ubuntu bionic-updates main universe

更新 apt-get

sudo apt update

然后我可以安装php7.2-mbstring。

我已启用宇宙但没有帮助。 - Jonathan
奇怪,你能把你的sources.list里面的内容发出来吗? - bradhancock
我已经改变了我的环境,原因与这个问题无关,但是一旦我安装了apache2和php,我会再次尝试并报告。 - Jonathan
@bradhancock我的sources.list文件的最后几行如下:# deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted deb http://security.ubuntu.com/ubuntu bionic-security main universe # deb-src http://security.ubuntu.com/ubuntu bionic-security universe deb http://security.ubuntu.com/ubuntu bionic-updates main universe # deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse``` - Khai Nguyen

我在Ubuntu 18.04遇到了同样的麻烦。 请编辑文件/etc/apt/sources.list,添加以下内容:
deb http://archive.ubuntu.com/ubuntu bionic main multiverse restricted universe
deb http://archive.ubuntu.com/ubuntu bionic-security main multiverse restricted universe
deb http://archive.ubuntu.com/ubuntu bionic-updates main multiverse restricted universe

#PHP 7.2 -> 保存并运行:

sudo apt update && sudo apt-get upgrade
sudo apt-get install php7.2-mbstring

#PHP 7.3 -> 保存并运行:

sudo apt update && sudo apt-get upgrade
sudo apt-get install php7.3-mbstring

完成了


如果你和我一样,可能会被诱惑着复制那些命令行并进行更新、安装和移动,而不知道这些东西的含义。我不确定哪个开关使它工作,所以有点沮丧——我该如何找出来呢?如果是restricted或multiverse,我需要付费吗?我的sources.list文件中最初只有"main"。我了解到: restricted=非免费/Canonical支持。universe=免费/不受支持。multiverse=非免费/不受支持。 https://en.wikipedia.org/wiki/Ubuntu#Package_classification_and_support - jbobbins
mbstring只在宇宙存储库中,所以您需要添加multiverse,您可以在这里获取更多信息:https://packages.ubuntu.com/bionic/php7.2-mbstring - Jorgeee
1同样适用于PHP7.3,但需要使用sudo apt-get install php7.3-mbstring进行安装。 - Yazid Erman

只需使用:

sudo apt-get install php-mbstring

然后你必须重新启动Apache服务,使用以下命令:
sudo service apache2 restart

对于安装了多个PHP版本的情况,请使用相应的mb字符串。例如,如果使用的是PHP 8.1,请使用apt install php-mbstring命令进行安装。对于非root用户,请在命令前加上sudo。 - undefined

我需要做的只是
sudo apt-get update

之后它就可以安装了。


尝试一下,我在Ubuntu 18.04中遇到了相同的问题,针对php8.0。
这将删除所有的php7.0、7.1、7.2等版本。
sudo apt-get purge php7.*
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt upgrade
sudo apt install php-mbstring

  • 相关问题