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
(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)
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'
#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


11 Responses to “Ruby/Rails 3 and PostgreSQL”
Thanks! Your post saved me a good bit of time getting my environment setup.
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
You are my hero!
Very simple and Very Helpful!
thank you
thanks,
if you use windows 7, you must choose 0.9.0 version of pg gem:
gem install pg -v=0.9.0
Awesome!
You saved me a lot of time too!
THANKS
Thanks man, that solved it for me!
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
thank you for this!
Thank you so much!
After a long time trying, your solution worked for me!
Thank you!!!
Lifesaver…
Leave a Reply