CIS 658

Getting Started with Rails

Winter 2019

Note: Parts of this document were originally written by Prof. Engelsma.

RVM

RVM is the Ruby Version Manager. It allows you to have multiple versions of Ruby installed on your machine. Rails, and certain Ruby packages, can be sensitive to the version. Therefore, I suggest you install and use RVM to manage your Ruby version. (Don't rely on the default Ruby version installed on your machine.)

Platform

Your first decision is whether to install Rails on your own machine, or to run it in a cloud environment. There are advantages to running Rails on your own machine (e.g., you don't have to worry about Internet access or time/space quotas); but, Rails is a complex framework with many dependencies. If you use a cloud platform, it is much easier to start from scratch if anything gets messed up.

Your own machine
Windows
I've never tried installing and running Rails on a Windows machine; but, I've heard it can be painful. If you want to run Rails locally on a Windows machine, try one of these approaches:
Linux or MacOS
There are a number of package installers designed to make this process easier; however, many are out of date, or lag behind hte official version of Rails. As explained above, I suggest using RVM rather than relying on the version of Ruby that came pre-installed on your machine.
  • Install RVM. (See rvm.io for details on your specific platform.)
  • Use RVM to install a recent version of Ruby: rvm install ruby-2.6.0
  • Make the version you just installed your default Ruby interpreter: rvm --default use 2.6.0
  • Install the most recent version of Rails: gem install rails
Cloud Environments
Cloud 9
Cloud9 has been Prof. Engelsma's favorite cloud-based IDE. However, Amazon acquired Cloud9 and incorporated it into Amazon Web Services (AWS). If you are fortunate enough to have created a Cloud9 account before it was acquired by Amazon, you can still use your existing account. If not you will need to create an AWS account. You will need a credit card to sign up; however, Amazon gives new users 12 months of "free tier" service that will allow you to use Cloud9 without charge. After your 12-month trial ends, $2/month should buy more than enough time on an EC2 instance to meet the needs of this class (aws.amazon.com/cloud9/pricing/).
CodeAnywhere
CodeAnywhere is an alternative cloud IDE to Cloud9. In Prof. Engelsma's opinion, it is not quite as easy to use; but, it is completely free (for up to 2 hours/day of usage) and doesn't require a credit card.
  • Go to codeanywhere.com/dashboard
  • Create a new project and open it.
  • When you open the new project for the first time, the Connection Wizard will appear. This Connection Wizazrd does two things. (1) You can set up a connection to a source code repository. This step is optional. (2) You name your container and choose its "stack" (initial configuration). Choose the "Ubuntu 16.04" version of Ruby.
  • Once the container is ready, select the "SSH Console" tab.
  • Check your RVM version: rvm --version
  • Upgrade RVM (if desired): rvm get stable
  • Check your Ruby version: ruby --version
  • Upgrade Ruby (if desired): rvm install ruby-2.6.0
  • Set the default Ruby version: rvm --default use 2.6.0
  • Check the Rails version: rails -v
  • Install Rails (if necessary): gem install rails
    • This step may take 6 to 8 minutes.
    • If you are building a test/toy application and don't need the documentation tools you can do a quicker install with gem install rails --no-ri --no-rdoc
  • Create a new Rails app: rails new name_of_your_app
    • Make sure the current working directory is underneath ~/workspace.
  • cd into the new application's directory
  • Launch rails: rails s --binding=0.0.0.0
    • If you get a help/"usage" display, then you ran the rails command from the wrong directory.
  • The information page for your container will contain a link to your web app. When you click it, you should see the default Rails landing page.
This screencast walks through the above steps: youtu.be/Lh5A6mshMvk.

Updated Friday, 12 April 2019, 1:18 PM

W3c Validation