RubyGems error after updating system

2019-04-21 16:40发布

问题:

When trying to launch the rails console after updating my ruby setup using 'sudo gem update --system', I then try execute the rails console by issuing rails c

I get this error:

Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find json (~> 1.4) amongst [Ascii85-1.0.1, abstract-1.0.0, actionmailer-3.1.1, actionmailer-3.1.0, actionmailer-3.0.9, actionmailer-3.0.5, actionmailer-3.0.3, actionpack-3.1.1, actionpack-3.1.0, actionpack-3.0.9, actionpack-3.0.5, actionpack-3.0.3, activemodel-3.1.1, activemodel-3.1.0, activemodel-3.0.10, activemodel-3.0.9, activemodel-3.0.5, activemodel-3.0.3, activerecord-3.1.1, activerecord-3.1.0, activerecord-3.0.9, activerecord-3.0.5, activerecord-3.0.3, activeresource-3.1.1, activeresource-3.1.0, activeresource-3.0.9, activeresource-3.0.5, activeresource-3.0.3, activesupport-3.1.1, activesupport-3.1.0, activesupport-3.0.10, activesupport-3.0.9, activesupport-3.0.5, activesupport-3.0.3, addressable-2.2.6, ansi-1.3.0, arel-2.2.1, arel-2.0.10, arel-2.0.9, arel-2.0.7, bcrypt-ruby-3.0.1, bcrypt-ruby-3.0.0, bcrypt-ruby-2.1.4, builder-3.0.0, builder-2.1.2, bundler-1.0.21, bundler-1.0.18, bundler-1.0.11, choices-0.2.4, cocaine-0.2.0, coffee-rails-3.1.1, coffee-rails-3.1.0, coffee-script-2.2.0, coffee-script-source-1.1.2, devise-1.4.8, devise-1.4.2, erubis-2.7.0, erubis-2.6.6, execjs-1.2.9, execjs-1.2.6, execjs-1.2.4, faraday-0.7.4, faraday-0.6.1, faraday_middleware-0.7.0, faraday_middleware-0.6.3, fastercsv-1.5.4, formtastic-2.0.2, formtastic-1.2.4, geocoder-1.0.4, geocoder-1.0.2, has_scope-0.5.1, hashie-1.1.0, hashie-1.0.0, heroku-2.7.0, hike-1.2.1, i18n-0.6.0, i18n-0.5.0, inherited_resources-1.3.0, inherited_resources-1.2.2, jquery-rails-1.0.16, jquery-rails-1.0.14, kaminari-0.12.4, launchy-2.0.5, libv8-3.3.10.2-x86_64-darwin-10, mail-2.3.0, mail-2.2.19, mail-2.2.15, mail-2.2.14, mechanize-2.0.1, mechanize-1.0.0, meta_search-1.1.1, meta_search-1.0.6, mime-types-1.16, multi_json-1.0.3, multi_xml-0.4.1, multi_xml-0.4.0, multi_xml-0.3.0, multi_xml-0.2.2, multipart-post-1.1.3, multipart-post-1.1.2, mysql-2.8.1, mysql2-0.3.7, mysql2-0.2.7, mysql2-0.2.6, net-http-digest_auth-1.1.1, net-http-persistent-2.1, net-http-persistent-2.0, net-http-persistent-1.9, nokogiri-1.5.0, nokogiri-1.4.4, orm_adapter-0.0.5, pdf-reader-0.10.0, pg-0.11.0, polyamorous-0.5.0, polyglot-0.3.2, polyglot-0.3.1, prawn-0.12.0, rack-1.3.4, rack-1.3.3, rack-1.3.2, rack-1.2.3, rack-1.2.2, rack-1.2.1, rack-cache-1.1, rack-cache-1.0.3, rack-mount-0.8.3, rack-mount-0.6.14, rack-mount-0.6.13, rack-ssl-1.3.2, rack-test-0.6.1, rack-test-0.5.7, rails-3.1.1, rails-3.1.0, rails-3.0.9, rails-3.0.5, rails-3.0.3, railties-3.1.1, railties-3.1.0, railties-3.0.9, railties-3.0.5, railties-3.0.3, rake-0.9.2, rake-0.8.7, rake-0.8.7, rash-0.3.1, rash-0.3.0, rdoc-3.10, rdoc-3.9.4, rdoc-3.9.2, responders-0.6.4, rest-client-1.6.7, rubygems-update-1.8.11, rubygems-update-1.8.10, rubygems-update-1.7.2, rubygems-update-1.7.1, rubygems-update-1.6.2, rubyzip-0.9.4, sass-3.1.10, sass-3.1.7, sass-rails-3.1.4, sass-rails-3.1.2, sass-rails-3.1.0, simple_oauth-0.1.5, sprockets-2.0.2, sprockets-2.0.0, sqlite3-1.3.4, term-ansicolor-1.0.6, therubyracer-0.9.4, thor-0.14.6, tilt-1.3.3, treetop-1.4.10, treetop-1.4.9, ttfunk-1.0.3, ttfunk-1.0.2, turn-0.8.2, twitter-1.7.1, twitter-1.4.1, tzinfo-0.3.30, tzinfo-0.3.29, tzinfo-0.3.26, tzinfo-0.3.24, uglifier-1.0.3, warden-1.0.6, warden-1.0.5, webrobots-0.0.12, webrobots-0.0.11] (Gem::LoadError)
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1932:in `block in traverse'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1931:in `each'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1931:in `traverse'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:465:in `block in find_in_unresolved_tree'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:463:in `reverse_each'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:463:in `find_in_unresolved_tree'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:47:in `require'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.1/lib/rails/script_rails_loader.rb:1:in `<top (required)>'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.1/lib/rails/cli.rb:2:in `<top (required)>'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/gems/rails-3.1.1/bin/rails:7:in `<top (required)>'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/bin/rails:19:in `load'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/bin/rails:19:in `<main>'

