brew upgrade broke Vim on OS X (dyld: Library not loaded)

Solution

Try to reinstall ruby and vim, e.g.

brew reinstall ruby vim

Troubleshooting

Here are other suggestions if above won't help:

  • Find any references to DYLD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH or DYLD_FRAMEWORK_PATH environmental variables and remove them from the startup shell scripts (e.g. ~/.bashrc, ~/.bash_profile, etc.).

tl;dr

brew link --overwrite ruby

Details

Actually, it turned out to be quite simple. I followed the suggestion to run brew doctor and I got these results:

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
    ruby

So I ran brew link ruby. This is what I got:

Linking /usr/local/Cellar/ruby/2.3.1... v
Error: Could not symlink bin/rake
Target /usr/local/bin/rake
already exists. You may want to remove it:
  rm '/usr/local/bin/rake'

As a result I decided to run brew link --overwrite ruby and now my Vim is working once again!


I ran into a similar error when doing brew upgrade where libperl doesn't get loaded.

dyld: Library not loaded: /usr/local/opt/perl/lib/perl5/5.24.1/darwin-thread-multi-2level/CORE/libperl.dylib
  Referenced from: /usr/local/Cellar/vim/8.0.0636/bin/vim
  Reason: image not found

Fix was to reinstall the broken dependency and vim:

brew uninstall --ignore-dependencies perl
brew uninstall vim
brew install vim