99

I've not run brew update && brew upgrade for a long time.

I just did a massive upgrade which turned out to broke my Vim.

This is what I got after running vim:

dyld: Library not loaded: /usr/local/opt/ruby/lib/libruby.2.3.0.dylib
  Referenced from: /usr/local/bin/vim
  Reason: image not found
Trace/BPT trap: 5

I've came across some websites but none of them were actually helpful.

They said that it might be related to rvm but brew uninstall vim; rvm system; brew install vim didn't help. I tried to reinstall my MacVim as well but it didn't solve the problem.

Adding export PATH="/usr/local/bin:$PATH" to my .bash_profile didn't help either.

Here's the list for future reference:

What happened to my Vim? How can I fix it?

11 Answers11

114

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.).
kenorb
  • 26,615
37

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!

10

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
Andy
  • 203
4

For me, I found that brew somehow installed macvim and it kept conflicting with OS stock vim. Attempts to use regular vim, and running git commands such as these produced errors:

$ git commit --amend
dyld: Library not loaded: /System/Library/Perl/5.16/darwin-thread-multi-2level/CORE/libperl.dylib
  Referenced from: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/MacOS/Vim
  Reason: image not found
error: vi died of signal 6
error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.

So I went ahead and uninstalled any vim-related packages that brew had installed:

$ brew list

And surely removing macvim with $ brew uninstall macvim solved the issue

kip2
  • 141
2

I tried reinstalling, relinking, removing all available versions etc. for ruby and vim but nothing really helped.

Thus, I just decided to rename my dylib file from

/usr/local/opt/ruby/lib/libruby.2.3.dylib

to

/usr/local/opt/ruby/lib/libruby.2.3.0.dylib

The result of that rename is that it works perfectly fine now.

Ueffes
  • 21
0

If you get a message like the following:

dyld: Library not loaded: /usr/local/opt/ruby/lib/libruby.2.4.1.dylib
  Referenced from: /usr/local/bin/vim
  Reason: image not found
error: vim died of signal 6
error: There was a problem with the editor 'vim'.
Please supply the message using either -m or -F option.

and you manage your Ruby using rvm, then properly setting one environment variable should get your vim back in action.

Follow these steps to see if it applies to your environment:

Is DYLD_LIBRARY_PATH defined and is it correct?:

$ env|grep DYLD_LIBRARY_PATH

Where is Ruby installed?

$ type ruby
ruby is hashed (/Users/<USER>/.rvm/rubies/ruby-2.4.1/bin/ruby)

That shows that my ruby is managed by rvm.

Where is libruby.2.4.1.dylib located?

find /Users/<USER>/.rvm/rubies/ruby-2.4.1  -name "*.dylib"

Add the "lib" directory and append it to your startup file:

echo -e "\nexport DYLD_LIBRARY_PATH=/Users/<USER>/.rvm/rubies/ruby-2.4.1/lib" >> ~/.bashrc

Note: Use which ever startup file (~/.profile, ~/bash_exports, etc.) that makes sense for your workstation.

Now, when you start a new terminal session, your vim should be working again.

l3x
  • 101
0

On my case it turns out ruby was installed but for reason not linked, so:

brew link ruby

kroe
  • 101
0

My Error (this occured after homebrew update):

dyld: Library not loaded: /usr/local/opt/ruby/lib/libruby.2.6.dylib Referenced from: /usr/local/bin/vim Reason: image not found [1] 2800 abort vim

This took an hour of my life. My solution:

Reinstall ruby $ brew reinstall ruby

Feedback from Homebrew:

ruby is keg-only, which means it was not symlinked into /usr/local, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH run: echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

For compilers to find ruby you may need to set: export LDFLAGS="-L/usr/local/opt/ruby/lib" export CPPFLAGS="-I/usr/local/opt/ruby/include"

For pkg-config to find ruby you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig" ==> Summary /usr/local/Cellar/ruby/2.6.3: 19,372 files, 32.4MB Error: Could not remove ruby backup keg! Do so manually: sudo rm -rf /usr/local/Cellar/ruby/2.4.2_1.reinstall

I followed homebrew's instructions and manually removed the ruby backup keg

$ sudo rm -rf /usr/local/Cellar/ruby/2.4.2_1.reinstall

After entering password and trying to open vim again with

$ vim

Vim opened and I smiled a bit and brushed away the frustration perspiration. :)

Pip
  • 111
0

As mentioned here, the following fixed it for me.

brew uninstall macvim && brew install macvim --HEAD

Also, after upgrading to macOS Catilina, I open X-Code in install necessary updates.

SyncMaster
  • 1,899
-1

I stopped using Homebrew because of all its problems and security issues.

In any case, I upgraded from OSX Yosemite to OSX High Sierra and macvim stopped working in Terminal. I got the error:

dyld: Library not loaded: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/libruby.2.0.0.dylib
  Referenced from: /Applications/MacVim.app/Contents/MacOS/Vim
  Reason: image not found
Abort trap: 6

I tried EXPORT'ing a path like in I3x's answer, but I still got the same error(yes, I opened a new Terminal window).

So, I downloaded macvim again. When I was told there was already a MacVim.app on my computer, I stopped the install, and I changed the name to MacVim_original.app. Then I proceed to install a new macvim. After that, macvim worked in Terminal again. I launch it with a shortcut command:

$ m 1.py 
7stud
  • 157
-1
brew uninstall --force ruby perl vim && brew install vim 

This is what worked for me.

Mark
  • 1