636

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

the
  • 21,007
  • 11
  • 68
  • 101
petekaner
  • 8,071
  • 5
  • 29
  • 52
  • Did you also install php from Homebrew? Did you try to reinstall php? – Ortomala Lokni Dec 18 '18 at 20:14
  • 5
    For posterity: uninstall/reinstall yarn/node seems to do the trick. – Nathaniel Ford Feb 14 '19 at 07:31
  • 37
    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. – sh6210 Feb 17 '19 at 14:38
  • 13
    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. – Seth Johnson Feb 16 '21 at 14:43
  • I have a weird situation (using High Sierra on an outdated machine) but this occurred after I updated PHP to 7.2 (or tried to). My solution was to reinstall node from a download. Homebrew isn't reliable once you're out of the range of MacOSs supported by Apple, I find. – David Rhoden Jun 02 '21 at 02:06
  • just running `brew upgrade` helped me – Maxim Yefremov May 28 '22 at 19:41
  • I came here due to problem with yarn which came from homebrew. None of the mentioned solution work, and finally I fixed it by installing yarn via nvm – gerrytan Aug 09 '22 at 04:55
  • Lots of outdated solutions here, unfortunately. I wrote about what I was able to do that solved it. Short version: Create a custom `new-tap` so you can `extract` the old formula and reinstall it from source, then manually symlink the new version over - https://gist.github.com/romellem/dcaba2d57d246420f600b7cfeb4b0cdd – romellem Sep 29 '22 at 02:55
  • Adding to @sh6210, I had to do brew upgrade -f to force the upgrade past an issue of a non-empty directory not deleting, but end result was same: fixed. – brianfit Jan 14 '23 at 12:19
  • Refer to [this answer](https://stackoverflow.com/a/67488727/529403), replacing the version number with your needs. – Ricardo Martins Jan 17 '23 at 00:25
  • This can happen if you run a different version of node (e.g. in an IDE) to that which created the `node_modules` – Rich May 28 '23 at 08:45

39 Answers39

967

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
Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116
Full Stack Alien
  • 11,244
  • 1
  • 24
  • 37
  • This worked for me after running `brew link npm....` command which seems to have borked composer, php, etc. – aubreypwd Apr 17 '19 at 15:05
  • @VincentTang what has npm to do with it? Where did you run this? – evolutionxbox Apr 26 '19 at 09:40
  • 19
    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. – mold May 02 '19 at 19:11
  • Good for me! After a Rails problem. – iGian May 27 '19 at 20:59
  • @mpoletto It is a good idea to stay current (for security) and homebrew provides tools to set an older version of one library without putting the entire environment, your users, and your system at risk. If you want to use an older php, it should not come at the cost of throwing the entire system in a time capsule. – Abandoned Cart Jun 07 '19 at 19:58
  • @AbandonedCart I was thinking in a developing environment, only in my machine... Imagine that I have two totally distinct systems in two production environments, one with PHP 5.6 and another with PHP 7.2. I am using my machine to develop sometimes to system 5.6 as another times to 7.2. – mold Jun 11 '19 at 21:01
  • @mpoletto Nothing you have presented is a reason why my suggestion is not possible. You really shouldn't have production systems that are intentionally outdated without good cause. – Abandoned Cart Jun 11 '19 at 22:51
  • Clever but didn't work for me, on the other hand a reinstall of php7.2 also didn't work on my system so that's probably the reason why ... – leo Jun 23 '19 at 09:08
  • 57
    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 Jul 16 '19 at 19:50
  • 2
    @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! – Full Stack Alien Jul 16 '19 at 23:53
  • 1
    @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. – Vishnu Narang Mar 29 '20 at 19:28
  • 1
    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. – Leo Fisher Apr 16 '20 at 02:47
  • I saw `brew upgrade` and disliked immediately. – tom10271 May 28 '20 at 06:52
  • I did this and ended up with half a day of package cleanup to get my development environment back. Not a good idea for most cases. – Joey Jul 13 '20 at 16:51
  • @Joey I'm sorry to hear that! I know this solution helped me and has helped others. If there is anything I should include in this answer to make sure that doesn't happen to someone else, let me know! – Full Stack Alien Jul 13 '20 at 17:51
  • For me, only `brew cleanup` was needed as I already did a `brew upgrade` and this error was the result of that with node. – Jonathan Bird Nov 16 '20 at 04:10
  • 1
    @AbandonedCart I voted negative because I thought this command dangerous for beginners. It's like estimulating Linux beginners to use rm -rf. Sorry, my opinion. – mold Jan 08 '21 at 21:32
  • 1
    @mpoletto no worries! I try to give the appropriate warnings in the answer so anyone considering the solution would understand the impact. – Full Stack Alien Jan 09 '21 at 00:12
  • @mpoletto I appreciate your concern for beginners, even if I am not sure why I was tagged. – Abandoned Cart Jan 09 '21 at 23:42
  • @AbandonedCart Sorry, but it doesn't appear or I can't see where I tagged you. – mold Jan 12 '21 at 14:32
  • This is a terrible response. Way too general. People who know what they're doing can get general solution out of specific solution, but people who don't know what they're doing can't get specific solution out of general solution like this. – J.Ko Apr 12 '21 at 18:28
  • @J.Ko you aren't completely wrong, but is not a good solution one that works? This error can occur due to a variety of brew issues and it seems to have helped get at least a few people unstuck. If you have a better solution I will happily upvote your answer. – Full Stack Alien Apr 12 '21 at 20:10
  • 1
    @VimDiesel I don't have a solution. That's why I'm here looking for one. The one below this by Grey Black worked. – J.Ko Apr 13 '21 at 22:09
  • `brew upgrade` worked for me, I didn't need the cleanup – abumalick Apr 29 '21 at 09:22
  • `brew cleanup` worked for me but I also had to do a `brew update-reset` to fix brew afterward, as in [this answer to another question](https://stackoverflow.com/a/54913258/1399438). – StockB May 05 '21 at 17:11
  • @xgMz thank you, `brew upgrade npm` works for me after cleanup – Prabowo Murti Nov 17 '21 at 04:22
  • I am in the same situation as @mpoletto, and I had one version of PHP pinned. SO for my this is what worked :`brew unpin php@7.4 && brew upgrade php@7.4 && brew pin php@7.4` – giuliot Mar 07 '22 at 06:58
  • It worked for me, though it's wise as advised to consider that it would end up upgrading all you brew-dependent packages. In my case the upgrade did no harm, and I was able to run my react-native project again. – Okpo Mar 24 '22 at 08:03
  • @AbandonedCart, let me consider about two things: 1) you can, eventually, need to maintain old versions in production as the real life is not a ideal life where you can do the most apropriate thing you would like to do - there are some legacy systems that need to stay running until you can upgrade to a better secure version of it; 2) beside this, without a notice (the author updated the answer), there wasn't danger only for begginers - and I can't realize why you were worried about if you didn't produced the answer. – mold Jan 18 '23 at 17:27
  • 1
    @Havingalifeonabeach Despite what you may think, I have not been holding my breath the last two years for a response. My reasoning, along with any argument you may have, is obsolete. I suggest moving on. – Abandoned Cart Jan 18 '23 at 17:50
  • `brew reinstall icu4c` worked for me. – Viral Lalakia Jan 25 '23 at 10:50
