views:

3935

answers:

6

Running a Ruby on Rails (RoR) app or Ruby code which uses the ActiveRecord framework, you get the error message:

Please install the postgresql adapter: gem install activerecord-postgresql-adapter

Trying to run:

gem install activerecord-postgresql-adapter

also fails, leaving you at a loss.

A: 

If this is on a *nix platform, you probably need to run sudo gem install activerecord-postgresql-adapter

James Deville
The question indicates that this attempt failed too. It is an incorrect and misleading error message.
the question indicates that gem install... failed. I said run with sudo, which is why gem installations usually fail on *nix platforms.
James Deville
Got it. I left out the "sudo" from the answer, but I did try it with sudo:% sudo gem install activerecord-postgresql-adapterERROR: could not find gem activerecord-postgresql-adapter locally or in a repository
ah, so were you saying that installing pg worked?
James Deville
Yep, that's in my answer. It's just that the error message displayed gives you misleading information.
A: 

You could read the following post to get an idea.

eKek0
My attempts at following that post are included in my original answer, as they did not work for me.
+4  A: 

This means you don’t have the new ‘pg’ postgresql library installed. This is easily fixed with a bit of:

sudo gem install pg

I (Dov) found other solutions on the web which described setting GEM_HOME and adding ~/.gem/ruby/vers/bin to your PATH, but they didn't work. This solution above was provided by Mark Mansour on his blog State of Flux at: http://stateofflux.com/2008/7/13/activerecord-postgresql-adapter-in-rails-2-1/

This one did not work for me ... still looking for a solution.
Toby Hede
A: 

I did a little roundup of the current state of Ruby + PostgreSQL database drivers on railsonpostgresql.com; I think sudo gem install pg is probably the one you want.

tomcopeland
+5  A: 

The problem is not what anyone wrote. The problem is that the name of the postgresql database adapter is "postgresql", not "postgres", fix the database.yml, but the name of the GEM is "pg".

mcr
This fixed my problem. Thanks!
localshred
A: 

sudo apt-get install ruby1.8-dev

then...

gem install pg

Worked for me!

KurtB
What if we want to use 1.9.2?
Ramon Tayag