在 Ubuntu 上安装 Nokogiri 失败

Failed While Installing Nokogiri on Ubuntu

我正在尝试在 Ubuntu Linux 上安装 nokogiri。我是 运行 Ruby-2.1.1。我已经安装了。

输出:

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

    current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.8.5/ext/nokogiri
/usr/bin/ruby2.5 -r ./siteconf20181205-6502-3n3u4g.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.5.0/gems/nokogiri-1.8.5 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.8.5/gem_make.out

任何人都可以解释我错过了什么吗?

尝试使用 rbenv 安装 Ruby 2.1.1 并将其设置为 ubuntu 中的默认版本:

    rbenv install 2.1.1
    rbenv global 2.1.1

安装 ruby 后,安装以下软件包:

sudo apt-get install libxslt-dev libxml2-dev zlib1g-dev

然后安装nokogiri:

sudo gem install nokogiri

这应该可以解决问题...