328

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.

Simone
  • 20,302
  • 14
  • 79
  • 103
Grey Black
  • 3,355
  • 1
  • 6
  • 6
  • 1
    This is exactly what happened to me as well, and you got me on the right track. The major caveat to this approach is that you have to have previously installed this version. I worked around this in my answer – Leland Jan 20 '19 at 03:04
  • 22
    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. – Steven Ensslen Feb 28 '19 at 02:34
  • 4
    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... – Andrew Apr 09 '19 at 23:31
  • 37
    I ended up running `brew reinstall postgres` and that seemed to solve my problems – Andrew Apr 10 '19 at 07:46
  • 1
    Helps switch to `icu4c 61.1`. `63.1` - not solve. `62.1` - not found. – Pavel Petrovich Apr 13 '19 at 11:08
  • Thanks @grey-black it worked for me I am using following MacOS Mojave version 10.14.4 (18E226) – Sangam Pandey May 22 '19 at 06:30
  • 1
    @ApoorvParijat `62.1` is only what Grey Black had installed, not part of a literal command for every user on every system. – Abandoned Cart Jun 07 '19 at 19:53
  • Magic. Helped with 6.4 -> 6.3 – Azee Jun 11 '19 at 05:07
  • And I ended up with `brew reinstall php@7.2` – Rafał R Oct 02 '19 at 21:07
  • Explicitly switching to the already installed compatible version did the trick for me. postgres was looking for v64. v64 was indeed installed, it still cribbed with image not found error, but, started working when I explicitly set it to v64 – darkdefender27 Nov 18 '19 at 17:28
  • Worked for me but I think you mean "Where version is the version number in the 'Library not loaded' message." 62 in the OP's case. 64.2 in my case. – Rooster242 May 19 '20 at 20:02
  • 28
    Unfortunately brew switch no longer available. – zenon Apr 09 '21 at 04:42
  • 24
    The new `brew switch` command is `brew link` – Simone Apr 08 '22 at 14:43
  • I also had to do "brew upgrade postgresql" – William Stein Sep 29 '22 at 05:36
