Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot install gem - make is not recognized as an internal or external command operable program or batch file

Tags:

ruby

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 ?

like image 368
stack1 Avatar asked Dec 01 '14 23:12

stack1


2 Answers

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.

like image 51
Kalyan Avatar answered Oct 02 '22 01:10

Kalyan


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

like image 25
Rujoota Shah Avatar answered Oct 02 '22 02:10

Rujoota Shah