Ruby gems path issue (system vs brew) - ruby

I'm having an issue with homebrew looking to the system gems when the system gems aren't in the $PATH.
Here is my gem env to show that my gems are installed in my .rvm/gems directory:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.5
- RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x86_64-darwin14]
- INSTALLATION DIRECTORY: /Users/scott/.rvm/gems/ruby-2.2.2
- RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
- EXECUTABLE DIRECTORY: /Users/scott/.rvm/gems/ruby-2.2.2/bin
- SPEC CACHE DIRECTORY: /Users/scott/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/2.2.2/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-14
- GEM PATHS:
- /Users/scott/.rvm/gems/ruby-2.2.2
- /Users/scott/.rvm/gems/ruby-2.2.2#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://gems.github.com"]
- :benchmark => false
- "gem" => "--no-ri --no-rdoc"
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gems.github.com
- SHELL PATH:
- /Users/scott/.rvm/gems/ruby-2.2.2/bin
- /Users/scott/.rvm/gems/ruby-2.2.2#global/bin
- /Users/scott/.rvm/rubies/ruby-2.2.2/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /opt/X11/bin
- /Users/scott/.rvm/bin
- /Users/scott/.composer/vendor/bin
- /usr/local/sbin
Now here is the error message I keep getting on various commands (this in particular was from brew services start httpd22):
Error: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin14.3.0/ports/libxml2/2.8.0... OK
Running 'compile' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-apple-darwin14.3.0/ports/libxml2/2.8.0/compile.log' to see what happened.
/Library/Ruby/Gems/2.0.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:265:in `block in execute': Failed to complete compile task (RuntimeError)
from /Library/Ruby/Gems/2.0.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:257:in `chdir'
from /Library/Ruby/Gems/2.0.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:257:in `execute'
from /Library/Ruby/Gems/2.0.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:69:in `compile'
from /Library/Ruby/Gems/2.0.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:109:in `cook'
from extconf.rb:101:in `block in <main>'
from extconf.rb:119:in `call'
from extconf.rb:119:in `block in <main>'
from extconf.rb:109:in `tap'
from extconf.rb:109:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/nokogiri-1.6.1/gem_make.out
See how it's looking to the system version of Ruby & Gems? I have XCode installed and up to date.
brew doctor yields no results and brew update is ready to brew.
I'm using OS 10.10.3. Anything I've left out, just ask.
EDIT
Here is my .zshrc $PATH export:
export PATH="$PATH:$HOME/.composer/vendor/bin"
export PATH="$PATH:/usr/local/sbin"
export PATH="$PATH:$HOME/.rvm/bin"
EDIT 2
$GEM_HOME
/Users/scott/.rvm/gems/ruby-2.2.2
$GEM_PATH
/Users/scott/.rvm/gems/ruby-2.2.2:/Users/scott/.rvm/gems/ruby-2.2.2#global
Thoughts?

looking at brew:
https://github.com/Homebrew/homebrew/blob/master/bin/brew
https://github.com/Homebrew/homebrew/blob/master/bin/brew#L22
so brew is upsetting the GEM_PATH and doing its own thing.

Found the answer, the system rubygems.rb was referencing the wrong version of Ruby. More details here: https://github.com/Homebrew/homebrew/issues/31220

Related

Installation messed up with Ruby: Unable to install jekyll

I was trying to setup a GitHub Page using Jekyll, which rely on Ruby (like here). Unfortunately, I think I kind of messed up with the installation (after a few sudo apt-get install ruby-full and sudo apt-get remove ruby-full ...)
Right now, I am stuck with an old version of Ruby (I think) on my computer that I am not able to update. Here is the state of my system right now:
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
$ gem -v
3.1.2
$ gem install jekyll
ERROR: Error installing jekyll:
The last version of sass-embedded (~> 1.54) to support your Ruby & RubyGems was 1.58.0. Try installing it with `gem install sass-embedded -v 1.58.0` and then running the current command again
sass-embedded requires RubyGems version >= 3.3.22. The current RubyGems version is 3.1.2. Try 'gem update --system' to update RubyGems itself.
$ gem update --system
Updating rubygems-update
Successfully installed rubygems-update-3.4.6
Parsing documentation for rubygems-update-3.4.6
Done installing documentation for rubygems-update after 0 seconds
Parsing documentation for rubygems-update-3.4.6
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.4.6
Traceback (most recent call last):
5: from setup.rb:22:in `<main>'
4: from setup.rb:22:in `require'
3: from /home/jarret/gems/gems/rubygems-update-3.4.6/lib/rubygems.rb:1332:in `<top (required)>'
2: from /home/jarret/gems/gems/rubygems-update-3.4.6/lib/rubygems.rb:1332:in `require'
1: from /usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:49:in `<top (required)>'
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:50:in `<class:Specification>': undefined method `rubyforge_project=' for class `Gem::Specification' (NameError)
3: from setup.rb:22:in `<main>'
2: from setup.rb:22:in `require'
1: from /home/jarret/gems/gems/rubygems-update-3.4.6/lib/rubygems.rb:1328:in `<top (required)>'
/home/jarret/gems/gems/rubygems-update-3.4.6/lib/rubygems.rb:1342:in `rescue in <top (required)>': undefined method `rubyforge_project=' for class `Gem::Specification' (NameError)
Loading the /usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb file caused an error. This file is owned by your OS, not by rubygems upstream. Please find out which OS package this file belongs to and follow the guidelines from your OS to report the problem and ask for help.
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.1.2
- RUBY VERSION: 2.7.0 (2019-12-25 patchlevel 0) [x86_64-linux-gnu]
- INSTALLATION DIRECTORY: /home/jarret/gems
- USER INSTALLATION DIRECTORY: /home/jarret/.gem/ruby/2.7.0
- RUBY EXECUTABLE: /usr/bin/ruby2.7
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /home/jarret/gems/bin
- SPEC CACHE DIRECTORY: /home/jarret/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/jarret/gems
- /home/jarret/.gem/ruby/2.7.0
- /var/lib/gems/2.7.0
- /usr/lib/ruby/gems/2.7.0
- /usr/share/rubygems-integration/2.7.0
- /usr/share/rubygems-integration/all
- /usr/lib/x86_64-linux-gnu/rubygems-integration/2.7.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /home/jarret/gems/bin
- /home/jarret/miniconda3/condabin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /usr/local/games
- /snap/bin
- /opt/fiji/Fiji.app
I've tried many remove/install, I've tried updated gem, ruby. Nothing unlocked me so far.
Try to replace ruby3.0, sass1.58 is too advanced and may not be compatible with ruby2.7.
Please follow these steps and run the command.
rvm install 3.0
rvm use 3.0.0 -default
rvm -v
rvm gemset update
gem install jekyll
jekyll -v

Cannot load such file --mechanize

There is a class called ParseSearch.rb, which uses mechanize gem.
I made a new file that is used for Ruby Shoes(GUI) and I required all gems that are needed
require "mechanize"
require "rubygems"
require_relative "ParseSearch.rb"
In the terminal I installed the gem
$ gem install mechanize
Successfully installed mechanize-2.7.6
Parsing documentation for mechanize-2.7.6
Done installing documentation for mechanize after 0 seconds
1 gem installed
However, when I run the shoes.rb I get a error
Error in <unknown> line 0 | 2020-02-16 15:40:27 -0500
cannot load such file -- mechanize
.shoes/walkabout/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:59:in `require'
.shoes/walkabout/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:59:in `require'
search_shoes.rb:1:in `<main>'
.shoes/walkabout/lib/shoes.rb:353:in `eval'
.shoes/walkabout/lib/shoes.rb:353:in `visit'
.shoes/walkabout/lib/shoes.rb:139:in `show_selector'
.shoes/walkabout/lib/shoes.rb:169:in `block (4 levels) in splash'
The gem env are shown below.
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3
- RUBY VERSION: 2.6.3 (2019-04-16 patchlevel 62) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/daniel/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0
- USER INSTALLATION DIRECTORY: /.gem/ruby/2.6.0
- RUBY EXECUTABLE: /.rbenv/versions/2.6.3/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /.rbenv/versions/2.6.3/bin
- SPEC CACHE DIRECTORY: /.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /.rbenv/versions/2.6.3/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0
- /.gem/ruby/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /.rbenv/versions/2.6.3/bin
- /.rbenv/libexec
- /.rbenv/plugins/ruby-build/bin
- /.rbenv/shims
- /.rbenv/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /usr/local/games
- /snap/bin