143

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
Kevin
  • 25,946
  • 2
  • 19
  • 21
Kevin Elliott
  • 2,630
  • 3
  • 23
  • 21
  • 1
    This is actually the best solution if, ```brew switch icu4c 62.1``` doesn't work for you in the first instance. – saberprashant Jan 08 '20 at 13:08
  • 30
    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` – John Kary Apr 23 '20 at 20:35
  • This was exactly the solution i was looking for. I was having issues with a valet-php version still using an older version of icu4c whereas brew updated to a newer one. – Kozie Apr 24 '20 at 13:01
  • In my case, this are better than reinstall PHP, because I have Oracle OCI, that is a pain to reinstall. Thanks – RafaelQm May 13 '20 at 05:19
  • 2
    Unfortunately **brew upgrade** removes older linked version and for people who still wanna use new version and keep brew up to date: 1)Use mentioned command to install older version 2)Copy 64.2 dir from **/usr/local/Cellar/icu4c/** somewhere locally 3)Run `brew upgrade` to install latest version of icu4c 4)Copy saved dir in to the **/usr/local/Cellar/icu4c/** 5)Now you can switch between versions: `brew switch icu4c 64.2` – Ilia Rebane May 26 '20 at 17:59
  • 3
    For icu4c **66**: `brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/22fb699a417093cd1440857134c530f1e3794f7d/Formula/icu4c.rb` – Magnus Jun 04 '20 at 21:18
  • 1
    For icu4c 67: brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/88b9cc789820f2f544d8d4a1053eebb044c2926c/Formula/icu4c.rb – Richard Frank Jun 09 '20 at 05:05
  • 10
    This doesn't work anymore. It asks you to `brew extract` – brunouno Sep 18 '20 at 01:53
  • 5
    @brunouno You need to download the .rb file and do: `brew reinstall icu4c.rb` – Patrick Fabrizius Nov 03 '20 at 15:23
  • 1
    version **67.1**: https://raw.githubusercontent.com/Homebrew/homebrew-core/8e4cfd6b1bc8b1f02b67d3bc5f98c7fe5ad2fb8c/Formula/icu4c.rb – Obed Parlapiano Mar 24 '21 at 14:22
  • It's generally recommended to go off specific versions, but adding this as another option (using master/latest). ```wget https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/icu4c.rb; brew reinstall icu4c.rb``` – Matt Kenefick May 13 '21 at 14:23
  • It did not worked for me, fixed by this new wonderful php tap: https://github.com/shivammathur/homebrew-php – palmic May 18 '21 at 11:41
  • 4
    Simple running `brew reinstall icu4c worked for me. Thanks for leading me in the right direction! – Joel Mellon Oct 01 '21 at 23:03
  • 1
    This solution worked for me. I ran ```curl https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/icu4c.rb -o icu4c.rb; brew reinstall icu4c.rb``` and that fixed the issue. – Mike T Nov 23 '21 at 19:30
  • 1
    `brew reinstall icu4c` worked for me – emmaakachukwu Sep 13 '22 at 10:04
99

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

