Cannot install gem - make is not recognized as an

2020-07-10 06:55发布

问题:

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 ?

回答1:

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.



回答2:

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.



回答3:

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



回答4:

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"



回答5:

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.



标签: ruby