Rails: Error installing pg gem

Steps to install postgresql

  1. Install PostgreSQL and its libraries

    sudo apt-get install postgresql postgresql-contrib libpq-dev
    
  2. After the installation create a user for postgresql

    sudo -u postgres createuser --superuser $USER
    

    or

    sudo -u postgres createuser pgs_root
    
  3. Set user password for the postgresql user

    sudo -u postgres psql postgres --set "user=$USER"
    postgres=# \passsword :user
    

    or

    sudo -u postgres psql postgres
    postgres=# \passsword pgs_root
    
  4. Configure the postgresql.conf file to make PostgreSQL listen to localhost or listen on an external IP or something, change this line to either the IP or 'localhost'

    gedit /etc/postgresql/8.4/main/postgresql.conf listen_addresses = 'localhost'
    

Like mysql query browser, there is a GUI for postgresql called pgadmin. To install run this command

sudo apt-get install pgadmin3

Are you on a Mac? If so - the easiest way to do this is to

  1. make sure you have Xcode installed (you can get it from the app store)
  2. use Homebrew
  3. brew install postgresql
  4. gem uninstall pg
  5. either bundle install in your application's root or gem install pg

Try to include this instead of pg

gem install postgres-pr

or

gem install ruby-pg

Edit

Did you do this already?

$ sudo apt-get install postgresql

$ rails new pg -d postgres

http://www.funonrails.com/2011/03/getting-started-with-rails-3-postgres.html