Installing PostgreSQL on Ubuntu was always a problem for me when I started using PostgreSQL. The problem was in setting up the root user credentials. I have tried lot of commands with no success. After so many tries I found which is correct command to use. I'm documenting the steps here which will help some newbies trying to install PostgreSQL on Ubuntu.

Versions Used

  • PostgreSQL - 9.3.5
  • pgAdmin III - 1.18.1
  • Ubuntu - 14.04

Step 1: Install PostgreSQL

You can install PostgreSQL 9.3 using the command

sudo apt-get install postgresql-9.3

Step 2: Set root user credentials

Login to PostgreSQL shell using the command

sudo -u postgres psql

Then set root user credentials using the command

ALTER USER postgres PASSWORD 'newpassword';

You can now exit the PostgreSQL shell using the command quit.

Henceforth you can login to the PostgreSQL shell using the command

psql -U postgres -h localhost

and the password you set in the previous step using the login password.

Step 3: Install pgAdmin (optional)

Installing pgAdmin is optional and you can ignore this step, if you don't need pgAdmin. To install pgAdmin, use the command

sudo apt-get install pgadmin3

Now we have installed PostgreSQL and pgAdmin successfully. Feel free to post your comments.