Solvedhomebrew core Upgrading to Ruby 2.4.1_1 breaks gem command.

  • Ran brew update and retried your prior step?
  • Ran brew doctor, fixed as many issues as possible and retried your prior step?
  • Confirmed this is a problem with specific formulae and not Homebrew/brew? If it's a general Homebrew/brew problem please file this issue at https://github.com/Homebrew/brew/issues/new

After upgrading Ruby to latest 2.4.1_1 formula, gem command no longer works and gives the following error:

/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/yaml.rb:5:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
/usr/local/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': dlopen(/usr/local/lib/ruby/gems/2.4.0/gems/psych-2.2.4/lib/psych.bundle, 9): Library not loaded: /usr/local/opt/ruby/lib/libruby.2.4.0.dylib (LoadError)
  Referenced from: /usr/local/lib/ruby/gems/2.4.0/gems/psych-2.2.4/lib/psych.bundle
  Reason: image not found - /usr/local/lib/ruby/gems/2.4.0/gems/psych-2.2.4/lib/psych.bundle
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/lib/ruby/gems/2.4.0/gems/psych-2.2.4/lib/psych.rb:8:in `<top (required)>'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/yaml.rb:6:in `<top (required)>'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems.rb:700:in `load_yaml'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/config_file.rb:340:in `load_file'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/config_file.rb:202:in `initialize'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/gem_runner.rb:75:in `new'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/gem_runner.rb:75:in `do_configuration'
	from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/gem_runner.rb:40:in `run'
	from /usr/local/bin/gem:21:in `<main>'

I tried both

brew reinstall -s libyaml

and

brew reinstall -s ruby

but none of them resolved the issue.

Could anyone help me fix this?
Many thanks.

28 Answers

✔️Accepted Answer

Oh hey! That solved it! So both:

rm -rf /usr/local/lib/ruby/gems/2.4.0/gems/psych-2.2.4

and

rm -rf /usr/local/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0/psych-2.2.4

seems to do the trick! Thanks!!

Other Answers:

Worked for me too!

rm -rf /usr/local/lib/ruby/gems/
brew uninstall ruby --ignore-dependencies
brew install ruby

More Issues: