726

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

14
  • Did you also install php from Homebrew? Did you try to reinstall php? Commented Dec 18, 2018 at 20:14
  • 6
    For posterity: uninstall/reinstall yarn/node seems to do the trick. Commented Feb 14, 2019 at 7:31
  • 50
    according to my understanding, this happens when you've mismatch version dependencies. in my case, "brew upgrade" command fixed my issues. please correct me, if i'm wrong in any way. Commented Feb 17, 2019 at 14:38
  • 17
    While I was getting this, the problem was that /usr/local/opt/icu4c didn't exist, and brew reinstall icu4c gave me a bunch of "permission denied" issues for the icu4c dir. So I sudo rm -rf /usr/local/Cellar/icu4c and brew reinstall icu4c, and everything worked. Commented Feb 16, 2021 at 14:43
  • 5
    just running brew upgrade helped me Commented May 28, 2022 at 19:41

48 Answers 48

1094
Answer recommended by PHP Collective

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 icu4c brew upgrade // or upgrade all packages 

and finally

brew cleanup 
Sign up to request clarification or add additional context in comments.

32 Comments

I think this is not a good idea for those that have environment with two versions of PHP like me. Also, brew upgrade will upgrade your PHP version and this is not necessary good if your goal is not to upgrade your PHP, but solve a library error.
I wouldn't do this because brew upgrade will upgrade all your brew outdated packages, instead, probably only do brew upgrade npm or a specific package, not all.
@xgMz You’re right about this. For me, I didn’t care if I was updating all my packages, but for someone that doesn’t want to, then that’s probably not great. I added a note to my solution. Thanks!
@Leland 's answer below is what was needed for me even after brew cleanup and brew upgrade of specific package. Switching the package manually worked.
This worked before I even ran brew cleanup. In my case the error didn't occur until I tried running an n98 command (magento cli) through crontab. This helped.
|
338

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.

16 Comments

I did not have 62.1 installed. brew list icu4c showed a files from /usr/local/Cellar/icu4c/63.1. brew switch icu4c 63.1 fixed it for me.
I found this page after finding this error in my Postgres logs. I also tried brew switch icu4c 63.1 but still getting the same error in the logs, even after restarting postgres. Not sure what to do next...
I ended up running brew reinstall postgres and that seemed to solve my problems
Unfortunately brew switch no longer available.
The new brew switch command is brew link
|
153

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 

15 Comments

