Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing PostgreSQL with Ruby on Rails on Mac OS X

I have everything installed. But when I run "rake db:create", I get the following:

Ken-Vogts-MacBook:sixmonths ken$ rake db:create
(in /Users/ken/sixmonths)
rake aborted!
no such file to load -- pg

Here is my database.yml:

development:
  adapter: postgresql
  encoding: unicode
  database: sixmonths_development
  pool: 5
  username: postgres
  password: xxxxxxxx

test:
    adapter: postgresql
    encoding: unicode
    database: sixmonths_test
    pool: 5
    username: sixmonths
    password: xxxxxxxx

production:
    adapter: postgresql
    encoding: unicode
    database: sixmonths_production
    pool: 5
    username: sixmonths
    password: xxxxxxxx

I can see pg is installed when I run: gem list

I tried replacing "postgresql" with "pg" per another post on stackoverflow, but it resulted in this:

Ken-Vogts-MacBook:sixmonths ken$ rake db:create
(in /Users/ken/sixmonths)

Seems cool, right?

Nope. Next, I try "rake db:schema:dump" and I get this:

Ken-Vogts-MacBook:sixmonths ken$ rake db:schema:dump
(in /Users/ken/sixmonths)
rake aborted!
Please install the pg adapter: `gem install activerecord-pg-adapter` (no such file to load -- active_record/connection_adapters/pg_adapter)

Of course there is no "activerecord-pg-adapter". What do I have to do to make this work?

Gemfile Contents:

source 'rubygems.org'
gem 'rails', '3.0.0' 
# Bundle edge Rails instead: 
# gem 'rails', :git => 'git://github.com/rails/rails.git' 
gem 'sqlite3-ruby', :require => 'sqlite3' 
# gem 'unicorn' 
# gem 'capistrano'
# gem 'ruby-debug'
# Bundle the extra gems: 
# gem 'bj' 
# gem 'nokogiri' 
# gem 'sqlite3-ruby', :require => 'sqlite3' 
# gem 'aws-s3', :require => 'aws/s3' 
# Bundle gems for the local environment. Make sure to 
# put test-only gems in this group so their generators 
# and rake tasks are available in development mode: 
# group :development, :test do 
  # gem 'webrat' 
# end
like image 751
Kenneth Vogt Avatar asked Feb 03 '23 21:02

Kenneth Vogt


1 Answers

Rails 3 will only let you access the gems you specify in your Gemfile, so even if you have it installed in your system-wide gems by doing a gem install pg, it won't be able to find it.

Add gem 'pg' to your Gemfile, run bundle install, and you should be good to go.

like image 113
Dylan Markow Avatar answered Feb 05 '23 16:02

Dylan Markow