Lucas Bustamante
  • 15,821
  • 7
  • 92
  • 86
  • 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. – free2idol1 Feb 16 '23 at 04:00
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 the Homebrew repo. This may take a while: git -C $(brew --repo homebrew/core) fetch --unshallow
  2. brew log icu4c to track down a commit that references 62.1; 575eb4b does the trick.
  3. cd $(brew --repo homebrew/core)
  4. git checkout 575eb4b -- Formula/icu4c.rb
  5. brew uninstall --ignore-dependencies icu4c
  6. brew install icu4c You should now have the correct version of the dependency! Now just to...
  7. git reset && git checkout . Cleanup your modified recipe.
  8. 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

Leland
  • 2,019
  • 17
  • 28
  • When I do `brew log icu4c`, there's only 3-4 results. None mention 62.1. The hash you use above doesn't work either. Have they removed 62? – Noah Feb 07 '19 at 15:14
  • 2
    You should first do `git -C (brew --repo homebrew/core) fetch --unshallow` to make sure you have a full brew git history. – Noah Feb 07 '19 at 17:03
  • 4
    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. – gedijedi Feb 19 '19 at 14:36
  • For me, I needed an even older version of icu4c. Applying these steps but searching for an older commit worked. To see which version you need, check the file in your error msg: `libicui18n.61.dylib` - in my case this meant I needed v.61. – TheKarateKid Mar 04 '19 at 22:43
  • Worked for me except I had to use `git -C "$(brew --repo homebrew/core)" fetch --unshallow` for step #1 – Jason Mar 11 '19 at 13:15
  • 5
    In my case I've needed icu4c v63, so the related commit to checkout is [bc0c97952453ff6afc146aa3a706e9902aba4300](https://github.com/Homebrew/homebrew-core/commit/bc0c97952453ff6afc146aa3a706e9902aba4300). The git command is `git checkout bc0c97952453ff6afc146aa3a706e9902aba4300 -- Formula/icu4c.rb` and then `brew switch 63.1` – nahuelhds Apr 23 '19 at 14:43
  • @gedijedi I recently installed ffmpeg and encountered the same error. Performing an update (`brew upgrade`) resolved the issue automatically and `brew switch` restored the php version I was using. No need to DIY a whole installation. – Abandoned Cart Jun 07 '19 at 20:03
  • I believe there's an easier way to do this (install a "previous" version of something via bew) ... this SO post worked simply and flawlessly for me: https://stackoverflow.com/a/55828190 – leo Jun 23 '19 at 09:14
  • Remeber to do ``` brew update``` before ```brew install icu4c```. As well, fetch the unshallow the command shown does not work, so what I did was cd $(brew --repo homebrew/core) then fetch --unshallow – Obromios Aug 24 '19 at 22:04
  • I don't know why but it installed the 64.1 version again instead of 62.1. I think ```brew update``` is required before installing it again. – saberprashant Jan 08 '20 at 13:04
  • this worked for me (like a charm!) thanks a lot! I was looking for version 64 (without a minor) I found (searching manually in GitHub) this commit: `896d1018c7a4906f2c3fa1386aaf283497db60a2` which references version "64.2" but it worked! php@5.6 is now working! – Khaleesi Jul 09 '20 at 20:56
  • 2
    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 https://github.com/Homebrew/homebrew-core/commit/88b9cc789820f2f544d8d4a1053eebb044c2926c. – bluepanda May 04 '21 at 19:35
  • It did not worked for me, fixed by this new wonderful php tap: https://github.com/shivammathur/homebrew-php – palmic May 18 '21 at 11:41
  • 1
    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: https://gist.github.com/bbatsche/c1c747bb9297661772ae7e106c556c3f. I used `wget` to pull the file and then `brew reinstall Icu4c@64.rb` followed by `brew link Icu4c@64`. I'll now retire to the simplicity of my archlinux box :) – starfry Dec 08 '21 at 16:43
  • `fatal: --unshallow on a complete repository does not make sense` ‍♂️ and just running `git -C $(brew --repo homebrew/core)` shows git help and doesn't do anything – Nico Brenner Dec 30 '21 at 22:52
69

For me the solution was to:

brew reinstall icu4c

Then

gem uninstall charlock_holmes
gem install charlock_holmes
Dorian
  • 7,749
  • 4
  • 38
  • 57
