Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake aborted! no such file to load -- pg (Creating postgre database in rails )

I'm trying to start a rails project with a postgresql database but when i try to create the db with the command:

rake db:create

I'm getting the following error message:

rake aborted! no such file to load -- pg

I'm using mac os X so postgresql is intalled in the /Library folder. I've look around for the pg file but i could not find it and i

like image 910
Fgblanch Avatar asked Nov 24 '10 22:11

Fgblanch


3 Answers

If you are using PostgreSQL 9 downloaded from enterprisedb you need to install the pg gem in one of the following way:

If you use rvm use:

env ARCHFLAGS="-arch x86_64" \
  gem install pg -- \
  --with-pg-include=/Library/PostgreSQL/9.0/include/ \
  --with-pg-lib=/Library/PostgreSQL/9.0/lib/

Otherwise use:

sudo env ARCHFLAGS="-arch x86_64" \
  gem install pg -- \
  --with-pg-include=/Library/PostgreSQL/9.0/include/ \
  --with-pg-lib=/Library/PostgreSQL/9.0/lib/

If that doesn't work, we need to know which version of OSX and which version of PostgreSQL.

like image 197
Sinetris Avatar answered Sep 23 '22 01:09

Sinetris


make sure you have the pg gem installed.

gem install pg

or

include gem pg in your Gemfile and run bundle install if using bundler

like image 30
Doon Avatar answered Sep 20 '22 01:09

Doon


All right. Another day, another opportunities.

I found the problem! If you want to install "gem install pg" you need to have the postgres header files on your machine. After I installed Postgres 8.3 via Macports I was also able to install the pg gem. I used this command to install the pg gem:

sudo env ARCHFLAGS='-arch i386' gem install pg

I found the solution in this blog post:

http://flux88.com/blog/installing-postgresql-for-rails-on-mac-os-x/

After reading the post and all the comments, I could resolve the problem.

like image 43
Robert Reiz Avatar answered Sep 24 '22 01:09

Robert Reiz