11

The exact error is:

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.

Here is a trace:

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.
techdreams
  • 5,371
  • 7
  • 42
  • 63
CodeTooNarrow
  • 221
  • 1
  • 2
  • 11
  • 1
    Can you put the whole log output ? – lcguida Mar 07 '17 at 15:31
  • Add the whole log to your question, and try installing the nio4r gem in a separate wa, otherwise download it from rubygems.org and do the installation. – Sebastián Palma Mar 07 '17 at 15:33
  • You should try installing the gem `nio4r` by running: `gem install nio4r -v 1.2.1` and see what the problem is. – Dung Pham Mar 07 '17 at 15:34
  • @DungPham I tried installing the gem both through the command line and putting it in my Gemfile but it has not worked. – CodeTooNarrow Mar 07 '17 at 16:14
  • @lcguida Here you go. – CodeTooNarrow Mar 07 '17 at 16:28
  • 1
    As you can see.. you have a `Permission Denied` error in you log. Can you check the permission on the folder indicated in the error message? – lcguida Mar 07 '17 at 16:30
  • @LukePlourde Try these commands with `sudo` or `chmod` the folder listed in the logs. – Dung Pham Mar 07 '17 at 16:33
  • I don't know which version of ruby you used but for me updating the docker image solved the problem - to new patch version (**there is no need** to change version of ruby, i.e.: 2.2.-> 2.4 ). Previously I've used `phusion/passenger-ruby22:0.9.24` and I've updated it to `phusion/passenger-ruby22:0.9.29`. – Egel Jan 26 '18 at 16:44

6 Answers6

14

I resolved the issue by running the following command.

bundle config build.nio4r --with-cflags="-std=c99"
bundle
techdreams
  • 5,371
  • 7
  • 42
  • 63
11

I was able to fix the problem with:

brew update 

and

bundle update
CodeTooNarrow
  • 221
  • 1
  • 2
  • 11
4

I was with the same error just now.. In my case, I had installed the ruby through the package: https://www.brightbox.com/blog/2017/01/13/ruby-2-4-ubuntu-packages/

But, I had not installed the ruby-dev package.

In my case: sudo apt-get install ruby2.4-dev worked for me.

After installation I was able to compile the gem: nio4r

I think you have to install some package ruby-dev => sudo apt-get install ruby-dev

gabrielpedepera
  • 181
  • 2
  • 7
2

This issue can be solved by either or all of the following in order of precedence. If you encounter this issue while trying to containerize your rails application using docker, I advice having these lines in your Dockerfile:

    RUN apt-get update
    RUN apt-get -y install ruby-dev
    RUN apt-get -y install build-essential
    RUN apt-get -y install libgmp-dev

In most cases, and for your case, the second command (sudo apt install ruby-dev) alone or the third command (sudo apt install build-essential) will solve the issue, but feel free to try out (sudo apt install libgmp-dev) as another resort.

1

This path:

/Users/lukeplourde/.rbenv/...

shows you're using rbenv to manage your Ruby.

You should never get permission errors in that case. The fact you are getting a permission error strongly suggests that at some point you installed something, probably nio4r, into that rbenv-managed Ruby using sudo.

When you use sudo, you temporarily elevate your privileges to the system's root user's privileges, and all files saved will have that user's read/write settings and ownership. That's definitely not what you want.

rbenv's documentation specifically says to not use 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.

To fix the problem simply run:

sudo chown -R lukeplourde ~/.rbenv

and chown will walk through all directories in the ~/.rbenv directory and change the ownership back to you for all child files and directories.

Knowing when to use sudo takes experience and knowledge of the Ruby environment, your current settings for it, and what it is you intend to happen. In general though, if your rbenv is set to use a Ruby you installed you do not want to use any sudo command when using gem. If you are on Mac OS and you are using sudo and rbenv and a Ruby you installed then think multiple times before pressing Return because it's likely not what you want to do.

And, the above warnings about using sudo apply if you're using a RVM or Homebrew managed Ruby also. sudo is usually not your desired first approach. The documentation on their official sites is your best source of information on what to do.


Did you reset the ownership of the files?

The ownership did not change no.

Most of the time, two things are at the root of permissions problems:

  • ownership
  • access flags

chown changes ownership of a file or directory and optionally allows us to change the owner's group. If you are not the owner according to the system, and/or not in the group, then your chances of being able to access it went down.

chmod changes the access privileges of a file or directory for the owner, their group, and/or for everyone else on the machine.

The .gitignore file in question should be owned by you, and have permissions of -rw-r--r--. If those aren't, you need to set them so they are. Study the chmod and chown commands using man chmod and man chown at the command-line and adjust the file/directory permissions appropriately and you should be able to fix the problem.

Community
  • 1
  • 1
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
1

If anyone is looking for this, I had updated my computer and the command line tools were updated. I needed to agree to the XCode license.

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

This fixed it for me.

smcdrc
  • 1,671
  • 2
  • 21
  • 29