$ gem -v
1.8.5
$ ruby -v
ruby 1.8.7 (2010-04-19 patchlevel 253) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2010.02
$ sudo gem install sanitize
ERROR: Error installing sanitize:
nokogiri requires Ruby version >= 1.8.7
This happens for other gems as well, not just nokogiri. I am on Ruby 1.8.7 and have set my $PATH to include /opt/ruby-enterprise-1.8.7-2010.02/bin/ruby before /usr/bin where system Ruby (1.8.6) is installed.
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.5
- RUBY VERSION: 1.8.7 (2010-04-19 patchlevel 253) [x86_64-linux]
- INSTALLATION DIRECTORY: /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/ruby-enterprise-1.8.7-2010.02/bin/ruby
- EXECUTABLE DIRECTORY: /opt/ruby-enterprise-1.8.7-2010.02/bin
$ which ruby
/opt/ruby-enterprise-1.8.7-2010.02/bin/ruby
$which gem
/opt/ruby-enterprise-1.8.7-2010.02/bin/gem
Your sudo command is most probably changing your PATH variable. Try
sudo gem envand you can verify this. As a solution you might try this:Also see here for further discussion:
sudo changes PATH – why?
As a workaround you could also do:
To get to a root prompt using the
-mmodifier to preserve environment. Then from that root prompt do your gem installs.