Step 1 – Installing PostgreSQL
$ sudo apt update
$ sudo apt install postgresql postgresql-contrib libpq-dev
Step 2 – Creating a New Database Role
$ sudo -u postgres createuser -s <username> -P
$ psql -U postgres --password
postgres=# \password <username>
postgres=# \q
Step 3 – Creating a New Rails Application
$ cd ..
$ rails new <app_name> -d=postgresql
$ cd <appname>
Step 4 – Configuring and Creating Your Database
$ echo 'export <app_name>_DATABASE_PASSWORD="<password>"' >> ~/.bashrc
$ source ~/.bashrc
$ nano config/database.yml
username: <username>
password: <%= ENV['<app_name>_DATABASE_PASSWORD'] %>
$ rails db:create