How to handle Ruby on Rails error: "Please install the postgresql adapter: `gem install activerecord-postgresql-adapter'"

35,148

Solution 1

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

The definition in the database.yml file should include

  adapter: postgresql

Solution 2

Here's the answer I got from Heroku and it worked for me (after trying different pg gems, adapters, and everything else on the 10 other posts about this)

1) add the line: gem 'pg' to your Gemfile.

2) Run the command bundle install to install the gem into your bundle.

3) Stage the Gemfile and Gemfile.lock changes: git add Gemfile Gemfile.lock

4) Commit the changes: git commit -m "Install the pg gem"

5) Redeploy to heroku: git push heroku master

Solution 3

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/

Solution 4

There is one more deeply hidden condition that will also cause this error.

If you have a local environment variable DATABASE_URL=postgres://mehmehmeh set, then some gem (I suspect Heroku) causes the app to think that Postgres is required even if it's nowhere in your configs. Kill that env variable and you should be fine.

Solution 5

You can try this

On debian(squeeze):

aptitude install libdbd-pg-ruby
Share:
35,148
user71268
Author by

user71268

Updated on July 08, 2022

Comments

  • user71268
    user71268 almost 2 years

    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.