dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac
Phpnode.jsMacosHomebrewPhp Problem Overview
I installed node using homebrew (Mojave), afterwards php stoped working and if I try to run php -v
I get this error:
php -v
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
I tried to uninstall both node and icu4c but the problem persists
Php Solutions
Solution 1 - Php
> Update - As stated in some of the comments, running brew cleanup
could possibly fix this error, if that alone doesn't fix it, you might try upgrading individual packages or all your brew packages.
I just had this same problem. Upgrading Homebrew and then cleaning up worked for me. This error likely showed up for me because of a mismatch in package versions. None of the above solutions resolved my error, but running the following homebrew commands did.
> Caution - This will upgrade all your brew packages, including, but not limited to PHP. If you only want to upgrade specific packages make sure to be specific.
brew upgrade // for upgrading all packages -- this is the command I used
brew upgrade {package} // for upgrading a specific package
and finally
brew cleanup
Solution 2 - Php
In my case, that happened because icu4c was upgraded to version 63 but my locally installed postgres image still referenced icu4c 62.1. Therefore I had to change the icu4c version used:
brew info icu4c
brew switch icu4c <version>
Where version
is the installed version returned by info
.
Solution 3 - Php
I am actually quite surprised that this solution has not been presented yet, and I feel like it is the easiest solution.
Go to GitHub, find the version of the brewfile that matches the version of icu4c
that you need and get the raw version of the file (follow the links above and click View File
then Raw
).
Then just have brew reinstall from that url.
For example, version 62.1
:
brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/575eb4bbef683551e19f329f60456b13a558132f/Formula/icu4c.rb
For example, version 64.2
:
brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/a806a621ed3722fb580a58000fb274a2f2d86a6d/Formula/icu4c.rb
UPDATE:
Later versions of Homebrew may require you to download the file first. If this is the case:
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/a806a621ed3722fb580a58000fb274a2f2d86a6d/Formula/icu4c.rb
brew reinstall icu4c.rb
Solution 4 - Php
Turns out I, like @Grey Black, had to actually install v62.1 of icu4c. Nothing else worked.
However, brew switch icu4c 62.1
only works if you have installed 62.1 in the past. If you haven't there's more legwork involved. Homebrew does not make it easy to install previous versions of formulae.
Here's how I did it:
- We first need a deep clone of the Homebrew repo. This may take a while:
git -C $(brew --repo homebrew/core) fetch --unshallow
brew log icu4c
to track down a commit that references 62.1;575eb4b
does the trick.cd $(brew --repo homebrew/core)
git checkout 575eb4b -- Formula/icu4c.rb
brew uninstall --ignore-dependencies icu4c
brew install icu4c
You should now have the correct version of the dependency! Now just to...git reset && git checkout .
Cleanup your modified recipe.brew pin icu4c
Pin the dependency to prevent it from being accidentally upgraded in the future
If you decide you do want to upgrade it at some point, make sure to run brew unpin icu4c
Solution 5 - Php
Run npm version
, if you see the same error, upgrade npm.
brew upgrade npm
.
==> Upgrading 1 outdated package, with result:
npm 8.1.2 -> 10.3.0
==> Upgrading npm
==> Installing dependencies for node: icu4c
==> Installing node dependency: icu4c
Solution 6 - Php
I had the same problem after I upgraded my macOS
to version 10.13.6
. I can't run composer
and php
commands. After researching for a while and trying various solutions posted online, reinstalling php using homebrew
worked.
brew reinstall [email protected]
Added on March 14th based on Ryan's comment
get the version you are currently using by running php -v
and get the right formulae (which you can find here: https://formulae.brew.sh/formula/php) to replace @7.1
in the above command.
Solution 7 - Php
This fixed it for me:
brew upgrade node
Solution 8 - Php
For me the solution was to:
brew reinstall icu4c
Then
gem uninstall charlock_holmes
gem install charlock_holmes
Solution 9 - Php
Seems like it is impossible to link icu4c
using brew
after latest OS X update. Which makes things more interesting. The only solution I found working for me:
- Download and compile
icu4c
62.1 to/usr/local/icu4c/62.1
mkdir ~/sources
cd ~/sources
wget http://download.icu-project.org/files/icu4c/62.1/icu4c-62_1-src.tgz
tar xvzf icu4c-62_1-src.tgz
cd icu/source/
sudo mkdir /usr/local/icu4c/62.1
./configure --prefix=/usr/local/icu4c/62.1
make
sudo make install
- Link libs:
ln -s /usr/local/icu4c/62.1/lib/*.dylib /usr/local/include/
- Set
DYLD_LIBRARY_PATH
in~/.bash_profile
:
export DYLD_LIBRARY_PATH=/usr/local/include
Solution 10 - Php
I actually tried all of the solutions which made sense, mentioned in this post and yet i still got the same error when running php -v
or composer
.
The node version was fine, npm as well there were no issues on having installed correct versions and they were all running.
Running reinstall [email protected]
just threw an error.
In the end i had to run:
brew reinstall icu4c
This basically worked, with me having to manually then install php dependencies such as imagick.so
, imap.so
As these libraries were installed for a project that i no longer maintain i can go without them. But if you do have dependancies on them, have in mind that there will be more work to do afterwards.
Solution 11 - Php
Just brew remove php
and brew install php
did not work, nor did brew reinstall php
.
My solution was to do:
brew remove php
cd /usr/local/Cellar
rm -rf php/
brew install php
brew doctor
brew cleanup
Now php -v
gives me:
PHP 7.3.2 (cli) (built: Feb 14 2019 10:08:45) ( NTS )
Solution 12 - Php
my issue:
# npm install -g canvas
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
Referenced from: /usr/local/opt/node@8/bin/node
Reason: image not found
for now 20210118, after many try:
...
brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/icu4c.rb
brew upgrade npm
brew install node
brew uninstall --ignore-dependencies node@8 icu4c
brew install icu4c
...
Final worked solution is:
brew reinstall npm
Solution 13 - Php
2021-02 Easy solution
After years of dealing with this problem the following, surprisingly easy, solution worked for me:
- Open the raw file in your web browser of the version you need:
Latest version: https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/icu4c.rb
- Copy paste the contents into a new file named: icu4c.rb
- Run the following on the newly created file:
brew reinstall icu4c.rb
Source: https://gist.github.com/hgrimelid/703691ab48c4a4d0537cfe835b4d55a6
Solution 14 - Php
Actually, I found the solution directly on homebrew page: https://docs.brew.sh/Common-Issues
Upgrading macOS can cause errors like the following:
- dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.54.dylib configure: error: Cannot find libz
- Following a macOS upgrade it may be necessary to reinstall the Xcode Command Line Tools and brew upgrade all installed formula:
xcode-select --install
brew upgrade
In my case the problem wasn't related to upgrading OS, but the solution worked nicely.
Solution 15 - Php
For me brew reinstall nodejs
fixed this - my issue was with running Elixir/Phoenix so not PHP specific, I think it was caused by brew install postgres
, but reinstalling that didn't help. I was getting it from npm
commands.
Solution 16 - Php
In order to downgrade, i had to recompile from source (MacOS Mojave)
$ wget https://ssl.icu-project.org/files/icu4c/62.1/icu4c-62_1-src.tgz
$ tar xvfz icu4c-62_1-src.tgz
$ cd icu/sources
$ ./configure
$ make
$ make install
Solution 17 - Php
brew update && brew upgrade
worked for me
Solution 18 - Php
i followed this article here and this seems to be the missing piece of the puzzle for me:
brew uninstall node@8
Solution 19 - Php
This is what finally worked for me.
brew reinstall postgres
After running the above command you might need to run
brew postgresql-upgrade-database
to access your previous data.
Solution 20 - Php
Rather than install an old version of icu4c
that the older (precompiled) php can link to, it's better to recompile the old php to link to the more recent library.
brew uninstall php@7.2
brew install --build-from-source php@7.2
This will build php and link it to the newer library. I found reinstall
didn't quite work; the new install choked when the destination folder already existed.
I also did brew link --force [email protected]
for my environment.
Solution 21 - Php
I had problems because my version of PHP (7.3) was expecting icu4c 63 and brew would only install 64.
https://stackoverflow.com/a/55828190/2000947 helped me install 63.
Solution 22 - Php
On MacOS Mojave, only way I could fix it was with brew upgrade
Solution 23 - Php
On OSX 10.15.4 running xcode-select --install
fixed the issue for me.
Solution 24 - Php
Leland's answer worked for me, but I had to change steps 4 and 6 to:
-
git checkout -B icu4c-62.1 575eb4b
-
brew reinstall Formula/icu4c.rb
Solution 25 - Php
The solution in this gist did it for me
brew uninstall --ignore-dependencies node icu4c
brew install node
Solution 26 - Php
In my case, brew update icu4c to version 67.1 so my php7.1 doesn't work. Just reinstall icu4c, then it fine.
Solution 27 - Php
Got this error, too, after installing php 7.3. I had it resolved upgrading just my old php's versions (5.6 and 7.0, not from the official repos).
The maintainers had compiled new php versions against the current icu4c.
In my case, PHP 7 got from 0.31 to 0.33, and the problem was solved.
Solution 28 - Php
In my case I had to switch between two versions of icu4c since I still maintain PHP 5.6 projects (which use the old icu4c 64.2). brew install and reinstall from raw .rb links always replaces the previously installed versions for some reason.
#fetching 64.2
brew fetch https://raw.githubusercontent.com/Homebrew/homebrew-core/a806a621ed3722fb580a58000fb274a2f2d86a6d/Formula/icu4c.rb
#fetching stable version
brew fetch https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/icu4c.rb
cd $(brew --cache)/downloads
tar xvfz e2a83648f37dc5193016ce14fa6faeb97460258b214e805b1d7ce8956e83c1a7--icu4c-64.2.catalina.bottle.tar.gz
tar xvfz e045a709e2e21df31e66144a637f0c77dfc154f60183c89e6b04afa2fbda28ba--icu4c-67.1.catalina.bottle.tar.gz
mv -n icu4c/67.1 $(brew --cellar)/icu4c/
mv -n icu4c/64.2 $(brew --cellar)/icu4c/
then switch between versions
$ brew switch icu4c 64.2
Cleaning /usr/local/Cellar/icu4c/64.2
Cleaning /usr/local/Cellar/icu4c/67.1
Opt link created for /usr/local/Cellar/icu4c/64.2
$ brew switch icu4c 67.1
Cleaning /usr/local/Cellar/icu4c/64.2
Cleaning /usr/local/Cellar/icu4c/67.1
Opt link created for /usr/local/Cellar/icu4c/67.1
Solution 29 - Php
[2020] edition
For me, it was installing icu4c with the needed version.
If you need to install the old version like version 62, (same steps for else versions), you need to:
- Create your own repo (or find someones repo) with this version of brew tap (links are different for every version):
version 62
https://raw.githubusercontent.com/Homebrew/homebrew-core/575eb4bbef683551e19f329f60456b13a558132f/Formula/icu4c.rb
version 64
https://raw.githubusercontent.com/Homebrew/homebrew-core/a806a621ed3722fb580a58000fb274a2f2d86a6d/Formula/icu4c.rb
version 66
https://raw.githubusercontent.com/Homebrew/homebrew-core/22fb699a417093cd1440857134c530f1e3794f7d/Formula/icu4c.rb
version 67
https://raw.githubusercontent.com/Homebrew/homebrew-core/88b9cc789820f2f544d8d4a1053eebb044c2926c/Formula/icu4c.rb
- [yourUsername]/homebrew-versions/Formula/
- Place downloaded file to 'Formula' folder
brew tap [yourUsername]/homebrew-versions
brew install [yourUsername]/homebrew-versions/icu4c
- You got it!
Where [yourUsername] is the name of your GitHub account or person who already have the needed version tap.
> Unfortunately, latest homebrew gives no longer a warning and now > displays the error: Error: Calling Installation of XXX from a GitHub > commit URL is disabled! Use 'brew extract XXX' to stable tap on GitHub > instead. So the way to go now is to create a new repo on github called > homebrew-versions to host the Formula in a Tap Then initialise it > with: brew tap-new MYORG/homebrew-versions after git cloning the > homebrew repo as suggested by Shine Hugh, copy paste the raw ruby file > to your new Formula. Beware the funny naming convention! Example: File > name is: [email protected] Class name is: GettextAT0202 Example: > https://github.com/nedap/homebrew-versions > > source:https://itnext.io/how-to-install-an-older-brew-package-add141e58d32
Solution 30 - Php
I just wanted to leave a detail summary on how to fix this issue at the current moment (this worked for me):
First go to the local installation of homebrew
cd /usr/local/Homebrew/
Homebrew > 2.5 remove the option to install formulas directly from git repos so we need to checkout an older version
git checkout 2.3.0
Install icu4c version (in my case 64.2 was compitable with [email protected])
HOMEBREW_NO_AUTO_UPDATE=1 brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/a806a621ed3722fb580a58000fb274a2f2d86a6d/Formula/icu4c.rb
Go back to current version of homebrew
git checkout -
Tell brew to use the old version of icu4c this way you can chose wich version to use if you have both intalled
brew switch icu4c 64.2
Solution 31 - Php
I solved int by updating all the R packages:
update.packages(checkBuilt = TRUE, ask = FALSE)
Solution 32 - Php
If you have latest icu4c
version and suffer like me from fragile software and just want postgres
/whatever to work:
$ brew upgrade icu4c
Warning: icu4c 69.1 already installed
Then you can just make symlinks:
> dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicuuc.68.dylib
cd /usr/local/opt/icu4c/lib
ln -s libicuuc.69.1.dylib libicuuc.68.dylib
ln -s libicuio.69.1.dylib libicui18n.68.dylib
These symlinks will disappear the first time you update icu4c
, but this is probably the fastest way to fix.
Solution 33 - Php
I've tried many of the suggestions here, and at the end brew upgrade php
is what did the trick for me, but seems the issue is all over the place
Solution 34 - Php
in my case, I reinstall all packages installed with Homebrew
$ brew list | xargs brew reinstall
After that, I start to install my version that I need