0

I can't find this specific error in the web but when typing sudo gem install rails -v 5.2.2 I get the following error:

    nysa@nysa-System-Product-Name:~$ sudo gem install rails -v 5.2.2
Fetching activesupport-5.2.2.gem
Fetching actionview-5.2.2.gem
Fetching actionpack-5.2.2.gem
Fetching railties-5.2.2.gem
Fetching activerecord-5.2.2.gem
Fetching activemodel-5.2.2.gem
Fetching activestorage-5.2.2.gem
Fetching actioncable-5.2.2.gem
Fetching activejob-5.2.2.gem
Fetching actionmailer-5.2.2.gem
Fetching rails-5.2.2.gem
Successfully installed activesupport-5.2.2
Successfully installed actionview-5.2.2
Successfully installed actionpack-5.2.2
Successfully installed railties-5.2.2
Successfully installed activemodel-5.2.2
Successfully installed activerecord-5.2.2
Successfully installed activestorage-5.2.2
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.5.0/gems/websocket-driver-0.7.1/ext/websocket-driver
/usr/bin/ruby2.5 -I /usr/local/lib/site_ruby/2.5.0 -r ./siteconf20190626-19849-1302wcu.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/websocket-driver-0.7.1 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/websocket-driver-0.7.1/gem_make.out

Looks like I have already a rails version installed but when typing rails -v I get a message that 'rails' doesn't exist. How can I make install the latest version of Rails and make this work?

Reyneer Leon
  • 21
  • 1
  • 3

1 Answers1

0

Installing rails involves compiling some C source code, which requires the header files of whatever libraries the C code happens to use. At minimum, the ruby-dev package must be installed, as that provides the header files for Ruby itself. The specific error you've seen appears to be due to its absence, since /usr/lib/ruby/include/ruby.h is absence.

Installing ruby-dev is often sufficient to solve this problem. However, I've found that, on recent Ubuntu systems that don't have zlib1g-dev installed, I need that too. My guess is that people often have it installed already and that this is why it is less often necessary to install.

sudo apt update
sudo apt install ruby-dev zlib1g-dev

After you install those packages, you can simply run your gem install command again. If there are more errors that talk about not being able to find header files, you can install the appropriate -dev packages, but I don't expect there to be anything else you need to install.

Installing ruby-dev also sometimes fixes gem install problems whose error mentions don't name a missing header file.


Depending on what you are trying to do, you might also consider the alternatives of:

Eliah Kagan
  • 117,780