gem install: Failed to build gem native extension (can't find header files)

MysqlRubyRubygems

Mysql Problem Overview


I am using Fedora 14 and I have MySQL and MySQL server 5.1.42 installed and running. Now I tried to do this as root user:

gem install mysql

But I get this error:

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

/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

What's wrong here? In installed ruby 1.8.7. and the latest rubygems 1.3.7.

Mysql Solutions


Solution 1 - Mysql

For those who may be confused by the accepted answer, as I was, you also need to have the ruby headers installed [ruby-devel].

The article that saved my hide is here.

And this is the revised solution (note that I'm on Fedora 13):

yum -y install gcc mysql-devel ruby-devel rubygems
gem install -y mysql -- --with-mysql-config=/usr/bin/mysql_config

For Debian, and other distributions using Debian style packaging the ruby development headers are installed by:

sudo apt-get install ruby-dev

For Ubuntu the ruby development headers are installed by:

sudo apt-get install ruby-all-dev

If you are using a earlier version of ruby (such as 2.2), then you will need to run:

sudo apt-get install ruby2.2-dev

(where 2.2 is your desired Ruby version)

Solution 2 - Mysql

Red Hat, Fedora:

yum -y install gcc mysql-devel ruby-devel rubygems
gem install -y mysql -- --with-mysql-config=/usr/bin/mysql_config

Debian, Ubuntu:

apt-get install libmysqlclient-dev ruby-dev
gem install mysql

Arch Linux:

pacman -S libmariadbclient
gem install mysql

Solution 3 - Mysql

For anyone reading this in 2015: if you happened to install the package ruby2.0, you need to install the matching ruby2.0-dev to get the appropriate Ruby headers. The same goes for ruby2.1 and ruby2.2, etc. For example:

$ sudo apt-get install ruby2.2-dev

Solution 4 - Mysql

it seems that the

yum install ruby-devel

was enough for me to perform

gem install datamapper

afterwards.

It's possible that you will need to install another packages:

yum install gcc gcc-c++

to be able to build native extensions

Solution 5 - Mysql

MAC users may face this issue when xcode tools are not installed properly. Below is the command to get rid of the issue.

xcode-select --install

Solution 6 - Mysql

I found the solution here.

# yum install mysql-devel gcc make
# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

Solution 7 - Mysql

This post helped me. Thanks a lot.

On Linux (Ubuntu 12.10) I needed to run

sudo apt-get install ruby
sudo apt-get install rubygems
sudo apt-get install ruby-dev

before I could succesfully run

sudo gem install jekyll

Solution 8 - Mysql

If you have gem installed and ruby and not able to install rails, then install ruby dev lib.

sudo apt-get install ruby-dev

It works for me. I have tried the different solution.

Solution 9 - Mysql

Red Hat, Fedora:

sudo dnf -y install gcc-c++ redhat-rpm-config ruby-devel gcc mysql-devel rubygems

Solution 10 - Mysql

For those that are still experiencing problems, like I have(I am using Ubuntu 16.04), I had to put in the following commands in order to get some gems like bcrypt, pg, and others installed. They are all similar to the ones above except for one.

sudo apt-get install ruby-dev -y
sudo apt-get install libpq-dev -y
sudo apt-get install libmysqlclient-dev
sudo apt-get install build-essential patch -y

This allowed me to install gems like, PG, bcrypt, and recaptcha.

Solution 11 - Mysql

My initial solution was to resolve the above errors by installing ruby-devel, patch and rubygems.

My issue was a bit different as bcrypt 3.1.11 still had issues compiling and installing on Fedora 23. I needed additional packages. So after ensuring I had the above installed, I was still having issues:

gcc: error: conftest.c: No such file or directory

gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory

From here I had to do the following:

  • I ensured that I wasn't lacking any C compiler tools sudo dnf group install "C Development Tools and Libraries"

  • Then I ran sudo dnf install redhat-rpm-config to resolve the gcc issue listed above.

You can find a write up here on Fedore Project. You may also find answers to other needs as well.

Solution 12 - Mysql

sudo apt-get install ruby-dev

This command solved the problem for me!

Solution 13 - Mysql

You need following packages instaled:

  • ruby-dev

  • gcc

  • libffi-dev

  • make

Here's the command for debian distro:

 sudo apt install gcc ruby-dev rubygems libgmp-dev libgmp3-dev make 

Solution 14 - Mysql

in openSUSE:

zypper in ruby-devel

Works to me :)

Solution 15 - Mysql

It's necessary to install redhat-rpm-config to. I guess it solve your problem!

Solution 16 - Mysql

This worked for me:

yum -y install gcc mysql-devel ruby-devel rubygems

Solution 17 - Mysql

You might have messed up with the RVM.

Try to do:

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

Solution 18 - Mysql

Just to add path to ruby.h file in my PATH
for example:

> export PATH=$PATH:/usr/src/ruby-xxxxxx

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTimView Question on Stackoverflow
Solution 1 - MysqlBrian LacyView Answer on Stackoverflow
Solution 2 - MysqlNowakerView Answer on Stackoverflow
Solution 3 - MysqlDror S.View Answer on Stackoverflow
Solution 4 - MysqlandrejView Answer on Stackoverflow
Solution 5 - MysqlAjit SinghView Answer on Stackoverflow
Solution 6 - MysqlTimView Answer on Stackoverflow
Solution 7 - MysqlqkrijgerView Answer on Stackoverflow
Solution 8 - MysqlHafiz Shehbaz AliView Answer on Stackoverflow
Solution 9 - MysqlmkunglaView Answer on Stackoverflow
Solution 10 - MysqlMikeView Answer on Stackoverflow
Solution 11 - MysqlAndrew LobbanView Answer on Stackoverflow
Solution 12 - MysqlViduni WickramarachchiView Answer on Stackoverflow
Solution 13 - MysqlrmpestanoView Answer on Stackoverflow
Solution 14 - MysqlRaul LibórioView Answer on Stackoverflow
Solution 15 - MysqlalvescleitonView Answer on Stackoverflow
Solution 16 - MysqlShveta SachdevaView Answer on Stackoverflow
Solution 17 - MysqlAadhyaView Answer on Stackoverflow
Solution 18 - MysqlMaregView Answer on Stackoverflow