11

I am attempting to install php-mbstring on a Ubuntu 18.04 server which already has apache2, php and mariadb installed. I have tried with the following sequence of commands:

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.

It appears that there is an unresolveable dependency involved. How can I correct the situation? This problem is blocking my attempt to install phpMyAdmin.

0

5 Answers 5

14

I had to enable universe in my sources.list

sudo vi /etc/apt/sources.list

change the file to look like this:

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

updated apt-get

sudo apt update

And then I could install php7.2-mbstring

4
  • I have universe enabled and it did not help.
    – Jonathan
    Aug 13, 2018 at 1:04
  • weird, can you post what you have in your sources.list? Aug 13, 2018 at 3:27
  • I have changed my environment for reasons unrelated to this problem but as soon as I have apache2 and php installed I will try again and report.
    – Jonathan
    Aug 13, 2018 at 15:42
  • @bradhancock The last lines on my sources.list file look like that deb http://security.ubuntu.com/ubuntu bionic main universe # 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 Jun 11, 2019 at 3:58
8

I had the same trouble in Ubuntu 18.04 #Edit the file /etc/apt/sources.list with the next lines:

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 -> Save and run:

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

#PHP 7.3 -> Save and run:

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

And it's done

3
  • If you're like me you might be tempted to copy those lines and update and install and move on without knowing what those things mean. I'm not sure which switch(es) made it work, so that's a little frustrating--how do I find that out? If it was restricted or multiverse do I have to pay for it? I only had "main" originally in my sources.list file. I learned: restricted=not_free/canonical_supported. universe=free/not_supported. multiverse=not_free/not_supported. en.wikipedia.org/wiki/Ubuntu#Package_classification_and_support
    – jbobbins
    Oct 30, 2018 at 16:31
  • mbstring is only universe repositories so you need add multiverse, you can reach more information here: packages.ubuntu.com/bionic/php7.2-mbstring
    – Jorgeee
    Nov 5, 2018 at 16:27
  • 1
    Same for PHP7.3, but with sudo apt-get install php7.3-mbstring Jun 21, 2020 at 8:58
1

Simply Use:

sudo apt-get install php-mbstring

Then you must restart Apache Service, Use:

sudo service apache2 restart
1

All I had to do was

sudo apt-get update

and it was available for install after this.

0

Try this I had the same issue for php8.0 in ubuntu 18.04

This will remove (all php7.0, 7.1, 7.2 etc)

sudo apt-get purge php7.*
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt upgrade
sudo apt install php-mbstring

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.