Problem using "gem install rails -v 5.2.3" on XUbuntu 18.04



I tried to install rails using gem install rails -v 5.2.3 as per the instruction. So far everything went fine, and strictly followed the instructions.

ruby -v
ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-linux]

rails -v
Command ‘rails’ not found, but can be installed with:
sudo apt install ruby-railties

I also tried to use gem install rails --version=5.2.3 but nothing changed.

This is what I get when I use gem install rails -v 5.2.3

Building native extensions. This could take a while…
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.

current directory: /home/shift/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.4/ext/nokogiri

/home/shift/.rbenv/versions/2.6.4/bin/ruby -I /home/shift/.rbenv/versions/2.6.4/lib/ruby/2.6.0 -r ./siteconf20191004-2230-16v4k4p.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:
/home/shift/.rbenv/versions/2.6.4/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/shift/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:585:inblock in try_compile’
from /home/shift/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:532:in with_werror' from /home/shift/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:585:intry_compile’
from extconf.rb:138:in nokogiri_try_compile' from extconf.rb:162:inblock in add_cflags’
from /home/shift/.rbenv/versions/2.6.4/lib/ruby/2.6.0/mkmf.rb:643:in with_cflags' from extconf.rb:161:inadd_cflags’
from extconf.rb:416:in `’

To see why this extension failed to compile, please check the mkmf.log which can be found here:


extconf failed, exit code 1

Gem files will remain installed in /home/shift/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.4 for inspection.
Results logged to /home/shift/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/nokogiri-1.10.4/gem_make.out


i also get problems to download of rails…

gem install rails -v 5.2.3
Fetching: activesupport-5.2.3.gem (100%)
ERROR: While executing gem … (Gem::FilePermissionError)
You don’t have write permissions for the /var/lib/gems/2.5.0 directory.


Hello LSubias,

You may find this link and this links useful.


Hey @danieelg

If you are having an issue with nokogiri it usually means nodejs isn’t installed.

A popular package to manage your node versions is nvm but in the installing ruby section there is a command for the command line to install a lot of packages including nodejs. Maybe check you did run that.


I reinstalled everything and now works fine.