14

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 .

techdreams
  • 5,371
  • 7
  • 42
  • 63
Mfms99
  • 143
  • 1
  • 1
  • 7
  • gem install nio4r -v '1.2.1' run and/ it will solve your error – Vishal Jul 20 '16 at 11:53
  • it returns this : http://pastebin.com/czfiV0Gb – Mfms99 Jul 20 '16 at 11:57
  • 1
    When asking questions, please always include the error full log directly into the question. Please don't link to external pastie sites since the logs there tend to vanish quickly, making the question way less useful in the future. – Holger Just Jul 20 '16 at 11:59

10 Answers10

8

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/

Melvin
  • 376
  • 4
  • 18
  • 1
    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 – Mfms99 Jul 21 '16 at 22:59
  • 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. – Melvin Jul 22 '16 at 04:07
  • @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? – Jonathan Soifer Nov 02 '16 at 12:46
  • @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. – Melvin Nov 05 '16 at 21:25
  • @MelvinCh'ng Mac :) – Jonathan Soifer Nov 05 '16 at 21:46
4

Solution for Fedora 64bit

sudo dnf install redhat-rpm-config
lord5et
  • 422
  • 7
  • 6
2

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.

techdreams
  • 5,371
  • 7
  • 42
  • 63
2

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. brew unlink gcc worked

Tox
  • 135
  • 1
  • 10
equivalent8
  • 13,754
  • 8
  • 81
  • 109
1

I came across this problem as i was setting up rails too. (looking for an alternative to php).

  • I realized that i had installed x86 ruby with x64 Devkit, so i first downloaded x64 ruby which i installed and uninstalled the x86 version. I made sure my path variables were well set.
  • Then i installed devkit using the instructions on this page http://rubyonwindowsguides.github.io/book/ch02-04.html
  • Finally i installed rails and it worked fine without the errors this time

Hope this helps

1

My son fixed this problem for me. The problem was that I installed first, Ruby and then the Rails installer. So I had to uninstall Ruby and reinstall with the Rails installer only.

1

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!

keke
  • 54
  • 1
  • 4
0

Remove the Gemfile.lock and run bundle install command

Hemanthkumar Naik
  • 151
  • 1
  • 3
  • 11
  • 1
    This is highly unrecommended. It might end up update gems you don't want to. – gizotti Dec 23 '16 at 12:30
  • Updating the gem nio4r from v2.0.0 to v2.1.0 resolved the problem for me. – Grilse Jun 12 '17 at 07:21
  • 1
    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`. – Ben Hull Dec 03 '18 at 13:08
  • 1
    @BenHull this comment is the greatest text about lockfiles I ever read – Даниил Пронин Feb 12 '20 at 04:46
0

To quote from your log output:

The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first.

On windows, you need to install the DevKit in order to be able to compile gems.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
  • 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 Jul 20 '16 at 12:12
  • should i install a certain version of DefKit ? i have installed version 2.2.5 – Mfms99 Jul 20 '16 at 12:18
0

If you use Windows and installed ruby with RubyInstaller with version more or equal to 2.4, than you should not install DevKit from RubyInstaller website and only use 'msys64' which is installed after Ruby with RubyInstaller (make sure you type number 3 to install both msys and mingw). Delete devkit directory and its path from PATH environment variable, so when rubygems will try to install nio4r and call C compilers, it will call msys ones. Read here https://rubyinstaller.org/2017/05/25/rubyinstaller-2.4.1-1-released.html for more info about MSYS2 and DevKit in RubyInstaller

SkipIntro
  • 124
  • 1
  • 6