Tuesday, August 15, 2017

Installing PostgreSQL database for Ruby on Rails on Ubuntu Linux

I realized that I did not write a blog for the installation procedures of PostgreSQL database for Ruby on Rails on Ubuntu Linux. This is an excerpt from GoRails.com :

Setting Up PostgreSQL

For PostgreSQL, we're going to add a new repository to easily install a recent version of Postgres.
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev

The postgres installation doesn't setup a user for you, so you'll need to follow these steps to create a user with permission to create databases. Feel free to replace chris with your username.
sudo -u postgres createuser chris -s

# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password chris

Creating Ruby on Rails application

#### If you want to use Postgres
# Note that this will expect a postgres user with the same username
# as your app, you may need to edit config/database.yml to match the
# user you created earlier

rails new myapp -d postgresql

Author's note: I did not modify the 'database.yml' file. I just left it as it the original from the 'rails new' command.

# Move into the application directory
cd myapp

# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified

# Create the database
rake db:create

rails server

You can now visit http://localhost:3000 to view your new website!

Reference:

Setup Ruby On Rails on Ubuntu 16.04 Xenial Xerus
https://gorails.com/setup/ubuntu/16.04#postgresql

2 comments:

  1. Nice post ! Thanks for sharing valuable information with us. Keep sharing..Big data hadoop online training Hyderabad

    ReplyDelete
  2. It was really a nice article and i was really impressed by reading this Ruby on Rails Online Training India

    ReplyDelete

How to kill an abandoned process in Linux/Unix

I remembered it, then I forgot, then I remembered it, and then I forgot again. In case of a Linux/Unit process hang, I have to figure out ...