shubham sharma
shubham sharma

Reputation: 31

Nokogiri and Rails wont install. [Ruby On Rails]

So I have been following this guide to learn ruby on rails. I just installed ubuntu and was making an effort to install the required gear but I am facing a lot of problems. I tried searching online but couldn't really find a solution. So basically, Im following this guide (https://www.railstutorial.org/book), and I was learning how to make my first app. There was this point after installing lots and lots of stuff where I was asked to modify the gemfile with the following text.

source 'https://rubygems.org'

gem 'rails',                '4.2.0.rc3'
gem 'sass-rails',           '5.0.0.beta1'
gem 'uglifier',             '2.5.3'
gem 'coffee-rails',         '4.1.0'
gem 'jquery-rails',         '4.0.0.beta2'
gem 'turbolinks',           '2.3.0'
gem 'jbuilder',             '2.2.3'
gem 'sdoc',                 '0.4.0', group: :doc

group :development, :test do
  gem 'sqlite3',     '1.3.9'
  gem 'byebug',      '3.4.0'
  gem 'web-console', '2.0.0.beta3'
  gem 'spring',      '1.1.3'
end

And I had ruby before itself but it was outdated so I updated it to 2.1.5. Now when I used the command "bundle install" it gave me errors saying it couldnt install rails and nokogiri. I tried installing rails and nokogiri seperately too but it didnt work out. Here's the error:

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

    /usr/bin/ruby2.1 -r ./siteconf20141220-9232-x08jtr.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.1.0/gems/nokogiri-1.6.5 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.5/gem_make.out

And for rails:
Fetching: rack-1.6.0.gem (100%)
Successfully installed rack-1.6.0
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 -r ./siteconf20141220-9321-6z0v97.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.1.0/gems/nokogiri-1.6.5 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.5/gem_make.out

What is happening ? And please do give me a detailed solution because I'm quite new to this.

Thanks for the help in Advance !

Upvotes: 3

Views: 929

Answers (2)

tagCincy
tagCincy

Reputation: 1599

First off, don't try to use the system Ruby for development. That Ruby version is packaged to run specific system level packages for the OS, you can break OS utils by manually updating it or a OS update can break your dev environment. Plus, it will most likely require you run everything as sudo which is just a pain. I recommend installing rvm or rbenv for managing your development rubies.

Now, as for your specific error, you probably just need to install libxml development packages for Ubuntu:

sudo apt-get install libxslt-dev libxml2-dev

Upvotes: 1

Peter Goldstein
Peter Goldstein

Reputation: 4545

It sounds like you didn't install the ruby-dev libraries. So you've got a Ruby VM, but not the libraries required to build gems. Try installing the ruby-dev package.

sudo apt-get install ruby-dev

And then rebundle.

Upvotes: 2

Related Questions