Adding gems on Sierra OS

I've tried to update, as well as run existing Ruby gems after upgrading to OS X Sierra.
> sudo gem update --system
> Password: *enters password*
> Updating rubygems-update...
> ERROR: While executing gem ... (Errno::EPERM)
> Operation not permitted - /usr/bin/update_rubygems
This happens whether I execute directly from RubyGems or clone and pull down from Github. Running the command with sudo also returns an error saying I lack permissions.
I tried sudo rubygems_update :
/usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/rubygems/dependency.rb:308:in `to_specs': Could not find 'rubygems-update' (>= 0.a) among 7 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/Users/Angelfirenze/.gem/ruby/2.4.0:/usr/local/lib/ruby/gems/2.4.0:/usr/local/Cellar/ruby/2.4.0/lib/ruby/gems/2.4.0', execute `gem env` for more information
from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/rubygems/dependency.rb:320:in `to_spec'
from /usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from /usr/local/bin/update_rubygems:22:in `<main>'
I have just executed gem env and my terminal returned the following:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.0.0 (2015-12-16 patchlevel 648) [universal.x86_64-darwin16]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- SPEC CACHE DIRECTORY: /Users/Angelfirenze/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-16
- GEM PATHS:
- /Library/Ruby/Gems/2.0.0
- /Users/Angelfirenze/.gem/ruby/2.0.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/Angelfirenze/.rbenv/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/git/bin
- /usr/local/MacGPG2/bin
- /Users/Angelfirenze/.rvm/bin
- /Users/Angelfirenze/bin
- /Users/Angelfirenze/bin
Maybe installing rvm would be the best option. I usually avoid the default ruby that comes shipped with OS X.
With that said I think Sierra ships with new security that needs to be disabled you can read about it here: Disable Mac OS SIP

Rails 4.2 and gem config broken

My OS X ruby dev environment is broken, I don't know why.
I undesrtood that the gem path is wrong, but I don't know how to fix it.
/Users/muqaddar/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'rails' (>= 0) among 14 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/muqaddar/.rvm/gems/ruby-2.0.0-p598:/Users/muqaddar/.rvm/gems/ruby-2.0.0-p598#global', execute `gem env` for more information
from /Users/muqaddar/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:324:in `to_spec'
from /Users/muqaddar/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
from /usr/bin/rails:22:in `<main>'
Here is my config with gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.6
- RUBY VERSION: 2.0.0 (2014-11-13 patchlevel 598) [x86_64-darwin14.1.0]
- INSTALLATION DIRECTORY: /Users/muqaddar/.rvm/gems/ruby-2.0.0-p598
- RUBY EXECUTABLE: /Users/muqaddar/.rvm/rubies/ruby-2.0.0-p598/bin/ruby
- EXECUTABLE DIRECTORY: /Users/muqaddar/.rvm/gems/ruby-2.0.0-p598/bin
- SPEC CACHE DIRECTORY: /Users/muqaddar/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/muqaddar/.rvm/rubies/ruby-2.0.0-p598/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-14
- GEM PATHS:
- /Users/muqaddar/.rvm/gems/ruby-2.0.0-p598
- /Users/muqaddar/.rvm/gems/ruby-2.0.0-p598#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/muqaddar/.rvm/gems/ruby-2.0.0-p598/bin
- /Users/muqaddar/.rvm/gems/ruby-2.0.0-p598#global/bin
- /Users/muqaddar/.rvm/rubies/ruby-2.0.0-p598/bin
- /usr/local/mysql/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /opt/X11/bin
- /Users/muqaddar/.rvm/bin
I tried many things, reading lots of threads.
- reinstall rvm
- remove .vendor/bundle
- bundle install
...etc
I think the gems are not installed in the right directory. How to change that depending my rvm config ?
You should try and follow these steps if you are using a mac: http://www.installrails.com/
Note that when installing a new gem, you first have to add it to the Gemfile inside your editor. For example: gem 'bootstrap-sass', '~> 3.3.3'
After doing this navigate to your folder using terminal and type: "bundle install". This will install your added gems.

Rubygems permission problem when using sudo

I use sudo to install gems and update rubygems itself but this causes the problem of all new files in /usr/lib/ruby/gems/1.8/gems to be owned by root:root with a permission of 750
This in turn causes most gems to fail to load.
For example, I recently updated rubygems and if I try gem env I get:
/usr/local/lib/site_ruby/1.8/rubygems/specification.rb:512:in `read': Permission denied - /usr/lib/ruby/gems/1.8/specifications/rubygems-update-1.6.2.gemspec (Errno::EACCES)
from /usr/local/lib/site_ruby/1.8/rubygems/specification.rb:512:in `load'
from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:116:in `load_gems_in'
from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:115:in `each'
from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:115:in `load_gems_in'
from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:112:in `reverse_each'
from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:112:in `load_gems_in'
from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:309:in `refresh!'
from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:67:in `from_gems_in'
from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:47:in `from_installed_gems'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:1025:in `source_index'
from /usr/local/lib/site_ruby/1.8/rubygems/gem_path_searcher.rb:135:in `init_gemspecs'
from /usr/local/lib/site_ruby/1.8/rubygems/gem_path_searcher.rb:14:in `initialize'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:984:in `new'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:984:in `searcher'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:206:in `try_activate'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:57:in `require'
from /usr/local/lib/site_ruby/1.8/rubygems/config_file.rb:55
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/site_ruby/1.8/rubygems/gem_runner.rb:8
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /usr/bin/gem:9
The current workaround is to chmod all files to be readable by everyone but this is getting really annoying.
Some server stats:
uname -a gives
Linux HomeBox 2.6.35 28-server #49-Ubuntu SMP Tue Mar 1 14:55:37 UTC 2011 x86_64 GNU/Linux
sudo gem env gives
RubyGems Environment:
- RUBYGEMS VERSION: 1.6.2
- RUBY VERSION: 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /home/nicklas/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
ruby -v gives
ruby 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux]
I'd be happy to provide more info on the problem.
Update
I just cleaned out all ruby and rubygems stuff and reinstalled it. Same problem.
I use Ubuntu at home too, and after many problems with using apt to install, I discovered RVM.
RVM is super-simple to install, and gets you up and running quickly and easily. But once you start using it for a while, you'll discover that it is superior to any OS package system because it has features that allow you to:
Install multiple versions of Ruby and JRuby and easily switch between them. I can just issue rvm use 1.9.2 or rvm use jruby-1.6.2 and my path is switched automatically and everthing just works.
Install sets of gems into "gemsets" which allow you to use the same gems across multiple ruby versions, so you don't have to manually reinstall. Also, you can switch between gemsets so you can isolate experimental gem versions, etc.
My recommendation is to uninstall the native ruby package, and install RVM. You'll be glad you did.

Resources