Creating blog with Ruby and Rails- Postgresql setup part2 (b)

One thing we have to note is that we get sqlite with our rails install. Its easier to get started. However, when we will be pushing to production we will need to use Postgresql for example. Lets Setup Postgresql on our environment.

In your Gem file add two groups one from development and one for production.

gem ‘pg’, group: :production

Before we bundle to install we need to make sure we have Postgresql install on our environment. Follow the steps below.

Install PostgreSQL from PostgreSQL Apt Repository

PostgreSQL is available in all Ubuntu versions by default, but it doesn’t guarantee automatic updates when new releases come out. The local repository only has “snapshots” of a specific version. The best practice is to install the software from the PostgreSQL Apt Repository.

Step 1: Add PostgreSQL Repository

sudo apt-get install wget ca-certificateswget --quiet -O - | sudo apt-key add -

Then, add the PostgreSQL repository by typing:

sudo sh -c 'echo "deb `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'

Step 2: Update the Package List

After adding the official PostgreSQL repository, make sure to update the package list. Doing this ensures you install the latest PostgreSQL package.

sudo apt-get update

To install PostgreSQL and the PostgreSQL contrib package (which provides additional features), use the following command:

sudo apt-get install postgresql postgresql-contrib

Check the available Version:

apt show postgresql

Install PostgreSQL Package

sudo apt install postgresql postgresql-contrib

To establish a connection with the newly set-up database, log into the postgres account with:

sudo su - postgres

Now open a postgress prompt using the command:


Check Connection Information

If you are connected to PostgreSQL and want to see details of the connection, use the command:


Now lets continue with bundle install

Open up a new terminal and navigate to blog and run the following command

sudo apt-get install postgresql 
sudo apt-get install libpq-dev
gem install pg


I am a passionate coder, QA Engineer, and someone who enjoys the outdoors.