5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gem install rails で"... can't find header files for ruby"

Posted at

ruby, riのインストール後、railsのインストールでエラーが発生。

    current directory: /var/lib/gems/2.3.0/gems/nokogiri-1.8.1/ext/nokogiri
/usr/bin/ruby2.3 -r ./siteconf20180106-13919-1x409ih.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

たしかに/usr/lib/rubyの下に includeディレクトリが無い。

環境
OS: ubuntu 16.04
ruby: 2.3
rails: 5.1.4

ruby-dev のインストール後にrailsをインストールしたら成功。

rubyのインストール時「提案パッケージ」にruby-devが出ていたが、無視していた。

$ sudo apt install ruby
    ...
提案パッケージ:
  ri ruby-dev
以下のパッケージが新たにインストールされます:
  libruby2.3 rake ruby ruby2.3
    ...
$ sudo apt install ri
    ...
$ sudo gem install rails
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
	ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/nokogiri-1.8.1/ext/nokogiri
/usr/bin/ruby2.3 -r ./siteconf20180106-13919-1x409ih.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.3.0/gems/nokogiri-1.8.1 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.8.1/gem_make.out

このエラー後、ruby-dev をインストール

$ sudo apt install ruby-dev
 
   ...
以下のパッケージが新たにインストールされます:
  libgmp-dev libgmpxx4ldbl ruby-dev ruby2.3-dev
    ...

その後、railsのインストールに成功

$ sudo gem install rails

参考

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?