【问题标题】:Why do I get an error installing the JSON gem in Ubuntu?为什么在 Ubuntu 中安装 JSON gem 时会出错?
【发布时间】:2012-06-15 22:31:28
【问题描述】:

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

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

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

【问题讨论】:

    标签: ruby-on-rails ruby json ubuntu gem


    【解决方案1】:

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

    sudo apt-get install ruby1.9.1-dev
    

    【讨论】:

    • 并非如此,“devkit”只是设置了编译需要它的扩展所必需的钩子和选项。 JSON gem 使用extensions written in C for speed。如果您真的不想(或不能)安装 devkit,您可以使用gem install json pure 安装纯 ruby​​ 平台。
    • 谢谢!使用sudo apt-get install ruby-dev 会不会更好,以便 Ubuntu 自己选择合适的版本?
    • 是和不是。 Ubuntu 的“默认”红宝石 - 即使最新的 Quantal 是 1.8,并且许多应用程序需要 1.9 或更高版本,因此您可能必须指定才能获得所需的版本,而不是可能已过时的默认存储库 pacakge。
    • @Simon 和 RecentCoin 谢谢,安装错误的 ruby​​-dev 是我的错误来源。看了你的cmets才意识到。
    • 这对我不起作用,但我显然没有 build-essential:$ sudo apt-get install build-essential
    猜你喜欢
    • 2015-11-10
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    相关资源
    最近更新 更多