How to set up and configure PostgreSQL database for use with Ruby on Rails on Linux PC/server and Ubuntu.
The versions are Ubuntu 16.04 and Ruby on Rails 5 respectively. Please note that details may differ depending on the version.
Install POSTGRESQL on ubuntu16.04
vim /etc/apt/sources.list.d/pgdg.list
# Add
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-10
sudo apt-get update
PostgreSQL: Linux downloads (Ubuntu)
Install gem to use with Ruby
gem install pg
Create postgres user
sudo -u postgres psql postgres # Login (no password)
create role englishtool with createdb login password 'password1';
# or
create user "englishtool" with password 'password1';
sudo /etc/init.d/postgresql restart
Create app
rails new englishtool --database=postgresql
Configure database.yml as follows. Set username and password to the same as previously configured.
development:
adapter: postgresql
encoding: unicode
database: englishtool_development
pool: 5
username: englishtool
password: password1
host: localhost
test:
adapter: postgresql
encoding: unicode
database: englishtool_test
pool: 5
username: englishtool
password: password1
host: localhost
Apply
Create the database as follows:
rake db:setup
rails db:migrate
This completes the database configuration.
Summary
This time, we introduced how to set up and configure PostgreSQL database in Ruby on Rails.
Thatโs all for the procedure to configure PostgreSQL for Rails in Ubuntu.