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

51

11

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?

Mateusz Piotrowski

Posted 2016-07-03T16:55:44.873

Reputation: 2 768

Now perhaps you could try: xcode-select --install and then brew upgrade, as suggested in section Upgrading macOS at Common Issues

– taper – 2017-11-10T12:12:23.830

Answers

27

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!

Mateusz Piotrowski

Posted 2016-07-03T16:55:44.873

Reputation: 2 768

2Damn brew upgrade does this crap to me a lot. Thank you very much for offering a clear set of instructions to fix this. – Sukima – 2016-07-15T14:02:35.210

Didn't work for me after upgrading to Catalina: Warning: Refusing to link macOS-provided software: ruby – Cory Klein – 2019-11-19T00:36:32.413

52

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

Posted 2016-07-03T16:55:44.873

Reputation: 16 795

3Just upgraded to high sierra and this did the trick! Thanks. – e_x_p – 2017-09-27T20:19:42.283

1I was having the issue with mac vim so I used this one instead brew reinstall ruby macvim and worked like a charm :) – Crisoforo Gaspar – 2017-12-17T05:02:49.480

6After 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 – 2017-12-21T08:29:49.647

7

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

Posted 2016-07-03T16:55:44.873

Reputation: 173

1My error was related to the ruby library in the op but after trying a few linking fixes, I found that I needed to uninstall/install vim. I had recently updated ruby. – jerome – 2018-04-18T18:47:29.760

I found these same steps here https://github.com/Homebrew/brew/issues/2356#issuecomment-301830565 and it worked.

– gabe – 2019-01-19T19:08:15.310

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

Posted 2016-07-03T16:55:44.873

Reputation: 141

This was my issue as well. Great answer; thanks! – rotarydial – 2018-10-24T19:30:53.790

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.

Ueffes

Posted 2016-07-03T16:55:44.873

Reputation: 11

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 – 2018-02-26T02:04:35.853

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

Posted 2016-07-03T16:55:44.873

Reputation: 101

0

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

brew link ruby

kroe

Posted 2016-07-03T16:55:44.873

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

Posted 2016-07-03T16:55:44.873

Reputation: 111

-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

Posted 2016-07-03T16:55:44.873

Reputation: 127

1When making statements like “all the problems and security issues,” consider including links to documentation thereof. (= – ELLIOTTCABLE – 2017-12-11T00:34:28.477

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 – 2017-12-15T02:16:43.593

-1

brew uninstall --force ruby perl vim && brew install vim 

This is what worked for me.

Mark

Posted 2016-07-03T16:55:44.873

Reputation: 1