0
votes

I'm running Ubuntu 14 and when I try to run rails server but I get this error:

Could not find gem 'mysql2 (>= 0) ruby' in the gems available on this machine. Run bundle install to install missing gems.

So I run the bundle install and then I get the following error.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 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/mysql2-0.3.16 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/gem_make.out
An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.

So I run gem install mysql2 -v '0.3.16' and it installs successfully however when I run bundle install again it gives me the same error:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 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/mysql2-0.3.16 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/gem_make.out
An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.
1
you didn't install all the necessary dependencies before installing ruby. You likely need build-essential and other header files.sevenseacat
@sevenseacat I already have it installed.Rodrigo
I agree with @sevenseacat. Your installation isn't correct for some reason. You might think you have it all installed, but somethings obviously amiss. How did you do the install? Did you do it through Ubuntu's application install mechanism or did you follow directions from the rubyonrails.org site? You may have to back up and start from scratch. I would also recommend using something like rvm.io in the long run if you're serious about RoR development.lurker
I followed the RoR tutorial book online @lurker should I unistall everything and start from scratch?Rodrigo
Yes, I think that's what I'd do. See if you can undo what you have and start from the top. Also I think Ubuntu has installs for it as well. Maybe you have a couple of different versions of things going on.lurker

1 Answers

0
votes

Start again from scratch and this time you should install RVM as it is really good at handling all this stuff for you. http://rvm.io/rvm/install

Make sure you get all the dependencies first, this code will check to see what you have and don't have:

for name in {bash,awk,sed,grep,ls,cp,tar,curl,gunzip,bunzip2,git,svn} ; do which $name ;  done

Its also worth looking at the prerequisites page: http://rvm.io/rvm/prerequisites

You can run the below code to install rvm with Ruby 2.1.1 and Rails:

\curl -sSL https://get.rvm.io | bash -s stable --rails

Then To start using RVM:

/bin/bash --login

Its definitely worth using RVM it will make your life much easier when managing your ruby versions, gems etc, just make sure you read through the webpage so that you know how to use it.