Worked great! To fix error dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib this command fixed it: brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/a806a621ed3722fb580a58000fb274a2f2d86a6d/Formula/icu4c.rb
For icu4c 66: brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/22fb699a417093cd1440857134c530f1e3794f7d/Formula/icu4c.rb
This doesn't work anymore. It asks you to brew extract
@brunouno You need to download the .rb file and do: brew reinstall icu4c.rb
Simple running `brew reinstall icu4c worked for me. Thanks for leading me in the right direction!
|
129

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 

Credits

5 Comments

it works for my case as I'd upgraded php to v8.2 yesterday but failed halfway, however, the icu4c had already upgraded to v.72 before that (with brew upgrade) while the current npm version only supports 71. So upgrading npm to newest version to match the newly upgraded icu4c version solves my issue.
Hello from 2024-Feb. This is the solution that worked in my case. I am using zsh with ohmyzsh. I suspect that a brew update failed resulting in missing required files (e.g., '/opt/homebrew/opt/icu4c/lib/libicui18n.73.dylib' (no such file)...). Regardless, commands were failing and brew COULD not upgrade other outdated packages due to resulting errors. Upgrading this 'npm' resolved the problem, and all subsequent brew upgrades worked.
This is the solution that worked. Thank you very much for this.
I had something similar but it was node that was out of date. 'brew update node' repaired it for me.
This one worked for me
84

For me the solution was to:

brew reinstall icu4c 

Then

gem uninstall charlock_holmes gem install charlock_holmes 

4 Comments

Just brew reinstall icu4c did the job for me. Thanks.
The solution for me was brew reinstall icu4c
For me it only worked to reinstall charlock_holmes
This worked for me to fix the error with vips.
84

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:

  1. We first need a deep clone of Homebrew's formulae. Warning, this will download about 900MB: brew tap homebrew/core --force && cd $(brew --repo homebrew/core)
    • Older Homebrew versions: cd $(brew --repo homebrew/core) && git fetch --unshallow
  2. brew log icu4c to track down a commit that references 62.1; 575eb4b does the trick.
  3. git checkout 575eb4b -- Formula/icu4c.rb
  4. brew uninstall --ignore-dependencies icu4c
  5. brew install icu4c You should now have the correct version of the dependency! Now just to...
  6. git reset --hard HEAD Cleanup your modified recipe.
  7. 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

16 Comments

You should first do git -C (brew --repo homebrew/core) fetch --unshallow to make sure you have a full brew git history.
This is the only solution out there that worked for me, thank you! In my case the problem was ffmpeg package which, I assume, installed newer version of icu4c. Neither updating, upgrading brew worked, nor reinstalling, relinking, building php from source.
In my case I've needed icu4c v63, so the related commit to checkout is bc0c97952453ff6afc146aa3a706e9902aba4300. The git command is git checkout bc0c97952453ff6afc146aa3a706e9902aba4300 -- Formula/icu4c.rb and then brew switch 63.1
This resulted in ==> Downloading https://ghcr.io/v2/homebrew/core/icu4c/manifests/67.1 #=#=-# # curl: (22) The requested URL returned error: 404 Error: Failed to download resource "icu4c_bottle_manifest" Download failed: https://ghcr.io/v2/homebrew/core/icu4c/manifests/67.1 when I tried to get version 67.1 with github.com/Homebrew/homebrew-core/commit/….
Ok so brew has moved on. The command structure has changed and the format of the "formula" has too. I got past the format by editing the ruby to suit the new format. It doesn't help me though becuase, as @bluepanda said, https://ghcr.io/v2/homebrew/core/icu4c/manifests/64.2 is gone. I did find an alternative formula though, and it did work for me: gist.github.com/bbatsche/c1c747bb9297661772ae7e106c556c3f. I used wget to pull the file and then brew reinstall [email protected] followed by brew link Icu4c@64. I'll now retire to the simplicity of my archlinux box :)
|
64

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.

5 Comments

I got the same error running node after upgrading macOS to 10.14.2, brew reinstall node was the ticket for me too
I started getting this error after installing a new package with brew. Doing brew upgrade fixed it for me.
brew reinstall php may end up installing a different version to the current one. You may have to specify the version using [email protected]
you can't get the current version by running php -v if your php is broken :p
@gingerCodeNinja that's true, perhaps this might help: for Mac OS, go to terminal and run echo $PATH (if you have php, you should see something like this: /usr/local/opt/[email protected]/bin) this is one way to find out what versions are currently being used.
53

This fixed it for me:

brew upgrade node 

5 Comments

This worked for me as well. I never fully investigated it but I believe brew just fixed the dependencies as well while upgrading node. This felt a lot more contained in comparison to brew upgrade.
seems similar case, > 'brew reinstall node' did help me after switching to Catalina
Oddly enough, this /icu4c/lib/libicui18n.66.dylib error suddenly occurred when I was running rspec. I stashed my handful of code changes, error still showed up. upgrading node fixed the problem! Thank you!
Thanks :) I was about to try the other solutions - but this fixed my issue right away.
You saved me. Thank you
19

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.

1 Comment

this worked for me! npm install wasn't working after my work macbook force updated to Catalina last week. Found here originally: gist.github.com/berkedel/d1fc6d13651c16002f64653096d1fded
15

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:

  1. 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 
  1. Link libs:
ln -s /usr/local/icu4c/62.1/lib/*.dylib /usr/local/include/ 
  1. Set DYLD_LIBRARY_PATH in ~/.bash_profile:
export DYLD_LIBRARY_PATH=/usr/local/include 

6 Comments

I'm running PHP 7.1 and this was the only thing that worked for me.
In my case I needed the 64.2 version, so I downloaded it from github.com/unicode-org/icu/releases/download/release-64-2/…
After updating to OS Big Sur, icu4c 67 was missing, tried all kinds of solutions but this was the only one that worked. Downloaded it from github.com/unicode-org/icu/releases/download/release-67-1/… . Thank you!
for node@12 with [email protected] works via $ ln -sf /usr/local/Cellar/[email protected]/71.1/lib/*.dylib /usr/local/lib/
|
12

On mac, anything related to node was not working for me. Running this solved the problem:

brew reinstall node 

Comments

11

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 ) 

Comments

8

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

1 Comment

brew reinstall npm command solved my problem
8

2021-02 Easy solution

After years of dealing with this problem the following, surprisingly easy, solution worked for me:

  1. Open the raw file in your web browser of the version you need:

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

Latest version: https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/icu4c.rb

  1. Copy paste the contents into a new file named: icu4c.rb
  2. Run the following on the newly created file: brew reinstall icu4c.rb

Source: https://gist.github.com/hgrimelid/703691ab48c4a4d0537cfe835b4d55a6

1 Comment

I found a similar set of instructions, but it requires compiling the source: programmersought.com/article/34721476513, which worked for me.
8

For me it was appearing for node@12 And the following steps worked for me -

brew uninstall --ignore-dependencies icu4c brew install node 

which installed icu4c automatically and fixed the whole thing.

Comments

7

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.

Comments

7

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.

1 Comment

This did the trick for me after upgrading to mac OS 11.6 Big Sur. Thanks!
5

brew update && brew upgrade worked for me

1 Comment

Welcome to SO! Your collaboration is welcome. In this case, there are 15 more questions so it will be a good point to show the Pros of yours.
5

i followed this article here and this seems to be the missing piece of the puzzle for me:

brew uninstall node@8 

2 Comments

After trying every suggestion from different forms my error stopped after using this but now we have an issue regarding npm after reinstalling node
The accepted answer did not work for me. What did work for me was a variation of this answer: brew remove node && brew install node
5

Lots of answers around restoring the missing version of icu4c. I had this same error with postgresql and I imagine this can manifest with various programs that depend on dynamically linking that library.

For me, I'm using a specific version of postgresql, namely postgresql@12. I found the simplest fix was to reinstall that

brew reinstall postgresql@12 

I imagine that would work for php as well.

1 Comment

This solution worked for me after running brew reinstall postgresql@14, brew doctor and brew cleanup.
4

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 

Comments

4

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.

1 Comment

This worked for me. MacOS Montery, PostgreSQL 14.3
3

On MacOS Mojave, only way I could fix it was with brew upgrade

Comments

3

[2022 Build It Yourself Edition]

Works for me on Mac OS 11.6.8 Big Sur.

$ wget https://github.com/unicode-org/icu/releases/download/release-69-1/icu4c-69_1-src.tgz $ # In Finder, copy from Downloads/ to your home directory $ tar xzvf icu4c-69_1-src.tgz $ cd icu/source $ ./configure $ make $ make install 

After that, node and npm worked again.

References

1 Comment

this exact problem i am getting
3

This worked for me brew reinstall [email protected] // replace your version

Comments

2

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 [email protected] brew install --build-from-source [email protected] 

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.

2 Comments

Tried this but no improvement; Grey Black's brew switch icu4c 62.1 command worked for me, however.
note that php 7 formulae are no longer available, so once you uninstall 7.x it's gone for good
2

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.

1 Comment

after searching for a while, this is what helped me. Thanks
2

On OSX 10.15.4 running xcode-select --install fixed the issue for me.

Comments

2

The solution in this gist did it for me

brew uninstall --ignore-dependencies node icu4c brew install node 

Comments

2

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.