62

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 php@7.1

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.

Arun Karnati
  • 1,027
  • 8
  • 9
  • 17
    I got the same error running `node` after upgrading macOS to `10.14.2`, `brew reinstall node` was the ticket for me too – gnmerritt Dec 19 '18 at 03:36
  • I started getting this error after installing a new package with brew. Doing `brew upgrade` fixed it for me. – samurai jack Jan 08 '19 at 23:34
  • 2
    `brew reinstall php` may end up installing a different version to the current one. You may have to specify the version using `php@7.1` – Ryan Mar 14 '19 at 04:58
  • 8
    you can't get the current version by running `php -v` if your php is broken :p – gingerCodeNinja May 23 '19 at 17:55
  • 1
    @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/php@7.2/bin`) this is one way to find out what versions are currently being used. – Arun Karnati May 30 '19 at 20:39
43

This fixed it for me:

brew upgrade node
sed
  • 5,431
  • 2
  • 24
  • 23
  • 1
    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. – hendrikbeck Oct 14 '19 at 14:07
  • 2
    seems similar case, > 'brew reinstall node' did help me after switching to Catalina – greencrest Nov 21 '19 at 15:29
  • 1
    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! – Jon Kern Jan 24 '21 at 05:19
  • 1
    Thanks :) I was about to try the other solutions - but this fixed my issue right away. – Nick Taras Mar 08 '21 at 23:04
16

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 php@7.1 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.

  • this worked for me! `npm install` wasn't working after my work macbook force updated to Catalina last week. Found here originally: https://gist.github.com/berkedel/d1fc6d13651c16002f64653096d1fded – Kingsley Apr 19 '21 at 13:21
14

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
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 3
    I'm running PHP 7.1 and this was the only thing that worked for me. – WebTigers Apr 06 '20 at 19:37
  • In my case I needed the 64.2 version, so I downloaded it from https://github.com/unicode-org/icu/releases/download/release-64-2/icu4c-64_2-src.tgz – RafaelQm May 13 '20 at 05:56
  • 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 https://github.com/unicode-org/icu/releases/download/release-67-1/icu4c-67_1-src.tgz . Thank you! – Sabine Jan 02 '21 at 16:35
  • 1
    This was moved to here: https://github.com/unicode-org/icu/releases/download/release-62-2/icu4c-62_2-src.tgz – Maros Apr 23 '21 at 23:06
  • for `node@12` with `icu4c@71.1` works via `$ ln -sf /usr/local/Cellar/icu4c@71.1/71.1/lib/*.dylib /usr/local/lib/` – Marslo Jun 26 '23 at 22:41
10

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 )
glajan
  • 101
  • 1
  • 2
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

crifan
  • 12,947
  • 1
  • 71
  • 56
6

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.

Callum M
  • 1,635
  • 19
  • 27
6

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

Laurence Cooper
  • 1,215
  • 1
  • 12
  • 21
  • I found a similar set of instructions, but it requires compiling the source: https://www.programmersought.com/article/34721476513/, which worked for me. – J.D. Pace Mar 11 '21 at 00:57
6

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.

Ygnaaac
  • 69
  • 1
  • 2
6

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.

Mr. Robot
  • 139
  • 1
  • 9
5

brew update && brew upgrade worked for me

Simson
  • 3,373
  • 2
  • 24
  • 38
Sanjok Dangol
  • 149
  • 3
  • 8
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
Taher
  • 11,902
  • 2
  • 28
  • 44
4

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

brew uninstall node@8
Nhan
  • 3,595
  • 6
  • 30
  • 38
gmansour
  • 889
  • 8
  • 8
  • After trying every suggestion from different forms my error stopped after using this but now we have an issue regarding npm after reinstalling node – Pratik Khadka Aug 22 '20 at 18:14
  • 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` – Joshua Richardson Aug 09 '21 at 00:12
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.

Muzammil Baloch
  • 176
  • 3
  • 14
3

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

3

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.

steve
  • 3,276
  • 27
  • 25
  • This solution worked for me after running `brew reinstall postgresql@14`, `brew doctor` and `brew cleanup`. – timgavin Apr 20 '23 at 18:33
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 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 php@7.2 for my environment.

Jerry
  • 3,391
  • 1
  • 19
  • 28
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.

Matt Rink
  • 345
  • 2
  • 12
2

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

Winter Faulk
  • 413
  • 4
  • 9
1

Leland's answer worked for me, but I had to change steps 4 and 6 to:

4) git checkout -B icu4c-62.1 575eb4b

6) brew reinstall Formula/icu4c.rb

sgrwg
  • 11
  • 1
1

The solution in this gist did it for me

brew uninstall --ignore-dependencies node icu4c
brew install node
mokagio
  • 16,391
  • 3
  • 51
  • 58
1

In my case, brew update icu4c to version 67.1 so my php7.1 doesn't work. Just reinstall icu4c, then it fine.

Ref this: https://devhoi.com/threads/error-dyld-library-not-loaded-usr-local-opt-icu4c-lib-libicui18n-64-dylib-with-php7-1.26/

Huy Phan
  • 81
  • 2
  • i simply re-installed php 7.3 which is what was broken and it fixed it also. This guide pointed me in the right direction though. – Nate S Jul 08 '20 at 01:29
1

[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

0

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.

0

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
Taher
  • 11,902
  • 2
  • 28
  • 44
0

[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:

  1. 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
  1. [yourUsername]/homebrew-versions/Formula/
  2. Place downloaded file to 'Formula' folder
  3. brew tap [yourUsername]/homebrew-versions
  4. brew install [yourUsername]/homebrew-versions/icu4c
  5. 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: gettext@0.20.2.rb Class name is: GettextAT0202 Example: https://github.com/nedap/homebrew-versions

source:https://itnext.io/how-to-install-an-older-brew-package-add141e58d32

mialdi98
  • 58
  • 7
  • If you got an error, try to install from source: //1. download file (for example, for 67) wget https://raw.githubusercontent.com/Homebrew/homebrew-core/88b9cc789820f2f544d8d4a1053eebb044c2926c/Formula/icu4c.rb //2. Find link to archive inside file 'cat icu4c.rb' //3. Download archive and install from source like https://stackoverflow.com/a/55024755/3126078 – Max Lipsky Jul 04 '21 at 20:16
0

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 php@7.1)

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
0

I solved int by updating all the R packages:

update.packages(checkBuilt = TRUE, ask = FALSE)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Freeman
  • 5,810
  • 3
  • 47
  • 48
0

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.

akkez
  • 13
  • 3
0

None of these answers were applicable to my fix which was running a dev server with node in a repo where it formerly worked.

I saw a few people mentioning reinstalling node or deinstalling certain versions but I'd like to point out that you can try switching versions of node using nvm install/use <version>. My system node had switched somehow and switching back to version 8 worked for me.

saylestyler
  • 389
  • 1
  • 4
  • 20
0

I tried in different ways but the only one currently worked for me was to edit the local brew icu4c formula and rebuild it.

I got the idea by opening the JSON in the formula description.

https://github.com/Homebrew/homebrew-core/blob/8738720eadff2f4e16b49ac05067b1498d4b078e/Formula/icu4c.rb

I saw that there is a direct link to the github icu4c release.

I changed it with the needed version and then when I tried to build it I get an error related to the sha256 number.

The correct one is suggested directly in the console. copy paste the correct one in the local formula and try to build again.

In my case asked me to update Xcode and to download a needed package, I simply followed what it was asking for and then as last step I had to run this command

sudo xcodebuild -license accept

to accept the licence.

Here the steps:

brew edit icu4c

change these lines

url "https://github.com/unicode-org/icu/releases/download/release-72-1/icu4c-72_1-src.tgz"
version "72.1"
sha256 "a2d2d38217092a7ed56635e34467f92f976b370e20182ad325edea6681a71d68"

with the needed version:

url "https://github.com/unicode-org/icu/releases/download/release-71-1/icu4c-71_1-src.tgz"
version "71.1"
sha256 "67a7e6e51f61faf1306b6935333e13b2c48abd8da6d2f46ce6adca24b1e21ebf"

save and then

brew reinstall --build-from-source /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/icu4c.rb
-1

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

pcambra
  • 661
  • 9
  • 15
-3

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