rails 5.0.0 when installing "nio4r" : Failed to build gem native extension

19,686

Solution 1

I am facing the same issue while I was trying to upgrade my Rails to V5.0.0, I follow this instruction and it works perfectly. Read the section "Install the Ruby DevKit" here >> http://jekyll-windows.juthilo.com/1-ruby-and-devkit/

Solution 2

Solution for Fedora 64bit

sudo dnf install redhat-rpm-config

Solution 3

I had a similar problem and running this command solved my issue.

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

Now you can successfully run bundle install afterwards.

Solution 4

Had this same issue on Ubuntu 16.04. What I did to fix this :

Remove Gemfile.lock : sudo rm Gemfile.lock Installed Ruby-Dev:

sudo apt-add-repository ppa:brightbox/ruby-ng sudo apt-get update sudo apt-get install ruby2.4-dev

and the important step : REBOOT!

Solution 5

this may be related: GCC compilation error when installing Nokogiri

I found a error. i had a 2 gcc versions installed on my system and I just run brew unlink gcc and that solved the problem.

this was my case too. benw unlink gcc worked

Share:
19,686
Mfms99
Author by

Mfms99

Updated on June 26, 2022

Comments

  • Mfms99
    Mfms99 almost 2 years

    Here is the logs: http://pastebin.com/CAgur9xd

    Installing nio4r 1.2.1 with native extensions
    
    Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    
        C:/RailsInstaller/Ruby2.2.0/bin/ruby.exe -r ./siteconf20160720-8272-c88sgk.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=C:/RailsInstaller/Ruby2.2.0/bin/$(RUBY_BASE_NAME)
    C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
    You have to install development tools first.
            from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:587:in `try_cpp'
             from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1060:in `block in have_header'
            from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'
            from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'
            from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
            from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'
            from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
            from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'
            from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'
            from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1059:in `have_header'
            from extconf.rb:3:in `<main>'
    
    extconf failed, exit code 1
    

    when installing bundle it returns(starts at line 117 in the logs ):

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

    So the bundle can't be installed. It returns at the end :

    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.
    

    Note :I have tried the solutions in other questions, but it is still the same. If it is possible to install "nio4r" manually please tell me how .

  • Mfms99
    Mfms99 almost 8 years
    i installed it and ran the setup and marked every thing in the setup , but when it finished and i tried again it gave me the same result. did i do something wrong in the installation of DefKit ?
  • Mfms99
    Mfms99 almost 8 years
    should i install a certain version of DefKit ? i have installed version 2.2.5
  • Mfms99
    Mfms99 almost 8 years
    i can't thank you enough my friend , some people told me before about DevKit ,but with no instructions so i couldn't bend it to ruby . of course there were other problems ,but they are solved now . thank you again
  • Melvin
    Melvin almost 8 years
    Downgrade to Ruby 2.2.5 if you are having issues. In my case, Rails 5.0.0 doesn't play well with Ruby 2.3.1.
  • Jonathan Soifer
    Jonathan Soifer over 7 years
    @MelvinCh'ng I'm also having issues with Rails 5 + Ruby 2.3.1 and some gems (nio4r, pg, puma, websocker-driver). Is this a known issue?
  • Melvin
    Melvin over 7 years
    @JonathanSoifer If you are having that issues on Windows, it is recommended to downgrade your Ruby to 2.2.3. Many people have issues when running Ruby 2.3.1 on Windows. Latest version of Ruby works well on Mac.
  • Jonathan Soifer
    Jonathan Soifer over 7 years
    @MelvinCh'ng Mac :)
  • Saravanabalagi Ramachandran
    Saravanabalagi Ramachandran over 7 years
    I did it the other way..! installed x64 ruby with x32 devkit, realised it only when I tried to go see the gems in their directory for inspection,,, And saved my day :)
  • gizotti
    gizotti over 7 years
    This is highly unrecommended. It might end up update gems you don't want to.
  • Jimbali
    Jimbali about 7 years
    lol tried various things for 2 hours and this was the solution. 😂 Well done that boy!
  • Grilse
    Grilse almost 7 years
    Updating the gem nio4r from v2.0.0 to v2.1.0 resolved the problem for me.
  • Ben Hull
    Ben Hull over 5 years
    To expand on @gizotti's comment, Gemfile.lock is the file which stores the gem dependency tree and the precise versions of each gem your project uses. If Gemfile is the recipe, Gemfile.lock is the cake you baked from the recipe. If you remove it, Bundler will rebuild a new one based on your Gemfile, which means you may end up with different versions of any gem in the tree in your project. For serious projects, that means lots of testing and validation, and not something you want to 'just do'. In any case, you can achieve basically the same thing by running bundle update.
  • Даниил Пронин
    Даниил Пронин about 4 years
    @BenHull this comment is the greatest text about lockfiles I ever read