Installing PostgreSQL on a machine running Ubuntu
If you are here, I assume you have had one or two issues with PostgreSQL installation. Well, you are not alone, and hopefully I will be of help to solving your problem. Enough with the jibber-jabber let’s get to work.
Remove all previous installation of PostgreSQL
First and foremost, you might need to remove all the previous installation of PostgreSQL packages from your machine. That is if you have tried the installation before. The following beautiful command will help you do so.
$ sudo apt-get remove --purge "postgresql.*"
Once all is said and done. You will see some disturbing output like this.
Installation
Here comes the elephant. Don’t run away yet. Brace yourself. It’s gonna be a smooth ride.
You will need to update your packages, sudo apt-get update, and make sure you are connected to the Internet. But I guess you are, otherwise you might not be reading this. :)
$ sudo apt-get update
Finally install PostgreSQL. Run the following command
$ sudo apt-get install postgresql postgresql-contrib
Starting the Server
Once the installation is complete, you will need to start the PostgreSQL server.
$ sudo service postgresql start
Relax, we are almost there. :) Finally, you will login as postgres user in your machine to be able to login into the database. The following command will log you in.
$ sudo su postgres
And finally you can now connect to the database.
$ psql
Changing Database Password
Type in the following command to change the postgres user password
\password
Remember, every step is as important as any other. Goodluck!