42

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?

  • Now perhaps you could try: xcode-select --install and then brew upgrade, as suggested in section Upgrading macOS at Common Issues – taper Nov 10 '17 at 12:12
40

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.).
  • 3
    Just upgraded to high sierra and this did the trick! Thanks. – e_x_p Sep 27 '17 at 20:19
  • 1
    I was having the issue with mac vim so I used this one instead brew reinstall ruby macvim and worked like a charm :) – Crisoforo Gaspar Dec 17 '17 at 5:02
  • 6
    After upgrading to high sierra I ran brew update and brew upgrade, which upgraded a lot of software to the high sierra versions and fixed my issue. – maffo Dec 21 '17 at 8:29
25

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!

  • 2
    Damn brew upgrade does this crap to me a lot. Thank you very much for offering a clear set of instructions to fix this. – Sukima Jul 15 '16 at 14:02
6

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

  • This was my issue as well. Great answer; thanks! – rotarydial Oct 24 '18 at 19:30
1

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.

  • You might want to consider using a symlink here instead of renaming the file, so that anything that referenced libruby2.3.dylib doesn't break too. – Derwent Feb 26 '18 at 2:04
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.

0

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

brew link ruby

0

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 
  • When making statements like “all the problems and security issues,” consider including links to documentation thereof. (= – ELLIOTTCABLE Dec 11 '17 at 0:34
  • google.com. – 7stud Dec 11 '17 at 8:02
  • Er. enjoy your downvote, then. I'm simply offering an explanation of why you got one, as is an accepted practice (just like citing your sources) here on Stack Exchange. ¯\_(ツ)_/¯ – ELLIOTTCABLE Dec 15 '17 at 2:16
-1
brew uninstall --force ruby perl vim && brew install vim 

This is what worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.