13

I don't know install mysql2 on ubuntu :(

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

current directory: /var/lib/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
/usr/bin/ruby2.3 -r ./siteconf20160515-9715-1s2u1sj.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.3.0/gems/mysql2-0.4.4 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/mysql2-0.4.4/gem_make.out

sudo apt-get install libmysqlclient-dev

Lendo listas de pacotes... Pronto
Construindo árvore de dependências       
Lendo informação de estado... Pronto
libmysqlclient-dev is already the newest version (5.7.12-0ubuntu1).
0 pacotes atualizados, 0 pacotes novos instalados, 0 a serem removidos e 61 não atualizados.

but is not working

Victor Igor
  • 871
  • 2
  • 7
  • 10
  • rake test `Could not find gem 'mysql2 (< 0.5, >= 0.3.13)' in any of the gem sources listed in your Gemfile or available on this machine.` Run `bundle install` to install missing gems. – Victor Igor May 15 '16 at 16:35
  • 1
    Do you have ruby dev environment installed? `sudo apt-get install ruby-dev` – Dawcars May 15 '16 at 16:44
  • Check if you have all the other requirements to build the native extensions of the mysql2 gem. – Ed de Almeida May 15 '16 at 17:02
  • http://stackoverflow.com/questions/3608287/error-installing-mysql2-failed-to-build-gem-native-extension – Ed de Almeida May 15 '16 at 17:05

3 Answers3

50

First, install libmysqlclient-dev using:

sudo apt-get install libmysqlclient-dev

Then:

bundle 
Zorencen R
  • 576
  • 4
  • 6
6
sudo apt-get install libnetcdf-dev libssl-dev libcrypto++-dev libgmp-dev

has resolved same issue for me

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Manohar
  • 69
  • 1
  • 3
1
sudo apt-get install ruby-mysql2
  • 1
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Donald Duck Jan 19 '17 at 15:52
  • This way is installing the "ruby-mysql2" OS package which might result in installing wrong or too old versions (depends on the OS) – Ivailo Bardarov Jan 03 '19 at 10:26