Homebrew - dyld not found - ruby

I run brew after a fresh install, and this is what I get:
dyld: Library not loaded: /usr/local/Cellar/ruby/1.9.3-p194/lib/libruby.1.9.1.dylib
Referenced from: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
Reason: image not found
I've tried most of the common fixes. Everything is up to date, and I'm using 1.9.3. Any help on this issue would be greatly appreciated.

I was getting this error after installing rvm and then running brew on Mac OSX. It seems as if the brew script targets a System version of ruby in the script, which wasn't mounted by rvm. All that I did was change this line:
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0
In my /usr/local/bin/brew file to this:
#!/Users/<my user name>/.rvm/rubies/ruby-1.9.3-p385/bin/ruby -W0
The location that rvm installed the version of ruby I was using (NOTE: I omitted my username in the snippet above, the path should be to a valid install of ruby on your system)
brew started to be happy after that.

Related

Updating Ruby Mac OS 10.6.8 Snow Leopard

I'm trying to install a more recent version of Ruby on Snow Leopard so I can install Jekyll. When trying to install any version of Jekyll I get an error saying that it requires liquid, which requires ruby v2+.
If I try upgrade via rbenv I get the following when trying all versions:
error: failed to download ruby-2.1.1.tar.bz2
BUILD FAILED (OS X 10.6.8 using ruby-build 20181019)
I've also installed Ruby manually from source but this isn't recognised by the system and I can't switch versions.
If i run rbenv global it only recognises the System version of Ruby.
When I try brew upgrade ruby I get the following error:
ruby 2.5.3_1 already installed
If I try link to the new version with brew I get the following error:
brew link --force --overwrite ruby#2.5.3_1
Error: No such keg: /usr/local/Cellar/ruby#2.5.3_1
RVM doesn't install so I'm not sure what to do next. Below are the details of the packages I have installed.
Xcode 3.2.2 (I cant get an installer working for any higher versions of Xcode). The more recent versions hosted by Apple for Snow Leopard are corrupt when downloaded.
rbenv 1.1.1
brew 1.8.4
ruby 1.8.7 (System)
You have (or had) a path issue. Before you did your follow up steps, if you had run which ruby you'd probably see it pointing to /usr/bin/ruby which is system ruby, not your homebrew ruby in /usr/local/bin/ruby.
You still need to, if you haven't already, add your export command to your ~/.bash_profile file to ensure your PATH gets updated for every terminal window you open.
I'm not sure what actually fixed this but I ran the following commands after reading other posts and now have Jekyll 3.8.3 installed and ruby 2.5.3p105.
sudo chown -R "$USER":admin /usr/local
export PATH=/usr/local/bin:$PATH
brew link --overwrite ruby --force
gem install jekyll

gem install - fatal error: 'ruby/config.h' file not found in Mojave

