codedecoder

breaking into the unknown…

Failed to build gem native extension

Leave a comment

While, running bundle install, many a time you encounter this error message :  Failed to build gem native extension . what I understand from my observation is that, these are the gems which have some dependency on you local resources. Example, when you install Mysql gem, it do not really install Mysql for you but expect that Mysql client and Mysql server is already installed in your system (you need to install it manually on your system) and through its native extension it just configure your application with Mysql.To build these native extension, the gem need some predefined package on your system which basically facilitate the build. So whenever, you get this error you just need to install the required package on your system. I will keep updating the dependency for different gem whenever I will come across them.

Below is the list of dependency for different gem to build there native extensions. They are listed with there install command

1 -> Mysql

$ sudo apt-get install libmysqlclient-dev # will install libmysqlclient-dev

2 -> pg

$ sudo apt-get install libpq-dev # will install libpq-dev

3 -> gherkin

Here, I do not installed any dependency, but installing the current version of gherkin gem solved the problem. This is a known issue with the gherkin gem itself and has been fixed in the current release. more detail on this issue is available here

4 -> therubyracer

When I run bundle install, it tried to install therubyracer version 0.11.0 with native extension, but failed to build the native extension. Some detail of solution is available here on stackoverflow. But, It didn’t solve my problem, So I explicitly mentioned the older version 0.10.2 of therubyracer in my gem file which do not need native extensions.

gem ‘therubyracer’ #removed this line, which install the current version 0.11.0 and need native extension

gem ‘therubyracer’, ‘0.10.2’ #added this line, it will install the older version which do not need native extension.so it will work

5 -> passenger

You may get this error for passenger with below detail:

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

So the ruby header file is missing here.

It can be solved by installing the ruby header , they are present in different package under different linux flavour

for ubuntu use:

$ sudo apt-get install ruby-dev

for centos use:

$ sudo yum install ruby-devel

 6 -> nokogiri

Below packages are required for it libxml2 libxslt

for ubuntu use:

$ sudo apt-get install libxml2-dev

$ sudo apt-get install libxslt-dev

for centos use:

$ sudo yum install libxml2-devel

$ sudo yum install libxslt-devel

 

7 => pg

It give error like

Can't find the 'libpq-fe.h header.

Below packages are required for it pg dev package is required

for ubuntu use:

$ sudo apt-get install libpq-dev

for centos use:

$ sudo yum install postgresql-devel

$ sudo yum install postgresql-libs

for mac use below:

$ brew install libpqxx

 

8 => json

It throw below error:

cannot load such file — mkmf (LoadError)

The mkmf file is present in ruby-dev package . Installing it will solve the problem

$sudo apt-get install ruby-dev

9 => capybara-webkit

for Ubuntu 14.04 and up installing below package will solve the problem

$sudo apt-get install libqt4-dev

for othe OS see this link

Author: arunyadav4u

over 10 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

Leave a comment