My profile: https://about.me/alexandrecalaca
1. Check your Rails version
rails -v
- Open the Gemfile and replace the line "gem 'sqlite3" with gem 'pg', '~> 0.21'
gem 'pg', '~> 0.21'
- Replace the line with your current Rails version with "gem 'rails', '5.0.6'"
gem 'rails', '5.0.6'
- In the terminal, run bundle install
bundle install
- In the terminal, run bundle update
bundle update
- Check your current Rails version
rails -v
- Check if pg is installed
bundle show pg
Now, let's config PostgreSQL
- 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.
- Start the PostgresQL service
sudo service postgresql start
- Enter the Postgreql terminal
sudo -u postgres psql
- Create the ubuntu user
CREATE USER ubuntu SUPERUSER PASSWORD 'yourpassword';
This password must match with your database.yml file.
- Check if your user is already there
\du
- 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
- Check if all databases have been created in Postgres.
\l
Press q to leave.
q
- Set ubuntu user to become the new owners of the databases
ALTER DATABASE database_name OWNER TO ubuntu;
Confirmation message is "ALTER DATABASE".
- Run the \l command again to check if your databases have been owned to ubuntu;
\l
- Press \q to leave postgresql terminal
\q
- Create Rails databases Run rails db:create
rails db:create
You'll get a message that they already exist
- Migrate them
rails db:migrate
- 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.