gem install is failing in MacOs Mojave. Anything that can help me solve this? My ruby version is ruby 2.3.7p456.
➜ sudo gem install json -v '1.8.3'
current directory: /Library/Ruby/Gems/2.3.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
In file included from ./../fbuffer/fbuffer.h:5:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
^~~~~~~~~~~~~~~
1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Update 15/03/2021
According to Apple, Ruby won't be included anymore in future versions of the system, so using a Ruby version manager will be the only way to go once this will actually happen.
Original answer
After hours and hours of trial and errors I wanted to go deeper into the reasons of this error and I finally found this that I think is the clean way to go around this issue:
Catalina (NdMe: I think this started earlier, on Mojave) no longer supports including macOS headers in command line
tools, they have to be explicitly used through Xcode SDK. You can do
so by running gem through the xcrun tool like:
xcrun gem install <your_gem>
Quoted from a Github issue comment.
Xcode 12 upgrade messed this up for me.
I installed ruby from brew and added this to my .zshrc
export PATH="/usr/local/opt/ruby/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
If you have the Xcode 10 beta running this might fix it
sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
In macOS Monterey (in the Beta at least), Ruby (ruby 2.6.3p62 (2019-04-16 revision 67580)) is still included but it doesn't seem to work well (fatal error: 'ruby/config.h' file not found), so I installed my own version of Ruby. You can install ruby manually, but I prefer to use rbenv, a Ruby version manager.
Install ruby using rbenv
Install rbenv: brew install rbenv ruby-build
ruby-build is a plugin for rbenv to actually install a ruby version, it provides ruby install command.
Setup rbenv: rbenv init, (and follow its recommended instructions, for example if you're using zsh, it says add eval "$(rbenv init -)" to ~/.zshrc)
Install ruby: rbenv install 3.0.1. Latest version listed here
Do what you came to do: sudo gem install cocoapods or bundle install
Or install ruby manually:
Run brew install ruby
Run echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc so that this version is used
Restart terminal
asdf?
An alternative to rbenv is asdf, but I find asdf a bit complicated to use, since it supports more than just ruby, NodeJS. I would argue it does none of them very ergonomically.
Note: I have an M1 mac, and it's still working.
I got into this issue when trying to install fastlane with homebrew. None of the suggestions mentioned earlier helped me. Manually installing the macOS_SDK_headers_for_macOS_10.14.pkg fixed it.
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
I was having this same issue where I could not install native extensions due to a failure when including "ruby/config.h".
I believe the cause of this issue was because I was using the ruby version installed with Homebrew. After upgrading to a new version of Ruby with Homebrew, I saw the following helpful message 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"' >> ~/.bash_profile
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"
Adding the following lines to my ~/.bash_profile fixed the issue for me:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
xcrun gem install <your_gem> worked for me, but I had to do it multiple times — every time bundle install failed.
The best solution is probably to set the same vars as xcrun in your .zshrc file. xcrun env on my system adds:
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPATH=/usr/local/include
LIBRARY_PATH=/usr/local/lib
I had this problem after installing Big Sur. I found the file ruby/config.h was not present in the Xcode Packages in the Xcode versions I had installed prior to upgrading. I was able to correct it by uninstalling the Xcode versions and reinstalling them.

How to fix "dyld: Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib" permanently for Ruby?

I updated my OS about 2 weeks ago, and since then I've been running into this issue:
> ruby -v
dyld: Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib
Referenced from: /Users/me/.rvm/rubies/ruby-2.2.1/bin/ruby
Reason: image not found
[1] 65487 trace trap ruby -v
A solution found here (Ruby -v dyld: Library not loaded: /usr/local/lib/libgmp.10.dylib) works for each terminal session, but not permanently. I am running OS 10.9.5.
This is what works temporarily:
rvm reinstall 2.1.4
This has no effect, other than update homebrew:
brew update && brew install gmp
How can I fix this permanently?
You probably need to reinstall ruby, gmp and rvm packages to fix the broken dependencies, e.g.
brew reinstall gmp rvm ruby
Consider running brew update && brew upgrade before.
Then reinstall ruby as:
rvm reinstall 2.1.4 --with-opt-dir=$(brew --prefix gmp) --disable-binary
Then check by:
ruby -v
Make sure you're using the right ruby (check by: which -a ruby), if not, setup the right order for PATH variable in your startup shell scripts (e.g. ~/.bash_profile).
Also make sure you're not overriding any DYLD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH or DYLD_FRAMEWORK_PATH variables from the startup shell scripts (e.g. ~/.bash_profile).
Related: Ruby installation issues with RVM.
A reinstall did it for me as well:
brew reinstall gmp ruby

Error loading RubyGems plugin ,openssl.bundle (LoadError)

I am new to ruby. When I type any thing related to gem, error below will happen. why causes it and how to solve the problem? Thanks!
Error loading RubyGems plugin "/Users/chiang/.rvm/gems/ruby-2.0.0-p247#global/gems/rubygems-bundler-1.2.2/lib/rubygems_plugin.rb": dlopen(/Users/chiang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin12.3.0/openssl.bundle, 9): Library not loaded: /opt/local/lib/libssl.1.0.0.dylib
Referenced from: /Users/chiang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin12.3.0/openssl.bundle
Reason: image not found - /Users/chiang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin12.3.0/openssl.bundle (LoadError)
Things to verify...
How did you install rvm
hit rvm notes and check if it's installed properly
ruby -v, check for the version of ruby present
If you find any issues here, uninstall rvm using rvm implode and also remove ruby. Refer to the rvm installation guide for the use of this command.
\curl -L https://get.rvm.io | bash -s stable --ruby
OR you can try the other way without removing the present rvm installation.
rvm get stable
rvm reinstall 2.0.0
Hope this helps.
The following worked for me.
brew rm openssl
brew cleanup openssl
brew install openssl
rvm reinstall ruby
Apparently brew update or brew upgrade breaks the Ruby runtime which is what caused the error for me.
To whoever having this problem with rbenv, I solved it reinstalling openssl and upgrading rbenv, then reinstalling ruby:
brew reinstall openssl
brew upgrade ruby-build rbenv
rbenv install 2.2.10 # or whatever version you're using it
Im assuming you already installed the right package aka brew install/reinstall openssl if not - do it.
Another Solution (In case your package is installed) - Might be that your package is not referenced to the right endpoint version, you have multiple versions of the same package (on this use-case openssl package) and your rvm is not finding it event though it's installed.
Run list of the package versions and switch to the right one.
example:
brew list --versions openssl
/* Output:
openssl 1.0.2s
openssl 1.2
openssl 1.3
*/
brew switch openssl 1.0.2s
Landed on this post in August '21 on Mojave using rbenv with this error:
Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
Reason: image not found - /.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin17/digest/md5.bundle
Found an answer that worked for me on this post
brew install rbenv/tap/openssl#1.0
ln -sfn /usr/local/Cellar/openssl#1.0/1.0.2t /usr/local/opt/openssl
(first command finished in ~5 minutes)
Coming from this GitHub Issue

Problems getting ruby-libvirt extensions to compile Mountain Lion

I bought a new Mac this week and have had big problems getting this gem installed. It was never a problem on my old Mac but seems to be particularly difficult on this one.
I have installed libvirt via Homebrew, Xcode4.4 (with command line tools) and gcc4.2. I have symlinked to make gcc4.2 the default compiler.
gem install ruby-libvirt -v '0.4.0' fails because it cannot find the headers
If I pass in the paths to the headers and libraries, like so:
ruby-libvirt -v '0.4.0' -V -- --with-libvirt-include=/usr/local/Cellar/libvirt/0.9.11.3/include/ --with-libvirt-lib=/usr/local/Cellar/libvirt/0.9.11.3/lib/
, it compiles just fine but fails when linking with the following errors:
linking shared-object _libvirt.bundle
ld: library not found for -lruby.1.9.1
collect2: ld returned 1 exit status
make: *** [_libvirt.bundle] Error 1
I have installed Ruby 1.9.3 via RVM and haven't had any troubles installing other native extensions, so I cannot see why it fails to find the ruby libraries in this case.
Does anyone have any ideas? Help would be much appreciated.
I built ruby-libvirt-0.4.0/ext/libvirt by proving external libvirt installed using brew.
Here is what I did to successfully install libvirt.
brew install libvirt
ruby extconf.rb --with-libvirt-include=/usr/local/include/libvirt --with-libvirt-lib=/usr/local/lib/libvirt
gem install ruby-libvirt -v '0.4.0' -V -- --with-libvirt-include=/usr/local/Cellar/libvirt/1.1.4/include/libvirt --with-libvirt-lib=/usr/local/Cellar/libvirt/1.1.4/lib
Hope this helps.
To install the gem you need to install the libvirt libraries. Using 'Homebrew' (a package manager for mac) :
brew install libvirt
bundle install
The exact error you got might have been:
An error occurred while installing ruby-libvirt (0.4.0)
I have finally solved this. It turns out that the command line tools were not properly installed. The following line needs to be added to your .zshrc file (or whatever applies to your choice of shell):
export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH
You need only to install libvirt, before the bundle install.
brew install libvirt

Resources