Ruby-on-rails 使用 brew 时出现“错误解释器”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8864668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 02:38:11  来源:igfitidea点击:

Getting a "bad interpreter" error when using brew

ruby-on-railsrubymacoshomebrew

提问by Holger Sindbaek

I'm getting this error when I try to run any brew command.

当我尝试运行任何 brew 命令时出现此错误。

Holger-Sindbaeks-MacBook-Air:~ holgersindbaek$ brew help
-bash: /usr/local/bin/brew: /usr/bin/ruby: bad interpreter: No such file or directory

I have absolutely no idea on how to fix this and been searching for a long time without answer.

我完全不知道如何解决这个问题,并且搜索了很长时间没有答案。

回答by Kjuly

I got this error (much the same):

我收到此错误(大致相同):

/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 26: /usr/local/Library/brew.rb: Undefined error: 0

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: 错误的解释器: 没有这样的文件或目录 / usr/local/bin/brew:第 26 行:/usr/local/Library/brew.rb:未定义错误:0

and fixed by the solution below:

并通过以下解决方案修复:

  1. Open brew.rb:

    $ sudo vim /usr/local/Library/brew.rb
    
  2. Change the first line's 1.8to Current:

    Before:

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

    After:

    #!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0
    
  1. 打开brew.rb:

    $ sudo vim /usr/local/Library/brew.rb
    
  2. 将第一行更改1.8Current

    前:

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

    后:

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

Then brewworks for me. Hope it helps if any other one got this issue. :)

然后brew对我来说有效。希望如果其他人遇到此问题会有所帮助。:)



If you get the error

如果你得到错误

Homebrew requires Leopard or higher. For Tiger support, see: https://github.com/mistydemeo/tigerbrew

Homebrew 需要 Leopard 或更高版本。有关 Tiger 支持,请参阅:https: //github.com/mistydemeo/tigerbrew

change the MACOS check from <10.5to <10.

将 MACOS 检查从 更改<10.5<10

Tip by @TimCastelijns:

@TimCastelijns 的提示:

10.5 doesn't work because in comparison, it's higher than 10.10 (.1 vs .5). I added a check (and MACOS_VERSION != 10.10) instead of lowering from 10.5 to 10.

10.5 不起作用,因为相比之下,它高于 10.10(.1 对 .5)。我添加了一个检查 ( and MACOS_VERSION != 10.10) 而不是从 10.5 降低到 10。

回答by Milad Naseri

What you are getting means that Homebrew has not been able to locate the Ruby interpretter at the specified location.

您得到的意思是 Homebrew 无法在指定位置找到 Ruby 解释器。

Install Apple Developer Kit (comes with Xcode) which should be available to you as an optional install (or you can simply download it from Apple). This will install the Ruby interpreter for you.

安装 Apple Developer Kit(与 Xcode 一起提供),它应该作为可选安装提供给您(或者您可以直接从 Apple 下载)。这将为您安装 Ruby 解释器。

In case you already have Xcode installed, this means that one of these things is happening:

如果您已经安装了 Xcode,这意味着正在发生以下情况之一:

  1. You have a broken Ruby installation
  2. You have more than one Ruby installation
  3. Your installation has not been configured properly.
  1. 你有一个损坏的 Ruby 安装
  2. 你有不止一个 Ruby 安装
  3. 您的安装配置不正确。

To identify if this is the first case, you can run rubyand see if you get any response.

要确定这是否是第一种情况,您可以运行ruby并查看是否有任何响应。

If you don't, your installation is broken and you need to reinstall it. If you do, you then run which ruby. This should give you the absolute path to your Ruby executable. If this is anything other than /usr/bin/rubythen homebrew (and a bunch of other programs) will not be able to find it.

如果不这样做,则您的安装已损坏,您需要重新安装它。如果这样做,则运行which ruby. 这应该为您提供 Ruby 可执行文件的绝对路径。如果这不是/usr/bin/ruby自制软件(和一堆其他程序)将无法找到它。

In case you have not ever tampered with your Ruby installation, you can check to see if /usr/bin/rubyalready exists or not: cat /usr/bin/ruby. If you get No such file or directory, then you can easily create a symbolic link to your Ruby installation. Assuming the output of which rubyto by /usr/local/bin/ruby, you create the symbolic link this way: sudo ln -s /usr/local/bin/ruby /usr/bin/rubyand all should be well.

在你还没有使用过你的Ruby安装篡改的情况下,你可以检查,看看是否/usr/bin/ruby已经存在与否:cat /usr/bin/ruby。如果您获得No such file or directory,那么您可以轻松地创建一个指向您的 Ruby 安装的符号链接。假设which rubyto by的输出/usr/local/bin/ruby,您以这种方式创建符号链接:sudo ln -s /usr/local/bin/ruby /usr/bin/ruby一切都应该很好。

If there is a file at that location, you can run file /usr/bin/rubyto see if it's a real file, a symbolic link, or a corrupted file. If it is a symbolic link, your installation should be working, and since it's not, it probably is either a corrupted symlink or it's a bogus file.

如果该位置有文件,您可以运行file /usr/bin/ruby以查看它是真实文件、符号链接还是损坏的文件。如果它是一个符号链接,则您的安装应该可以正常工作,因为它不是,它可能是一个损坏的符号链接或一个伪造的文件。