Any ideas?

回答1:

what do you get when you try to list your gems.. is json >= 1.4 there?

e.g.:

> gem list json

*** LOCAL GEMS ***

json (1.6.1, 1.5.4, 1.5.3, 1.5.1, 1.4.2)
json_pure (1.6.1, 1.5.4, 1.5.3)

if you use RVM gemsets, you may want to list them also, to check if your default gemset has changed:

rvm gemset list

EDIT: Mystery Solved! :-)

you accidentially installed your gems with sudo -- but you have RVM installed for your user account!

When you have RVM installed for an individual user, it's generally not a good idea to do sudo gem install ... , but you should install the gems just for the local user and let RVM manage them for whatever Ruby version you are using.

If you still install with sudo, RVM will not find the gems, because they are stored in a different location, outside of RVM, and not searched by RVM...! Looks like that's the case you experienced.

Check this RailsCast: http://railscasts.com/episodes/200-rails-3-beta-and-rvm

if you're using Rails: - edit your Gemfile and add the json dependency , then run bundle install

if you're just using Ruby by itself, or an old version or Ruby: - run gem install json in the shell

With newer Ruby versions you should not manually install the gems



回答2:

Add gem "json", "~> 1.4" in your Gemfile and run bundle install



回答3:

Also

You only use the sudo command during the install process. In Multi-User configurations, any operations which require sudo access must use the rvmsudo command which preserves the RVM environment and passes this on to sudo. There are very few cases where rvmsudo is required once the core install is completed, except for when updating RVM itself. There is never a reason to use sudo post-install. Once users added to the 'rvm' group have logged out, then back in to gain rvm group membership, rvmsudo should only be needed for updating RVM itself with

rvmsudo rvm get head

Please read the https://rvm.beginrescueend.com/support/troubleshooting/ page The installer page also details this for new installations. You will need to remove your existing installation and redo it in order to properly reconfigure the permissions. In the future, never user sudo when working on your RVM installation, except when installing. Any other commands will not require sudo use except for

rvmsudo rvm get head

to update your installation. If the users are properly placed in the rvm group as detailed on the site, you will have no need to use sudo at all, and rvmsudo only for updating.

Also, RVM does not manage the system installed ruby at all! We do provide the use of

rvm use system

in order to give a natural way to switch between RVM controlled rubies, and the system. Your package manager, or lack thereof for OS X, is responsible for managing your system installed ruby and is outside the control of RVM 100%.