Error Installing Rails: Can't Find Header Files


#1

I apologize if this has been addressed in a previous post that I might not have found when searching the forums for a solution to my problem, but I can’t get rails to install on my machine (Linux Mint 18.3). There is a dependency issue when installing rails based on the error:
$ 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.4/ext/nokogiri

/usr/bin/ruby2.3 -r ./siteconf20180828-1145-m699g6.rb extconf.rb
mkmf.rb can’t find header files for ruby at /usr/lib/ruby/include/ruby.h

I checked that the version of Ruby installed in the previous steps of Web Development 101 was the correct version:
$ ruby -v

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

Does anyone have any insight into what my problem might be? Obviously rails intends to use files that don’t exist, meaning that Ruby must not have installed properly, but I’m not sure how to address that other than removing rbenv and Ruby, and reinstalling.

Thank-you in advance.


#2

Hi @markw444

You shouldn’t install any gem with sudo. gem install rails is all you need.

Try that and see if it installs. If you still get an error let me know here.


#3

I’ve successfully installed rails–I had to delete the rbenv directory, remove the references in .bashrc, then complete the process as before. I don’t know why this didn’t work the first time–in reference to CouchofTomato’s reply, I didn’t initially use “sudo gem install rails” on the first install attempt to use gem to install rails–after it failed the initial install subsequent attempts resulted in a prompt for use of ‘sudo’. I found it curious that rbenv is not actually installed as a package–Synaptic Package Manager indicates that there is no rbenv package installed and the typical terminal commands for removing a package do not work, although ‘rbenv -v’ is recognized. In other words, the only way to remove rbenv is to delete the directory created at ~/.


#4

Hey @markw444

Glad you got it sorted.


#5

oh no! I did not know about the sudo thing and installed it with sudo! I feel like an idiot now. :disappointed:

I wanted to add to this answer that I was getting a similar error for Nokogiri and this is what worked for me on Linux Mint 19.

This was the error I was getting:
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/nokogiri-1.8.4/ext/nokogiri

/usr/bin/ruby2.5 -r ./siteconf20180930-20843-dcey9h.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.4 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.8.4/gem_make.out

This is what worked for me:
sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
and then gem install nokogiri
as stated in the official website --> http://www.nokogiri.org/tutorials/installing_nokogiri.html


#6

brother, thanks so much, you were my master now Lol thanks bother I have no words to thank ya.