You can remedy that by first deleting it (sudo rm /usr/bin/ruby) and then creating a new symlink to the correct location (sudo ln -s /usr/local/bin/ruby /usr/bin/ruby).

您可以通过首先删除它 ( sudo rm /usr/bin/ruby) 然后创建一个指向正确位置的新符号链接 ( sudo ln -s /usr/local/bin/ruby /usr/bin/ruby)来解决这个问题。

If non of the above works, you should consult the homebrew team after a clean install of Xcode and removing any traces of a Ruby installation on your system.

如果上述方法均无效,您应该在全新安装 Xcode 并删除系统上任何 Ruby 安装痕迹后咨询自制软件团队。

EDIT

编辑

Alternatively, as pointed out by the other answers, the issue might be because of a bad ruby version in your Homebrew settings.

或者,正如其他答案所指出的,问题可能是因为 Homebrew 设置中的 ruby​​ 版本不好。

A quick fix might be updating your Homebrew:

快速修复可能是更新您的 Homebrew:

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

If this does not help, you might want to get your hands dirty and manually fix the problem by:

如果这没有帮助,您可能想要弄脏手并通过以下方式手动解决问题:

  1. Editing brew.rbfrom /user/local/Library/brew.rb
  2. Changing /1.8/to /Current/in the first line, which will cause the hashbang to point to the current Ruby version as the executor
  1. 编辑brew.rb/user/local/Library/brew.rb
  2. 在第一行更改/1.8//Current/,这将导致 hashbang 指向当前的 Ruby 版本作为执行者

If this does not help, either, you can also modify the MACOScheck and change it from 10.5to 10to avoid the infamous "Homebrew requires Leopard or higher" error.

如果这也没有帮助,您也可以修改MACOS检查并将其从10.5更改为10,以避免臭名昭著的“Homebrew 需要 Leopard 或更高版本”错误。

DISCLAIMER

免责声明

A bunch of thanks to other contributors in the answers below and their commenters. I am not committing plagiarism, simply aggregating the answers into one integrated article to help others.

非常感谢下面答案中的其他贡献者和他们的评论者。我没有抄袭,只是将答案汇总到一篇综合文章中以帮助他人。

回答by Shobhit C

Fix:

使固定:

sudo gem install cocoapods

回答by mcfedr

This happened because I needed to update brew - in the updated version it already uses Current ruby

发生这种情况是因为我需要更新 brew - 在更新版本中它已经使用 Current ruby

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

This solved the problem

这解决了问题

回答by Nick Sarafa

At the risk of oversimplifying things, try running

冒着把事情简单化的风险,尝试运行

gem install bundler

I was transitioning my Ruby environment from RBENV to RVM and it worked for me.

我正在将我的 Ruby 环境从 RBENV 转换到 RVM,它对我有用。

回答by Sivabalaa Jothibose

You need to change the path for Ruby.Framework

您需要更改 Ruby.Framework 的路径

I solved it with commands as mentioned.

我用上面提到的命令解决了它。

  1. brew install cocoapods --build-from-source

  2. brew link --overwrite cocoapods

  1. brew install cocoapods --build-from-source

  2. brew link --overwrite cocoapods

If you have a lower version below Xcode 11, you have to remove it before you use the above commands.

如果下面有低版本Xcode 11,在使用上述命令之前必须先将其删除。

Reference: Ruby Framework issue

参考:Ruby 框架问题

回答by James Toomey

None of the above worked for me, so I kept browsing and found this answer, https://stackoverflow.com/a/24225960/1359088which did fix brew for me. He says in step 1 to install XCode 6 command line tools, but doesn't say how; use this command:

以上都不适合我,所以我继续浏览并找到了这个答案, https://stackoverflow.com/a/24225960/1359088 确实为我修复了 brew。他在第 1 步中说要安装 XCode 6 命令行工具,但没有说明如何安装;使用这个命令:

xcode-select --install

回答by Piyush

I got the same issue when updated to MacOSX High Sierra & using Xcode 9 with that. High Sierra update ruby gem to version 2.3 but xcpreety command of Xcode 9 still using Ruby 2.0 which is unable to find now & gives bad interpreter. Just go to Terminal & run

更新到 MacOSX High Sierra 并使用 Xcode 9 时,我遇到了同样的问题。High Sierra 将 ruby​​ gem 更新到 2.3 版,但 Xcode 9 的 xcpreety 命令仍在使用 Ruby 2.0,它现在无法找到并且给出了错误的解释器。只需转到终端并运行

sudo gem install xcpretty

Restart Xcode & do fresh clean build it works for me. Hope it helps!!!

重新启动 Xcode 并重新构建它对我有用。希望能帮助到你!!!

回答by Balamurugan

After upgrading to macOS High Sierra, get it fixed with following commands:

升级到 macOS High Sierra 后,使用以下命令修复它:

sudo gem install cocoapods

sudo gem 安装 cocoapods

回答by Serg Smyk

In my case seems like fastlaneinstalled incorrectly with brew install fastlanesystem didn't write correct path to fastlane. I fixed it with alias fastlane=~/.fastlane/bin/fastlane

在我的情况下,似乎fastlane安装不正确,brew install fastlane系统没有写出正确的 fastlane 路径。我用alias fastlane=~/.fastlane/bin/fastlane