Installing ‘pg’ gem with RubyInstaller 1.9.1 preview2
I’ve been running the latest RubyInstaller preview for Ruby 1.9.1 on my Windows boxes. It’s way better than the old 1.8.x stuff, but some things are harder than others. One thing that’s tricky is getting some gems installed that build from source. I recently had cause to install the ‘pg’ gem to access PostgreSQL databases from my Ruby apps. Here’s what I did:
I started with the RubyInstaller 1.9.1 preview2, which installed Ruby 1.9.1 P243. I got it here.
I then downloaded the DevKit 3.4.5 r3 from the same page, and extracted the .7z file into the directory where I installed Ruby (c:\work\tools\Ruby19 if you care).
Next I opened up a command prompt with the Ruby environment already set up, using the ‘Start Command Prompt with Ruby’ shortcut. If you instead launch your own command prompt, things probably won’t work right, as the paths won’t be tweaked appropriately.
After that, I tried gem install pg, which failed thusly:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
C:/work/tools/Ruby19/bin/ruby.exe extconf.rb
ERROR: can't find pg_config.
HINT: Make sure pg_config is in your PATH
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/work/tools/Ruby19/bin/ruby
Gem files will remain installed in C:/work/tools/Ruby19/lib/ruby/gems/1.9.1/gems/pg-0.8.0 for inspection.
Results logged to C:/work/tools/Ruby19/lib/ruby/gems/1.9.1/gems/pg-0.8.0/ext/gem_make.out
Doh! The PostgreSQL pg_config tool isn’t in my path.
I’m running PostgreSQL 8.4.0-1 installed with the One-Click Installer, installed in the default path C:\Program Files (x86)\PostgreSQL\8.4. The pg_config tool is in the bin subdirectory:
set "PATH=%PATH%;C:\Program Files (x86)\PostgreSQL\8.4\bin"
Note the double-quotes are important, since the PATH includes paths that contain spaces. I then tried gem install pg again:
Building native extensions. This could take a while... Successfully installed pg-0.8.0 1 gem installed Installing ri documentation for pg-0.8.0...
Ok. Let’s test it:
irb(main):001:0> require 'pg'
=> true
irb(main):005:0> conn = PGconn.connect('pixel', 5432, '', '', 'testdb', 'test', 'test')
=> #
Yay! Nailed it!
Next up, getting it working with Rails.
September 27th, 2009 - 21:02
Tried the same thing but get:
checking for main() in -lpq… no
checking for main() in -llibpq… no
checking for main() in -lms/libpq… no
*** extconf.rb failed ***
Any thoughts?