I am able to install the json library using ruby gems. In case it’s relevant, I’m using the latest OS X.
usr$ sudo gem install json
Password:
Building native extensions. This could take a while...
Successfully installed json-1.6.5
1 gem installed
Installing ri documentation for json-1.6.5...
Installing RDoc documentation for json-1.6.5...
However, attempting to require 'json' it doesn’t work. What am I doing wrong?
touakas-MacBook-Pro:tmp jacob$ ruby x.rb
x.rb:3:in `require': no such file to load -- json (LoadError)
from x.rb:2
The x.rb is as follows:
#!/usr/bin/env ruby
require 'json'
x = { "a"=>"b" }
print x.to_json
You need to load RubyGems first:
Edit:
According to the comment below, you’d better use
ruby -rubygems x.rbrather thanrequire rubygemsdirectly (suppose that you’re writing a module for resue).Credit to: @injekt and @Ingenu