Focus on IT Recommend

Home > ruby on rails - Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension ubuntu

ruby on rails - Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension ubuntu



While running bundle install i am getting the following error in 'pg' gem i changed the gem as sqlite then too am getting same error. This is my error message.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb 
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:2:in `<main>'

Gem files will remain installed in /var/lib/gems/1.9.1/gems/pg-0.16.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/pg-0.16.0/ext/gem_make.out

An error occurred while installing pg (0.16.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.16.0'` succeeds before bundling.

I tried apt-get install libpg-dev gem install pg -v '0.16.0' nothing helps me

ruby-on-rails gem
  this question
asked Aug 5 '13 at 17:10 overflow 1,445 9 25 67      it should be a dev package missing, see this question or this one –  mdemolin Aug 5 '13 at 17:12      Possible duplicate of… –  MrYoshiji Aug 5 '13 at 18:15      possible duplicate of Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension –  Pavel S. Oct 6 '13 at 15:31


9 Answers


I have the same problem i solved it by installing it in ubuntu as normal user not as root user. I hope this may help you.

  this answer
answered Aug 22 '13 at 13:35 chiyango 176 1 13


You should have postgresql installed before you install pg gem.

sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install postgresql libpq-dev

If your sqlite is not working, it looks like there are some packages you might have missed.

sudo apt-get install libreadline-dev libssl-dev zlib1g-dev build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev

  this answer
edited Aug 5 '13 at 17:18 answered Aug 5 '13 at 17:12 Vysakh Sreenivasan 1,247 1 9 21      Yes i installed it already even sqlite throwing same error –  overflow Aug 5 '13 at 17:14      For sqlite, did you install the dependencies? I will update the answer with dependencies –  Vysakh Sreenivasan Aug 5 '13 at 17:17      I am not sure about sqlite dependencies but for postgresql i installed everything and its working in command line. But i am unable to locate gem. –  overflow Aug 5 '13 at 17:19      The dependencies I have given is not restricted to sqlite. It also includes packages other than sqlite. Try installing the packages I have given, it should work. –  Vysakh Sreenivasan Aug 5 '13 at 17:21      Its throwing same error. I tried most of the Stackoverflow answers. –  overflow Aug 5 '13 at 17:28  |  show more comments

On Ubuntu 14.04 (and possibly every other Debian 7 based distro) this problem is caused by the absence of the Ruby development package. Thus the fix is simply to install it:

sudo apt-get install ruby1.9.1-dev

  this answer
answered Jan 24 '15 at 16:44 Luís de Sousa 873 1 13 30 1   It solved an issue on debian too. Thanks. –  Brice Favre Mar 12 '15 at 9:54      sudo yum install ruby-devel for CentOS (solved my issue) –  Denys Vitali Sep 17 '15 at 11:35      This solved all my issues, thanks! –  Gricher Jul 4 '16 at 4:41


I solved it by follwing these steps

  1. Uninstalled ruby completely using sudo apt-get purge ruby*
  2. Then in removed curl sudo apt-get purge curl

Then i followed this link to install Ruby RVM and rails 4.0.0

Install Rails 4.0.0

  this answer
answered Aug 6 '13 at 2:58 overflow 1,445 9 25 67


Sometimes you need to update your Ruby library, run this code:

sudo gem update --system

  this answer
answered Nov 26 '13 at 19:41 Mohammed Sawaie 29 3



Recommend:ruby - Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. Rails Capistrano

to deploy to our production server in the past, but I'm now trying to deploy to a different server (Ubuntu 12.04 LTS 64bit) for testing. So I changed my deploy.rb with all of the proper information (server ip, app name, repo, etc). When I




bundle install

  this answer
answered Nov 16 '13 at 17:36 sparkle 2,205 11 40 75


I had an issue with slightly different Ruby builds. The existing application's Gemfile.lock was created using ruby-1.9.3-p194 and my local ruby was ruby-1.9.3-p484. Switching to the proper ruby allowed for a successful bundle.

  this answer
answered Feb 21 '14 at 2:27 tmr08c 59 6


I had the same problem with CentOS 6.5.

  1. Created a new user
  2. Added this users to the sudoers file /etc/sudoers
  3. Install ruby-devel using yum -y install ruby-devel

  this answer
answered Feb 3 '15 at 17:40 Ian Bryce 16


On Debian, the pg install was failing to build native extensions because postgres wasn't installed.

I installed the postgres dependencies with:

$ apt-get install postgresql postgresql-client libpq-dev

Then the pg gem built its dependencies just fine:

$ gem install pg -v '0.18.3'
Building native extensions.  This could take a while...
Successfully installed pg-0.18.3
1 gem installed

  this answer
answered Apr 28 '16 at 1:57 cgenco 547 5 17


Recommend:ruby on rails - Build a gem with native extension (Gem::Installer::ExtensionBuildError)

/root/.gem/ruby/1.9.0 GEM CONFIGURATION: :update_sources => true :verbose => true :benchmark => false :backtrace => false :bulk_threshold => 1000 REMOTE SOURCES: And when I try this simple command: gem install no


------splitte line----------------------------