如何让Ruby / Homebrew / RVM在Yosemite上运行?

时间:2014-06-15 02:07:26

标签: ruby-on-rails ruby homebrew osx-yosemite

安装Yosemite之后,我无法运行brew或ruby。

我在brew update上遇到了这个错误:

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

在irb上收到此错误:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:in mkdir': Permission denied - /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14 (Errno::EACCES) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:infu_mkdir'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:219:in block (2 levels) in mkdir_p' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:inreverse_each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:in block in mkdir_p' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:ineach'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:in mkdir_p' from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:210:inwrite_gem_make_out'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:132:in build_error' from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:171:inrescue in build_extension'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:156:in build_extension' from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:198:inblock in build_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:195:in each' from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:195:inbuild_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1436:in block in build_extensions' from /Library/Ruby/Site/2.0.0/rubygems/user_interaction.rb:45:inuse_ui'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1434:in build_extensions' from /Library/Ruby/Site/2.0.0/rubygems/stub_specification.rb:60:inbuild_extensions'
from /Library/Ruby/Site/2.0.0/rubygems/basic_specification.rb:56:in contains_requirable_file?' from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:925:inblock in find_inactive_by_path'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in each' from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:infind'
from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in find_inactive_by_path' from /Library/Ruby/Site/2.0.0/rubygems.rb:185:intry_activate'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:150:in block in search_file' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:158:inblock in each_localized_path'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:167:in each_sublocale' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:157:ineach_localized_path'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:145:in search_file' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:124:infind'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:108:in load' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/locale.rb:32:ininitialize'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/init.rb:114:in new' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/init.rb:114:ininit_config'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/init.rb:16:in setup' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb.rb:380:instart'
from /usr/bin/irb:12:in `'

11 个答案:

答案 0 :(得分:281)

可以通过以下步骤轻松修复此错误:

1)打开终端

2)输入nano /usr/local/Library/brew.rb

3)在第一行中将“1.8”更改为“Current”,所以它应该如下所示:

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0

通过http://blog.ic3man.gr/2014/06/homebrew-ruby-bad-interpreter-no-such-file-or-directory/

答案 1 :(得分:39)

我更新了Yosemite,后来发现brew已被破坏。

/usr/local/bin/brew: /usr/local/Library/brew.rb: 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory /usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

如果您尚未对brew进行任何更改,请按以下步骤进行操作。否则请阅读以下内容。

  1. cd /System/Library/Frameworks/Ruby.framework/Versions/
  2. sudo ln -s Current 1.8
  3. brew update
  4. sudo unlink 1.8
  5. 已经对brew文件进行了更改并陷入混乱?

    我尝试编辑/usr/local/Library/brew.rb,但我对git repo的本地更改阻止brew update删除更新。我尝试了本页和其他网站上提到的其他一些解决方案,最后我得到了一个混乱,我想要做的就是撤消我酿造的所有东西。

    我做出了改变,但事情变得更糟。最终我不得不撤消我的提交和git reset --hard HEAD~1,直到我处于正确的提交状态。我也有一堆无版本的文件(我在/ usr / Local中更改了文件权限)所以我做了一个git clean -f -d删除了所有未版本控制的文件和目录,并让我回到我开始之前我做了任何更改。< / p>

答案 2 :(得分:37)

修复它的步骤:

  1. 安装Xcode 6的命令行工具

  2. 重新安装brew:

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  3. 安装brew后,rvm将起作用:

    rvm install ruby
    
  4. 为我工作,雅虎!

答案 3 :(得分:33)

编辑脚本意味着brew update无效;对跟踪文件进行本地编辑会导致git pull失败。

我这样做了,我怀疑它更清洁:

cd /usr/local/Library
git pull -q origin refs/heads/master:refs/remotes/origin/master

brew doctor没有投诉。

答案 4 :(得分:7)

这是来自其他人帖子的答案以及对谷歌的一些挖掘的集合,但我想我会把它放在一起,所以一个完整的答案在一个地方。具体来说,这可以让事情现在起作用,但也可以让你像往常一样进行更新,让一切恢复干净。

  1. 打开/usr/local/Library/brew.rb(emacs/vi / nano /等)
  2. 将第一行更改为:#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0。你只是将那行中的“1.8”改为“当前”(确保你保留大写“C”,否则git会在以后混淆)。
  3. cd $(brew --repository)
  4. git add Library/brew.rb
  5. git commit -m "upgrading to ruby 2.0"
  6. brew update(如果您的brew设置为仅使用sudo进行系统更改,则为sudo brew update
  7. 信用:很多内容来自here,但我真的建议您不要在/ usr / local文件夹中执行git commit -am

答案 5 :(得分:3)

就像前面说过的那样: 1)改为当前 2)安装xcode 6

如果你现在还有brew和ruby的问题,这应该会有所帮助: 不知何故brew需要在版本1.8上使用ruby,因此创建文件夹:

sudo mkdir -p /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin

并制作符号链接:

sudo ln -s /usr/bin/ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

答案 6 :(得分:2)

在这里查看本教程:http://ryantvenge.com/2014/09/ruby-homebrea-yosemite/

它对我有用!

答案 7 :(得分:1)

我修正了如下:

  1. sudo chown -R $(whoami):admin /usr/local
  2. cd $(brew --prefix) && git fetch origin && git reset --hard origin/master

答案 8 :(得分:0)

brew更新错误可以通过以下方式修复:

sudo chown -R $USER:admin /usr/local
cd /usr/local
git reset --hard origin/master
brew update

https://github.com/Homebrew/homebrew/issues/19140

答案 9 :(得分:0)

注意:如果您最终处于完全失败状态,请执行以下操作,因为这非常危险

作为一个例子,我一直在

  

$ sudo ln -s Current 1.8

     

$ brew update

     

/usr/local/Library/brew.rb:18:in' ;: undefined method help?'for [“update”]:Array(NoMethodError)

我刚刚得到这个......(无论什么命令只是用命令切换出“更新”) 我通过询问好友/usr/local文件夹解决了这个问题。然后我备份了我的/usr/local文件夹。

  

sudo mv / usr / local /usr/local.orig

然后我将他的/usr/local移到了我的

  

sudo mv~ / Downloads / local / usr / local

注意:您可能会丢失一些数据,因此请务必进行备份。

答案 10 :(得分:-1)

我在尝试使用包管理器安装Ruby时遇到了问题。为了公平对待这些计划,我承认对他们没什么经验,并且没有像大多数其他响应者那样努力深入挖掘。我很懒,更喜欢使用二进制安装程序,可用于大多数opsys选择和许多软件包。不幸的是,Ruby似乎没有供应。

我发现ruby-build易于安装(独立 - 不是插件),它从源代码构建Ruby而没有错误,并将其放置在我想要的位置。

Bingo - easy :)对于我们这些包经理挑战说服的人来说,这看起来是个不错的选择。

查理