Ruby-on-rails 为什么在 Ubuntu 中安装 JSON gem 时出现错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11058952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 03:32:52  来源:igfitidea点击:

Why do I get an error installing the JSON gem in Ubuntu?

ruby-on-railsrubyjsonubuntugem

提问by TownWizard

Using Ubuntu, when I run "bundle install" to set up my Rails environment, it throws an error during the JSON gem installation:

使用 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.

When I try installing only the JSON 1.7.3 gem it also gives me an error:

当我尝试仅安装 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

I've installed RVM and am running Ruby 1.9.3; Why can't it install the JSON gem?

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

回答by Dylan Markow

Installing the ruby1.9.1-devpackage should fix this for you:

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

sudo apt-get install ruby1.9.1-dev