Install Rails Error “invalid gem: package is corru

2019-02-02 06:47发布

问题:

I am running Mac OSX 10.9.1 and I am using RVM to manage Ruby v2.0.0-p353.

When I try to install Rails I get this error:

Ryans-MacBook-Air-2:~ ryan$ gem install rails
ERROR:  Error installing rails:
invalid gem: package is corrupt, exception while verifying: undefined method`path2class' for #<Psych::ClassLoader:0x0000010c9d0be0> (NoMethodError) in /Users/ryan/.rvm/gems/ruby-2.0.0-p353/cache/i18n-0.6.9.gem

Here is a list of gems I have installed:

Ryans-MacBook-Air-2:~ ryan$ gem list

*** LOCAL GEMS ***

bigdecimal (1.2.3, 1.2.0)
bundler (1.5.1)
bundler-unload (1.0.2)
executable-hooks (1.2.6)
gem-wrappers (1.2.1)
io-console (0.4.2)
json (1.8.1, 1.7.7)
minitest (5.2.0, 4.3.2)
psych (2.0.2, 2.0.0)
rake (10.1.1, 0.9.6)
rdoc (4.1.0, 4.0.0)
rubygems-bundler (1.4.2)
rvm (1.11.3.8)
test-unit (2.5.5, 2.0.0.0)

Does anyone have suggestions to fix this?

回答1:

The latest version no longer has the class2path method so the problem can be avoided by downgrading the Psych gem to version 2.0.0:

gem list psych   # note down latest version
gem uninstall psych -v 2.0.5  # or whatever version you have installed

After the gems are installed you can upgrade the Psych gem again should you need it.



回答2:

I had this exact issue as well with the exact environment as you. I tried many things including the link which Alexbhandari added to the comment. I spent hours and finally decided to call it quits and totally wipe all of the ~/.rvm folder and start again.

Warning: this should only be done for new installs without first considering what you might lose things, such as as gemsets you may have built yourself. If however it is a new install you will not loose anything that cannot be replaced.

I renamed the ~/.rvm folder so that I did have a backup and started the whole install process again. This time it worked and I was actually up and running within about 20 minutes as opposed to the hours I had wasted prior trying to fix the issue.

You do this from the terminal window with the mv command. The ~/.rvm directory was in my $home directory:

Stephens-MacBook-Pro-2:~ Steve$ mv .rvm old.rvm

I know this is a drastic step however it worked for me on a new install so I am hoping it will help a newby in the future.



回答3:

I was having the same problem and remembered seeing something in my Terminal output that said XCode developer tools was out of date or not installed (I can't remember which). It suggested running:

$ xcode-select --install

After doing so, I was still getting the problem. I tried removing the cache for the gemset (I'm using RVM) but still was getting the error. I was still on ruby-2.0.0-p353. I did the following and things are working for me:

$ rvm get stable
$ rvm reload
$ rvm install 2.1
$ rvm gemset create your_gemset_name
# Updated my .ruby-version and .ruby-gemset files in my Rails app to use the new gemset
$ cd /to/my/rails/app
# You can run $ rvm list gemsets to make sure your app is now using the new gemset. It will point to the current one being used.
$ bundle install

With a new version of Ruby and a new gemset things work fine. Not sure what happened with the other gemset, but I noticed it first when I tried to add the sidekiq gem and ran $ bundle install.

I wonder if it had something to do with a recent XCode update though since I was asked about the developer tools.



回答4:

Following Steps worked for me -

  1. Go to corrupted package/gem location

    $ cd /Users/ryan/.rvm/gems/ruby-2.0.0-p353/cache/

  2. Remove corrupted package/gem

    $ rm i18n-0.6.9.gem

  3. Now install that specific gem OR $ bundle install