Tom
Tom

Reputation: 91

Error installing the json gem on Windows

I am new to ruby on rails, I am trying to get my first project working with git and heroku. I am following the tutorial by Michael Hartl. I was originally trying to

git push heroku master

but I dont have a GemFile.lock, so I have been trying bundle installs and bundle updates but nothing works because I dont have the json native gem.

bundle update

this is the command that reuturned this error, its not the whole error i left out all the gems i already have

Installing json (1.7.3) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        "C:/Program Files/ruby-1.9.3/bin/ruby.exe" extconf.rb
creating Makefile

make
Makefile:160: warning: overriding commands for target `C:/Program'
Makefile:153: warning: ignoring old commands for target `C:/Program'
C:/Program Files/ruby-1.9.3/bin/ruby -e "puts 'EXPORTS', 'Init_parser'"  > parser-i386
mingw32.def
/bin/sh: C:/Program: No such file or directory
make: *** [parser-i386-mingw32.def] Error 127


Gem files will remain installed in C:/Program Files/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/json-1.7.3 f
or inspection.
Results logged to C:/Program Files/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/json-1.7.3/ext/json/ext/parser/gem_make.out
An error occured while installing json (1.7.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.3'` succeeds before bundling.

If anybody knows how to fix my error so that i can move onto the next one or how i can get a working GemFile.lock, it would be appreciated.

Upvotes: 1

Views: 4005

Answers (3)

nfriend21
nfriend21

Reputation: 2200

I had the same problem and found that in my config.yaml file, there was an installation of Ruby 1.9.2 that had a space in it. I had to uninstall that version of Ruby entirely, and remove it from the PATH in environment variables. Then, I re-installed the DevKit and it worked perfectly.

Upvotes: 0

Casper
Casper

Reputation: 34338

Install json_pure instead on your development machine. This is a version of the json gem that does not require C-extensions (but is a bit slower).

On Heroku you should be able to go with the faster json directly.

If you want to build the C-extension on windows then you might want to look here:
The 'json' native gem requires installed build tools

You can create a windows-specific section in the Gemfile like so:

# Common gems
gem 'xyz'
...

# Platform specific gems
platforms :ruby do
  gem 'json'
end

platforms :mswin, :mingw do
  gem 'json_pure'
end 

Upvotes: 4

Nick Colgan
Nick Colgan

Reputation: 5518

Windows isn't properly escaping the space in "C:\Program Files". I haven't used Windows in a while, but a quick search reveals a few fixes.

Upvotes: 3

Related Questions