简体   繁体   English

安装Rails错误“无效的gem:包已损坏”

[英]Install Rails Error “invalid gem: package is corrupt”

I am running Mac OSX 10.9.1 and I am using RVM to manage Ruby v2.0.0-p353. 我正在运行Mac OSX 10.9.1,我正在使用RVM来管理Ruby v2.0.0-p353。

When I try to install Rails I get this error: 当我尝试安装Rails时出现此错误:

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? 有没有人有解决这个问题的建议?

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: 最新版本不再具有class2path方法,因此可以通过将Psych gem降级到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. 安装宝石后,如果需要,可以再次升级Psych宝石。

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. 我尝试了很多东西,包括Alexbhandari在评论中添加的链接。 I spent hours and finally decided to call it quits and totally wipe all of the ~/.rvm folder and start again. 我花了几个小时最后决定退出并完全擦除所有〜/ .rvm文件夹并重新开始。

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. 警告 :这应该仅在新安装时完成,而不首先考虑您可能丢失的东西,例如您自己可能构建的gemsets。 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. 我重命名了〜/ .rvm文件夹,以便我确实有备份并再次启动整个安装过程。 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. 这一次它起作用了,我实际上在20分钟内启动并运行,而不是我在尝试解决问题之前浪费的时间。

You do this from the terminal window with the mv command. 您可以使用mv命令从终端窗口执行此操作。 The ~/.rvm directory was in my $home directory: 〜/ .rvm目录在我的$ home目录中:

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. 我知道这是一个激烈的步骤,但它在新的安装上对我有用,所以我希望它将来会帮助一个新手。

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). 我遇到了同样的问题,并记得在我的终端输出中看到一些说XCode开发人员工具已过期或未安装(我不记得哪些)。 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. 我尝试删除gemset的缓存(我正在使用RVM),但仍然收到错误。 I was still on ruby-2.0.0-p353. 我还在使用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. 使用新版本的Ruby和新的gemset,工作正常。 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 . 不确定其他gemset发生了什么,但是当我尝试添加sidekiq gem并运行$ bundle install时,我首先注意到了它。

I wonder if it had something to do with a recent XCode update though since I was asked about the developer tools. 我想知道它是否与最近的XCode更新有关,因为我被问及开发人员工具。

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 现在安装特定的gem OR $ bundle install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM