为什么我在Ubuntu中安装JSON gem时出错?

Tow*_*ard 22 ruby ubuntu gem json ruby-on-rails

使用Ubuntu,当我运行" bundle install"来设置我的Rails环境时,它会在JSON gem安装期间抛出一个错误:

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

/usr/bin/ruby1.9.1 extconf.rb 
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:1:in `<main>'

Gem files will remain installed in /home/danny/.bundler/tmp/2040/gems/json-1.7.3 for inspection.
Results logged to /home/danny/.bundler/tmp/2040/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.
Run Code Online (Sandbox Code Playgroud)

当我尝试只安装JSON 1.7.3 gem时,它也会给我一个错误:

Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:1:in `<main>'

Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.7.3 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.7.3/ext/json/ext/parser/gem_make.out
Run Code Online (Sandbox Code Playgroud)

我已经安装了RVM并运行了Ruby 1.9.3; 为什么不能安装JSON gem?

Dyl*_*kow 69

安装ruby1.9.1-dev包应该为您解决这个问题:

sudo apt-get install ruby1.9.1-dev
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!使用`sudo apt-get install ruby​​-dev`不是更好,以便Ubuntu自己选择合适的版本吗? (4认同)
  • 是的,不是.Ubuntu的"默认"ruby - 即使最近Quantal是1.8,许多应用程序想要1.9或更高,所以你可能必须指定以获得你想要的版本而不是默认的存储库pacakge,这可能已经过时了. (3认同)