如何在 Rails 5.0.0 上修复捆绑包安装 "nio4r error"

How to fix a bundle install "nio4r error" on Rails 5.0.0

准确的错误是:

An error occurred while installing nio4r (1.2.1), and bundler cannot continue. Make sure that 'gem install nio4r -v '1.2.1'' succeeds before bundling.

这里有痕迹:

Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Fetching dependency metadata from https://rubygems.org/
Using rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.1
Using minitest 5.10.1
Using thread_safe 0.3.6
Using builder 3.2.3
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using rack 2.0.1
Installing nio4r 1.2.1 with native extensions

Errno::EACCES: Permission denied @ rb_sysopen - /Users/lukeplourde/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nio4r-1.2.1/.gitignore
Using websocket-extensions 0.1.2
Using mime-types-data 3.2016.0521
Using arel 7.1.4
Using byebug 9.0.6
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using method_source 0.8.2
Using thor 0.19.4
Using debug_inspector 0.0.2
Using ffi 1.9.17
Using multi_json 1.12.1
Using rb-fsevent 0.9.8
Using puma 3.7.0
Using bundler 1.12.5
Using sass 3.4.23
Using tilt 2.0.6
Using sqlite3 1.3.13
Using turbolinks-source 5.0.0
Using tzinfo 1.2.2
Using nokogiri 1.7.0.1
Using rack-test 0.6.3
Using sprockets 3.7.1
An error occurred while installing nio4r (1.2.1), and Bundler cannot continue.
Make sure that `gem install nio4r -v '1.2.1'` succeeds before bundling.

此路径:

/Users/lukeplourde/.rbenv/...

显示您正在使用 rbenv 来管理您的 Ruby。

在这种情况下,您永远不会遇到权限错误。您 收到权限错误这一事实强烈表明您在某个时候安装了一些东西,可能是 nio4r,使用 sudo.

当您使用 sudo 时,您暂时将您的权限提升为系统的 root 用户权限,所有保存的文件都将拥有该用户的 read/write 设置和所有权。那绝对不是你想要的。

rbenv's documentation 明确表示不要使用 sudo:

You don't need sudo to install gems. Typically, the Ruby versions will be installed and writeable by your user. No extra privileges are required to install gems.

简单解决问题运行:

sudo chown -R lukeplourde ~/.rbenv

chown 将遍历 ~/.rbenv 目录中的所有目录,并将所有子文件和目录的所有权更改回您。

知道何时使用 sudo 需要对 Ruby 环境、您当前的设置以及您打算发生什么的经验和知识。一般来说,如果你的 rbenv 被设置为使用 Ruby 你安装了你不想在使用 gem 时使用任何 sudo 命令。如果你在 Mac OS 并且你正在使用 sudo 和 rbenv 以及你安装的 Ruby 然后在按下 Return 因为这可能不是您想要做的。

而且,如果您还使用 RVM 或 Homebrew 管理的 Ruby,则上述关于使用 sudo 的警告也适用。 sudo 通常不是您想要的第一种方法。他们官方网站上的文档是您如何操作的最佳信息来源。


Did you reset the ownership of the files?

所有权没有改变。

大多数时候,权限问题的根源有两点:

  • 所有权
  • 访问标志

chown 更改文件或目录的所有权,并可选择允许我们更改所有者的组。如果根据系统您不是所有者,and/or 不在组中,那么您访问它的机会就会减少。

chmod 更改所有者及其组的文件或目录的访问权限,and/or 机器上其他所有人的访问权限。

有问题的 .gitignore 文件应该归您所有,并且具有 -rw-r--r-- 的权限。如果不是,则需要将它们设置为。在命令行使用 man chmodman chown 研究 chmodchown 命令并适当调整 file/directory 权限,您应该能够解决问题.

我刚才遇到了同样的错误。在我的例子中,我已经通过软件包安装了 ruby:https://www.brightbox.com/blog/2017/01/13/ruby-2-4-ubuntu-packages/

但是,我还没有安装 ruby-dev 包。

就我而言:sudo apt-get install ruby2.4-dev 对我有用。

安装后我能够编译gem:nio4r

我想你必须安装一些包 ruby-dev => sudo apt-get install ruby-dev

我能够通过以下方式解决问题:

brew update 

bundle update

我通过 运行 以下命令解决了这个问题。

bundle config build.nio4r --with-cflags="-std=c99"
bundle

如果有人在找这个,我已经更新了我的电脑和命令行工具。我需要同意 XCode 许可。

Error: You have not agreed to the Xcode license. Please resolve this
 by running:   sudo xcodebuild -license accept

这帮我修好了。