8

I wanted to install the rspec-rails gem with ruby 1.9.3 on windows 7. I got some errors saying that some json libraries could not be installed. So, I used the instructions below to solve it. Source = The 'json' native gem requires installed build tools

  1. Download [Ruby 1.9.3][2] from [rubyinstaller.org][3]
  2. Download DevKit file from [rubyinstaller.org][3]
    • For Ruby 1.9.3 use [DevKit-tdm-32-4.5.2-20110712-1620-sfx.exe][4]
  3. Extract DevKit to path C:\Ruby193\DevKit
  4. Run cd C:\Ruby193\DevKit
  5. Run ruby dk.rb init
  6. Run ruby dk.rb review
  7. Run ruby dk.rb install

To return to the problem at hand, you should be able to install JSON (or otherwise test that your DevKit successfully installed) by running the following commands which will perform an install of the JSON gem and then use it:

gem install json --platform=ruby
ruby -rubygems -e "require 'json'; puts JSON.load('[42]').inspect"

When I execute the above first step, I get the error -

C:\Ruby193\DevKit>gem install json --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing json:
        ERROR: Failed to build gem native extension.

        C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile

make
'make' is not recognized as an internal or external command,
operable program or batch file.

Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection. Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

I am trying to solve the above error now -

'make' is not recognized as an internal or external command, operable program or batch file. using make is not recognized as an internal or external command - Qt SDK - Windows

If someone already knows how to fix this, then please help me. I have been struggling to install gems and I am failing for so many days. I am wondering if ruby is so difficult.

The DOSKEY approach failed !!!

I did this - Install Mingw and installed all its developer tools and base stuff. Then added C:\MinGW\bin to environment variables to find mingw32-make.exe. Then, I ran the DOSKEY make=mingw32-make followed by the ruby command. I got the same error. I am guessing that the ruby code is spawning off a hidden cmd window and thats why the command is not working. DOSKEY is valid only in the cmd window in which you run it.

Next step - Not so nice, but, I'll change mingw32-make.exe to make.exe and see.

Failed again with a new error -

Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... ERROR: Error installing json: ERROR: Failed to build gem native extension.

    C:/Ruby193/bin/ruby.exe extconf.rb creating Makefile

make generating generator-i386-mingw32.def compiling generator.c In file included from generator.c:1:0: ../fbuffer/fbuffer.h:5:18: fatal error: ruby.h: No such file or directory #include "ruby.h" ^ compilation terminated. Makefile:204: recipe for target 'generator.o' failed make: *** [generator.o] Error 1

Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection. Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

What do I do now ?

Community
  • 1
  • 1
stack1
  • 1,004
  • 2
  • 13
  • 28

5 Answers5

16

Most of the Ruby gems are developed for Unix and require some extra tools to make it work on Windows.

In order to install those gem in Windows, you need Ruby DEVELOPMENT KIT from the download link (choose the correct installer based on your Ruby version).

Extract the installation to some permanent location. In my system, it is C:\RubyDevKit.

Open command prompt and cd to the extracted location and execute the following commands

cd C:\RubyDevKit
ruby dk.rb init
ruby dk.rb install
devkitvars.bat

The last command is what I missed initially and took sometime to figure out. Now try installing your gem; it worked for me.


Additional Information

The Ruby Development Kit has a component called MinGW which is used to run Unix command on Windows.

The below error, in my case, was Ruby Development Kit not added to the system path variable

make 'make' is not recognized as an internal or external command, operable program or batch file.

The command devkitvars.bat adds the Development Kit to the system path.

Kalyan
  • 1,781
  • 11
  • 15
  • 1
    The `devkit` should be injected into your `PATH` whenever you install a `gem` that requires the `devkit`. If you have to run `devkitvars.bat` it means something is wrong with your `devkit` installation, but installing `gem`s works because it's doing what the script is supposed to do, just in your entire shell instead of the single installing process. – Azolo Oct 06 '16 at 20:54
  • I did exactly what u described and after cd´ing to the folder and entering first command: `ruby dk.rb init`, it says: `ruby: No such file or directory -- dk.rb (LoadError)` – ints Mar 11 '23 at 08:53
1

Try installing gnuwin-32 make and then change environment variable PATH to point to C:\Program Files (x86)\GnuWin32\bin

Rujoota Shah
  • 1,251
  • 16
  • 18
1

Ruby installation wizard asks you "Add Ruby executables to your PATH", for me, easy solution is to uninstall ruby and install again, this time checking the check box "Add Ruby executables to your PATH"

enter image description here

Fahad
  • 346
  • 2
  • 16
0

With the latest version of Ruby 2.4.2, the dev kit is included in the installation so you don't need to follow the separate install instructions. Just uninstall existing ruby and reinstall the new one here https://rubyinstaller.org/downloads/.

Once finished, it'll open up a command prompt on which you need to select option 3 to include the dev kit. However, at the time of writing it's so buggy and you may or may not have issues installing.

friek108
  • 1,064
  • 1
  • 12
  • 23
-6

I have tried to setup ruby on rails on a windows system, although there are one click installers that install ruby itself and rails, many of the gems rely on a posix based operating system to be compiled, thus making it near impossible to do actual work on windows.

My advise would be to get yourself a linux system, perhaps unbuntu on your system and dual boot, or get a virtual pc software, like this one, or any of the other options, and try installing ruby from there.

Saifis
  • 2,197
  • 1
  • 22
  • 36
  • See, this is ridiculous. This is why I absolutely HATE open source. – Christine Jan 09 '16 at 00:07
  • well it works fine on virtually anything other than windows,its more of a windows issue than an open source issue – Saifis Jan 09 '16 at 00:42
  • The answer to his question is that you have to set up the environment variables in command prompt... not to just completely turn his back on his environment and go with a totally different OS. The issue at hand is cause primarily by open source garbage because open source developers think they're above developing things that are compatible for Windows. Most third-party apps have install packages that run out of the box on any Windows machines, EXCEPT a good number of open source apps. This garbage is SPECIFIC to open source software. – Christine Jan 09 '16 at 01:05
  • Your insinuation is garbage. It's like, if I had a political vendetta against foreign cars, so I developed a car batter that's specifically designed ONLY to work on American made cars. Now, would that be Honda's fault that my battery doesn't work in their cars, or would it be MY fault? Open Source developers neglect Windows users, then act like Windows sucks because THEIR software isn't compatible with Windows systems. That's just bullcrap imo. – Christine Jan 09 '16 at 01:09
  • 1
    I mean, this is just a bad answer. If I had the reputation, I would straight downvote it simply because of your elitist little "It doesn't work because Windows sucks" answer. Windows is used by the VAST majority of PC users and developers. So, regardless of your personal feelings about it, if your software can't work on a Windows machine out of the box without jumping through all these hoops, your software sucks. I'm sorry. – Christine Jan 09 '16 at 01:13
  • I wonder how this answer is marked as an accepted answer. – Sanan Ali Sep 15 '21 at 07:28