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

18

363

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.

Elect answered 29/11, 2010 at 13:58 Comment(3)
Just a quick guess: do you have the dev fileheaders for MySQLMartijn
How can I get these dev fileheaders?Elect
I did it in Ubuntu doing the following: apt-get install ruby-dev rubygems gem install mysql -- with-mysql-config=/usr/bin/mysql_config All works fine.Jarret
T
764

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)

Taub answered 21/12, 2010 at 18:34 Comment(9)
this worked when i had a problem trying to create an app using ruby on rails. it complained about how it can't install json and bundler can't continue. installing ruby-devel worked.Buckram
In addition to ruby-dev posted by @NoBugs above, I also needed libmysqlcient-dev on Ubuntu (12.04). (Or, just see the Debian/Ubuntu answer by Damian Nowak below.)Ear
Worked for me on RHEL6 when I had trouble installing jekyll.Creigh
This helped me install fpm, probably helps install any ruby-based software. I used yum -y install gcc ruby-devel rubygems.Golightly
Life saver. Nothing worked until I reached there before doing "gem install pg". Other install I did before it: postgresql-devel, postgresql-libs, postgresql93-serverWanyen
Not running MySQL on Fedora 22, and rubygems installed with ruby, but ruby-devel certainly worked for me.Conscionable
@SameerAzazi thanks.. updated the link courtesy of the Wayback Machine.Taub
apt-get install ruby2.4-dev did work for me! (And my error was looking for ruby.h in /usr/lib/ruby/include/ruby.h just for context/relevance)Corbeil
This was the missing piece I needed to get it working on WSL running UbuntuObstipation
G
93

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
Gamin answered 29/11, 2010 at 14:5 Comment(5)
Is it this one? mysql-devel.i686 : Files for development of MySQL applicationsElect
For sure mysql-devel is needed. The question is what is needed besides. Maybe try this: fedora-tunisia.org/?q=node/44 Let me know if it works.Gamin
I just had this problem here: #6298251 Good solution!Augend
What you say is required, but it's ruby-devel that's needed to fix the error message in question.Quieten
BTW on RedHat system is ruby-devel.Vizier
S
51

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
Saline answered 26/11, 2014 at 20:30 Comment(3)
On fedora 22: sudo dnf install ruby-develEnterpriser
Thank you! ruby is so weird sometimes.Ensiform
Same goes for ruby 2.3.Scarce
I
25

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

Irishirishism answered 25/9, 2011 at 14:31 Comment(1)
I was getting a very wierd error, without a clear message, and it was because gcc packages were not instaled. :( This post made me remember of this basic step. ;PGeographical
B
10

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
Blowsy answered 23/8, 2015 at 7:25 Comment(2)
yeah, that was the problem. Thanks a lot!Isosteric
And then this sudo gem install -n /usr/local/bin cocoapods thumbsupCedillo
E
8

I found the solution here.

# yum install mysql-devel gcc make
# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
Elect answered 6/12, 2010 at 9:37 Comment(0)
K
8

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
Kaela answered 17/3, 2013 at 0:2 Comment(0)
C
4

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.

Cajole answered 30/11, 2016 at 17:24 Comment(1)
I have Ubuntu 16.04LTS. I think, same will be for other previous version.Cajole
N
3

Red Hat, Fedora:

sudo dnf -y install gcc-c++ redhat-rpm-config ruby-devel gcc mysql-devel rubygems
Neat answered 18/2, 2016 at 23:0 Comment(0)
Q
2

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.

Quorum answered 2/9, 2017 at 22:22 Comment(0)
P
2

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 
Palish answered 17/9, 2018 at 17:27 Comment(0)
S
1

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.

Salmonoid answered 6/5, 2016 at 17:27 Comment(0)
T
1
sudo apt-get install ruby-dev

This command solved the problem for me!

Thenceforth answered 11/4, 2017 at 8:15 Comment(0)
A
0

in openSUSE:

zypper in ruby-devel

Works to me :)

Andry answered 10/8, 2016 at 4:29 Comment(0)
M
0

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

Moorings answered 12/7, 2017 at 20:0 Comment(0)
F
0

This worked for me:

yum -y install gcc mysql-devel ruby-devel rubygems
Fullrigged answered 2/4, 2018 at 19:25 Comment(0)
E
0

You might have messed up with the RVM.

Try to do:

\curl -sSL https://get.rvm.io | bash -s stable --rails
Endoskeleton answered 22/2, 2020 at 12:37 Comment(0)
M
-1

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

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

Mesoglea answered 7/12, 2012 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.