简体   繁体   中英

Error while running bundle install rails 5.2 app

OS: Mac Mojave 10.14.6
Rails 5.2.3
Ruby 2.6.3

I generated a new application, and was trying to do a

bundle install

Which was interrupted with the following error message:

Fetching nio4r 2.5.2
Installing nio4r 2.5.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/nio4r-2.5.2/ext/nio4r
/Users/johndoe/.rbenv/versions/2.6.3/bin/ruby -I /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20190924-11373-sf54p6.rb extconf.rb --with-cflags\=-std\=c99
checking for unistd.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
  --with-opt-dir
  --without-opt-dir
  --with-opt-include
  --without-opt-include=${opt-dir}/include
  --with-opt-lib
  --without-opt-lib=${opt-dir}/lib
  --with-make-prog
  --without-make-prog
  --srcdir=.
  --curdir
  --ruby=/Users/johndoe/.rbenv/versions/2.6.3/bin/$(RUBY_BASE_NAME)
/Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:601:in `try_cpp'
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:331:in `open'
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:331:in `open'
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
  from /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
  from extconf.rb:14:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nio4r-2.5.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/nio4r-2.5.2 for inspection.
Results logged to /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nio4r-2.5.2/gem_make.out

An error occurred while installing nio4r (2.5.2), and Bundler cannot continue.
Make sure that `gem install nio4r -v '2.5.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rails was resolved to 5.2.3, which depends on
    actioncable was resolved to 5.2.3, which depends on
      nio4r

I looked around, and tried some of the suggestions, such as

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

But it did not work. Any ideas?

EDIT:

This had been working fine, with my existing project, but it noticed that it stopped working yesterday, when I did a:

bundle update

I got the same error. If I do:

bundle install

when I add a new Gem to my existing project, it works fine. In my Gemfile.lock file, I have:

actioncable (5.2.3)
  actionpack (= 5.2.3)
  nio4r (~> 2.0)
  websocket-driver (>= 0.6.1)

and:

nio4r (2.5.1)

By looking at it, it looks like you are missing tools to compile the gems. I'm not a OS-X user, but in linux distros this would be solved by installing the package build-essentials.

I did a quick research online and found out that in OS-X this tools are packaged in xcode, so I would recommend that you tried this command: xcode-select --install

Keep me posted if this fixed your issue.

Run xcode-select --install solved the issue. Thanks @luiz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM