A short checklist borrowed from this blog post:
Simply run the following commands in order:
sudo apt-get update
- updates Ubuntu packages to latest version so you don't install out-of-date versionssudo apt-get install curl
- installs the cURL utility that is used to send HTTP requests (like in the next command)\curl -L https://get.rvm.io | bash -s stable --ruby
- downloads and installs RVM (Ruby Version Manager)rvmsudo rvm get stable --autolibs=enable
- RVM updates itself to the most recent stable versionrvm reload
- Reload RVM so it's using the latest version that was just installedrvm --default use ruby-2.3.0
- tells RVM to use Ruby 2.3.0 (for Rails 5)gem update --system
- updates gem (the Ruby package manager)gem install rails --pre
- installs the most recent stable Rails versionrails -v
- checks the Rails version. It should be 5
If all of the above worked and rails -v
is giving the correct output, you can move on.
This is a bit trickier, but nothing extremely difficult.
-
rails new my_app_name -d postgresql
- generates a new Rails application (folders, files, etc.) with the name my_app_name, using PostgreSQL database -
sudo service postgresql start
- Start PostgreSQL so that Rails can use it -
rake db:create
- creates the PostgreSQL databaseOh no, an error:
PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
What a pain in the ass. Basically the template for PostgreSQL databases is encoded as SQL_ASCII, but Rails wants to create the database in UTF-8 encoding because of this line in
config/database.yml
:encoding: unicode
Rails is right, PostgreSQL should have its default encoding as UTF-8. ASCII makes no sense. Whatever.
To fix it, download this script and execute it (you may need to run
chmod 777
on it) The script will simply set the default encoding for the database template used by Rails to UTF-8 isntead of SQL_ASCII. You should see this output:UPDATE 1 DROP DATABASE CREATE DATABASE UPDATE 1 VACUUM UPDATE 1
To verify that this worked, check PostgreSQL directly:
sudo sudo -u postgres psql
to launch the PostgreSQL console\list
to list any existing databases
You should see this line:
template1 | postgres | UTF8 | C | C |
; Rails will usetemplate1
when creating databases, so as long as the encoding is UTF-8, everything will be fine.- Re-run
rake db:create
; the command should no longer throw an exception - Re-run
\list
in the PostgreSQL console to list databases.
You should now see the database for your rails app:
my_app_name_development | ubuntu | UTF8 | C | C |
. Use\q
to quit the console. -
Navigate to the app's Cloud9 URL, e.g.
https://rails-playground-cireficc.c9users.io
.- You should see a beautiful picture of happy people with a welcome message:
"Yay! You're on Rails!"
If you got this far, then you've successfully set up Rails and are now ready to start playing around!
Here are some useful sites containing tutorials: