Ruby/Rails 3 and PostgreSQL

I’ve just spent an hour arguing with a new install of ruby 1.92, rails 3.0.2rc and PostgreSQL.

Every time i tried to do a db:migrate I got a strange error.

rake db:migrate
(in /home/peter/projects/workspace/testapp)
rake aborted!
no such file to load -- pg

I did the usual trawling around helpful websites, each suggesting I hadn’t the correct database gem installed. some referred to pg, some to postgresql, other to ruby-postgres.

What I have installed is listed below

abstract (1.0.0)
actionmailer (3.0.0.rc)
actionpack (3.0.0.rc)
activemodel (3.0.0.rc)
activerecord (3.0.0.rc)
activeresource (3.0.0.rc)
activesupport (3.0.0.rc)
arel (0.4.0)
builder (2.1.2)
bundler (1.0.0.rc.2)
capistrano (2.5.19)
erubis (2.6.6)
highline (1.6.1)
i18n (0.4.1)
mail (2.2.5)
mime-types (1.16)
minitest (1.6.0)
net-scp (1.0.2)
net-sftp (2.0.4)
net-ssh (2.0.23)
net-ssh-gateway (1.0.1)
pg (0.9.0)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.9)
rack-test (0.5.4)
rails (3.0.0.rc)
railties (3.0.0.rc)
rake (0.8.7)
rdoc (2.5.8)
sqlite3-ruby (1.3.1)
thor (0.14.0)
treetop (1.4.8)
tzinfo (0.3.22)

The fix for the 'no such file to load — pg' error is to update the new Gemfile file in your application’s root folder.

#Comment out the sqlite3 requirement
#gem 'sqlite3-ruby', :require => 'sqlite3'
#Add a pg requirement
gem 'pg', :require => 'pg'

Once you’ve done this do a bundle install from your application root folder. This ensures you have all required gems installed. Another hour wasted fighting against the machine.

$ sudo bundle install
Share

11 Responses to “Ruby/Rails 3 and PostgreSQL”

  1. John @ September 4th, 2010

    Thanks! Your post saved me a good bit of time getting my environment setup.

  2. Thuon Chen @ November 2nd, 2010

    Thanks Peter, I’ve given you a shout-out in my latest blog post:

    http://tpc247.blogspot.com/2010/11/rails3-migrating-from-mysql-to.html

  3. Marc Lacoursiere @ November 3rd, 2010

    You are my hero! :)

  4. Sand @ November 22nd, 2010

    Very simple and Very Helpful!
    thank you :)

  5. Kamil @ December 10th, 2010

    thanks,
    if you use windows 7, you must choose 0.9.0 version of pg gem:
    gem install pg -v=0.9.0

  6. Eric @ December 24th, 2010

    Awesome!

    You saved me a lot of time too!

    THANKS

  7. Gaetan @ January 10th, 2011

    Thanks man, that solved it for me!

  8. Freddy Vulto @ January 11th, 2011

    This can be shortened to: gem ‘pg’, as the require defaults to the name of the gem itself. See also: http://gembundler.com/man/gemfile.5.html

  9. Garrett @ April 29th, 2011

    thank you for this!

  10. André @ May 6th, 2011

    Thank you so much!
    After a long time trying, your solution worked for me!
    Thank you!!!

  11. You are @ May 30th, 2011

    Lifesaver…

Leave a Reply



*

Spam protection by WP Captcha-Free