Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexcalaca/28b1b3223971b01827bcd46fd2c8fd57 to your computer and use it in GitHub Desktop.
Save alexcalaca/28b1b3223971b01827bcd46fd2c8fd57 to your computer and use it in GitHub Desktop.
How to set up Ruby on Rails 5 + PostgreSQL database on Cloud9

My profile: https://about.me/alexandrecalaca

1. Check your Rails version

rails -v
  1. Open the Gemfile and replace the line "gem 'sqlite3" with gem 'pg', '~> 0.21'
gem 'pg', '~> 0.21'
  1. Replace the line with your current Rails version with "gem 'rails', '5.0.6'"
gem 'rails', '5.0.6'
  1. In the terminal, run bundle install
bundle install
  1. In the terminal, run bundle update
bundle update
  1. Check your current Rails version
rails -v
  1. Check if pg is installed
bundle show pg

Now, let's config PostgreSQL

  1. Respect the indentation and replace the database.yml with a new code
default: &default
  adapter: postgresql
  encoding: SQL_ASCII
  pool: 5
  username: ubuntu
  password: password

development:
  <<: *default
  database: top_development

test:
  <<: *default
  database: top_test

production:
  <<: *default
  database: top_production

by default, your username is "ubuntu", so, just choose a password now and don't forget it. Change your database name according to your project.

  1. Start the PostgresQL service
sudo service postgresql start
  1. Enter the Postgreql terminal
sudo -u postgres psql
  1. Create the ubuntu user
CREATE USER ubuntu SUPERUSER PASSWORD 'yourpassword';

This password must match with your database.yml file.

  1. Check if your user is already there
\du
  1. Create your databases
CREATE DATABASE "database_name";

A confirmation message is "CREATE Database".

As always, those database names need to match in Postgres and the database.yml file

  1. Check if all databases have been created in Postgres.
\l

Press q to leave.

q
  1. Set ubuntu user to become the new owners of the databases
ALTER DATABASE database_name OWNER TO ubuntu;

Confirmation message is "ALTER DATABASE".

  1. Run the \l command again to check if your databases have been owned to ubuntu;
\l
  1. Press \q to leave postgresql terminal
\q
  1. Create Rails databases Run rails db:create
rails db:create

You'll get a message that they already exist

  1. Migrate them
rails db:migrate
  1. Run the server If you get this message: Yay! You’re on Rails!

Then, you gotta be happy. If you don't, check the error message and try again. Let me know if I can help you out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment