12

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

Prabhakaran
  • 3,900
  • 15
  • 46
  • 113
  • it should be a dev package missing, see [this question](http://stackoverflow.com/questions/7645918/require-no-such-file-to-load-mkmf-loaderror) or [this one](http://stackoverflow.com/questions/12731904/rails-installation-failed-on-ubuntu-with-cannot-load-such-file-mkmf) – mdemolin Aug 05 '13 at 17:12
  • Possible duplicate of http://stackoverflow.com/questions/13767725/unable-to-install-gem-failed-to-build-gem-native-extension-cannot-load-such – MrYoshiji Aug 05 '13 at 18:15
  • possible duplicate of [Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension](http://stackoverflow.com/questions/15816331/geminstallerextensionbuilderror-error-failed-to-build-gem-native-extension) – Pavel S. Oct 06 '13 at 15:31

9 Answers9

14

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
Vysakh Sreenivasan
  • 1,719
  • 1
  • 16
  • 27
9

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
Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86
4

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.

chiyango
  • 401
  • 10
  • 20
2

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

Prabhakaran
  • 3,900
  • 15
  • 46
  • 113
1

Install

http://postgresapp.com/

then

PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

then

bundle install
sparkle
  • 7,530
  • 22
  • 69
  • 131
1

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

sudo gem update --system
1

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.

tmr08c
  • 77
  • 1
  • 8
0

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
Ian Bryce
  • 62
  • 1
  • 3
0

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
cgenco
  • 3,370
  • 2
  • 31
  • 36