ruby-on-rails – 无法加载此类文件 – mkmf(LoadError)

使用rbenv,runnng bundle install,并在安装Json 1.8.1时出错.

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>'

尝试通过apt安装ruby-dev(不确定无论如何都会有所帮助,因为ruby是通过rbenv安装的)

可能有帮助的东西?

$which gem
/home/ubuntu/.rbenv/shims/gem
$which ruby
/home/ubuntu/.rbenv/shims/ruby
$locate mkmf
/home/ubuntu/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/mkmf.rb
/home/ubuntu/.rbenv/versions/1.9.3-p484/share/ri/1.9.1/system/Object/mkmf-i.ri
/usr/local/rvm/gems/ruby-2.2.1/extensions/x86_64-linux/2.2.0/nokogiri-1.6.6.2/mkmf.log
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb

最佳答案 基于您的locate命令,您在rvm和ubuntu的home diretory中有mkmf,但在系统上没有,并且您明确使用系统的ruby(而不是rbenv或rvm)来运行extconf.rb.从您拥有mkmf的其中一个环境中运行ruby,或者在系统上安装ruby-dev软件包.

点赞