dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac

前端 未结 27 1321
孤城傲影
孤城傲影 2020-11-27 09:02

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 lo         


        
相关标签:
27条回答
  • 2020-11-27 09:46

    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

    0 讨论(0)
  • 2020-11-27 09:47

    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

    0 讨论(0)
  • 2020-11-27 09:47

    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.

    0 讨论(0)
  • 2020-11-27 09:48

    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.

    0 讨论(0)
  • 2020-11-27 09:49

    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 the installed version returned by info

    0 讨论(0)
  • 2020-11-27 09:51

    brew update && brew upgrade worked for me

    0 讨论(0)
提交回复
热议问题