Building native extensions. This could take a while...と出てrailsがインストールできなかった
Railsインストールできない問題
特にWindows民にとっては。Pythonはインストローラーでいい感じになるのに。なんでや・・・。
と愚痴を言っても仕方ないので解決策を。
環境
エラー内容
Building native extensions. This could take a while...
/home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/ext/builder.rb:76: warning: Insecure world writable dir /home/Username/.rbenv/versions in PATH, mode 040777
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
current directory: /home/Username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.3/ext/nokogiri
/home/Username/.rbenv/versions/2.6.3/bin/ruby -I /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20190530-21712-ay2hde.rb extconf.rb
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/Username/.rbenv/versions/2.6.3/bin/$(RUBY_BASE_NAME)
--help
--clean
/home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
from /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:532:in `with_werror'
from /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
from extconf.rb:138:in `nokogiri_try_compile'
from extconf.rb:162:in `block in add_cflags'
from /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:643:in `with_cflags'
from extconf.rb:161:in `add_cflags'
from extconf.rb:416:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/home/Username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/nokogiri-1.10.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/Username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.3 for inspection.
Results logged to /home/Username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/nokogiri-1.10.3/gem_make.out
以下を実行
sudo apt-get install libxslt-dev build-essential ruby-dev zlib1g-dev liblzma-dev libxmlsec1-dev libxml2-dev
これでbundle installすればインストールできます。