15

I'm trying to get Rails to work with PostgreSQL. Apparently one thing I need to do along the way is sudo gem install pg. When I do that, I get this:

jason@buster:~/projects$ sudo gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
extconf.rb:2:in `require': no such file to load -- mkmf (LoadError)
        from extconf.rb:2


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

I've Googled and tried a few things based on what I've found but nothing seems to help. Any advice? I'm on Ubuntu.

Jason Swett
  • 43,526
  • 67
  • 220
  • 351

2 Answers2

38

You need to install your distro ruby-dev (or devel) package otherwise you won~t be able to build any ruby C extensions.

I'm not on ubuntu, but you package-manager command might be somewhat like this:

$ sudo apt-get install ruby-dev build-essential
Mereghost
  • 698
  • 4
  • 8
  • 1
    This is what I've been looking for as well. There are a dozen different answers to this question out there, but this is the only one that worked for me -- specifically, no one else bothers to mention installing the *ruby-dev* package. – Brian Lacy Aug 08 '11 at 19:58
  • what will the solution for same problem in fedora24 – Krishna Chalise Oct 23 '16 at 12:32
35

On Ubuntu:

$ sudo apt-get install postgresql-client libpq5 libpq-dev
$ sudo gem install pg
yfeldblum
  • 65,165
  • 12
  • 129
  • 169