如何在Rails 5.0.0上修复bundle install“nio4r error”

确切的错误是:

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. 

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

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

我能够解决这个问题:

 brew update 

 bundle update 

我刚才遇到了同样的错误。在我的情况下,我通过软件包安装了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

这条路径:

 /Users/lukeplourde/.rbenv/... 

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

在这种情况下,您永远不应该获得权限错误。 您获得权限错误的事实强烈暗示您在某些时候使用sudo将某些东西(可能是nio4r)安装到rbenv管理的Ruby中。

当您使用sudo ,您暂时将您的权限提升为系统的root用户权限,并且保存的所有文件将具有该用户的读/写设置和所有权。 这绝对不是你想要的。

rbenv的文档特别说不使用sudo

你不需要sudo来安装gem。 通常,Ruby版本将由您的用户安装和编写。 安装gem不需要额外的权限。

要解决问题,只需运行:

 sudo chown -R lukeplourde ~/.rbenv 

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

了解何时使用sudo需要获得Ruby环境的经验和知识,您当前的设置以及您打算发生的事情。 通常,如果您的rbenv设置为使用您安装的Ruby,则在使用gem时不希望使用任何sudo命令。 如果您使用的是Mac OS,并且使用的是sudo和rbenv以及安装的Ruby,那么请在按Return之前多次思考,因为它可能不是您想要做的。

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


你重置了文件的所有权吗?

所有权没有改变否。

大多数情况下,有两件事是权限问题的根源:

  • 所有权
  • 访问标志

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

chmod更改所有者,其组和/或计算机上其他所有人的文件或目录的访问权限。

有问题的.gitignore文件应由您拥有,并具有-rw-r--r--权限。 如果不是,你需要设置它们。 使用命令行中的man chmodman chown研究chmodchown命令,并适当调整文件/目录权限,您应该能够解决问题。