Setup

Exercises

Objective

Welcome to your first exercise! We're delighted to have you along for the course.

Before we can start creating Rails apps, we need to get Ruby and Rails installed on your computer. Depending on your operating system, you may already have a version of Rails installed. But for this course you'll need to be running Rails 6.0.0.

So just follow the steps below for your favorite operating system—Mac, Windows, or Linux— and we'll be on our way!

Mac OS X

The best way we've found to install Ruby and Rails on a Mac is using rbenv. It's a command-line tool that makes it easy to install and manage Ruby versions. We'll be installing Ruby 2.6.5 and Rails 6.0.0.

If you already have Ruby 2.5+ installed, you can jump straight to installing Rails.

Note that Mac OS X ships with a version of Ruby. However, it's best not to mess around with the system-installed Ruby as it's intended to be used by the operating system and apps installed by Apple. So we'll use rbenv to install a separate user-level Ruby environment, rather than changing the system-installed Ruby.

  1. Start by finding the Terminal application (it's under the Applications -> Utilities directory) and dragging it onto your dock. You'll end up using Terminal a lot as a Rails developer, so it's good to have it handy. Then open a new Terminal session. You should see a new window with a cursor and a prompt that looks something like this:

    enoch:~ mike$

    If this is the first time you've seen this side of a Mac, it may seem rather intimidating. Don't let it throw you. It's simply a way to interact with your computer by entering commands. The default prompt includes the computer name (enoch in my case), the current working directory (tilde represents your home directory), the current user name (mike), and a trailing $ which is the prompt for input.

    We'll use the command prompt throughout the course to run commands and perform tasks on our Rails app. In fact, here comes our first command...

  2. To install rbenv, first we need to install Homebrew which makes it easy to install and compile software packages from source.

    To install Homebrew, copy the following command and paste it after your Terminal prompt:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    If you're asked about installing Apple's Command Line Tools for Xcode, go ahead and answer "yes".

  3. Now we can use Homebrew to install rbenv. To do that, run the following command in your Terminal session:

    brew install rbenv
  4. Next, set up rbenv in your Terminal's shell by running the following command and following the printed instructions:

    rbenv init
  5. Then close your Terminal session and open a fresh new Terminal session so that the changes take effect.

  6. Now that we have rbenv installed and the Terminal's shell set up properly, we're ready to install Ruby 2.6.5. To do that, type

    rbenv install 2.6.5

    This will download, compile, and install Ruby into a directory managed by rbenv. (If you're curious, it's under the ~/.rbenv directory.)

    Installing Ruby may take a while, so feel free to grab a refreshing beverage or a tasty snack. Mmm...

  7. When installation is complete, set Ruby 2.6.5 as the global Ruby version by typing:

    rbenv global 2.6.5

    This sets Ruby 2.6.5 as the default version to be used whenever you open any new Terminal sessions.

  8. Then verify that Ruby 2.6.5 is the current Ruby version by typing:

    ruby -v

    You should see something like the following, though your exact patch number, date, and revision may be slightly different:

    ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
  9. With Ruby installed, now we're ready to install Rails! Rails is distributed via RubyGems: the standard Ruby package manager. When you installed Ruby, the RubyGems system came along for the ride. With RubyGems already installed, it's easy to install Rails and its dependencies.

    Install Rails 6.0.0 by typing

    gem install rails -v 6.0.0 --no-document

    Then sit back and relax as RubyGems downloads all the Rails-related gems. After a minute or so, you should end up with a couple dozen gems installed.

  10. Installing Rails gives us a rails command, but to use it we first need to inform rbenv about that command. To do that, type

    rbenv rehash
  11. Finally, verify that Rails 6.0.0 was successfully installed by typing

    rails -v

    You should see:

    Rails 6.0.0
  12. You'll also need to install Node.js and install Yarn. This duo gives you a JavaScript runtime that's compatible with Rails. Since you already have Homebrew installed, you can use it to install Node.js and Yarn:

    brew install node yarn
  13. Finally, you'll need to install Git (a distributed version control system) if you don't already have a version installed. You can check if you have Git installed by

    git --version

    We won't use Git until later in the course, but Rails will auto-generate some handy Git-related files if we have Git installed from the get-go.

Excellent! Now everything you need is installed.

Choose A Code Editor

Throughout the course we'll be creating a Rails application by writing Ruby code in one or more files. You'll need a code editor to create and edit these files. The editor doesn't need to have a lot of features. In fact, a basic code editor that has Ruby syntax highlighting and a file/directory browser works best.

We'll make the decision easy for you. Unless you already have a code editor that you're very comfortable using, we recommend using Visual Studio Code as we do in the videos. VS Code runs equally well on Mac, Windows, or Linux and it's completely free! We also recommend installing the Simple Ruby ERB extension which provides both Ruby and ERB syntax highlighting.

You're now ready to start creating Rails apps!

Windows 10

The best way we've found to install Ruby and Rails on Windows is using RubyInstaller. It's a self-contained Windows-based installer that includes a Ruby language execution environment and the Windows DevKit.

  1. Navigate to the RubyInstaller downloads page and click the Ruby+Devkit 2.6.5-1 (x64) executable installer. Save the file to your Desktop, for example, and then run the file once it has finished downloading. You may need to use Windows Explorer to navigate to where you saved the executable file and double-click it to start the installation process.

  2. After accepting the license agreement, the installer will ask you to select components to install. Make sure the checkmark labeled "MSYS2 development toolchain" is checked! MSYS2 is required to install Ruby gems with C extensions, and some of the gems used by Rails do indeed have C extensions. Then click "Next" and Ruby will be installed in the C:\Ruby26-x64 directory as promised.

    Wait! Do not click "Finish" on the last installer screen until you've made sure the checkmark labeled "Run 'ridk install' to setup MSYS2" is checked. Which that checkbox checked, when you click "Finish", a new command window will open asking you which components of MSYS you want to install. Choose "1" which is the base MSYS2 installation. It will proceed to install a bunch of stuff, and then return back to the prompt asking which components you want to install. You should see the message "MSYS2 seems to be properly installed". Go ahead and close that command window.

  3. Next, open a new command prompt by selecting the Start menu, typing cmd into the search box, and pressing Enter. You should see a new window with a blinking cursor and a command prompt that looks something like this:

    C:\Users\mike>

    If this is the first time you've seen this command prompt it may seem rather intimidating, but don't let it throw you. It's simply a way to interact with your computer by entering commands. We'll use the command prompt throughout the course to run Ruby and use some related command-line tools. In fact, here comes our first command...

  4. Verify that Ruby 2.6.5 was successfully installed by typing the following at the command prompt:

    ruby -v

    You should see something like this, though your exact patch number, date, and revision may be slightly different:

    ruby 2.6.5p114 (2019-10-01 revision 67812) [x64-mingw32]

    If instead you see "Command not found", then you either need to open a new command prompt and try again, or check that your PATH environment variable includes the C:\Ruby26-x64\bin directory.

  5. Windows requires a specific version of the sqlite3 gem. Run the following command to install it:

    gem install sqlite3 -v '1.4.1' --source 'https://rubygems.org/'

    This builds a native extension, so it could take a couple minutes.

  6. Next, install Rails 6.0.0 by typing

    gem install rails -v 6.0.0 --no-document

    Then sit back and relax as all the Rails-related gems are downloaded. After a few minutes, you should end up with 40 or so gems installed.

  7. And verify that Rails 6.0.0 was successfully installed by typing

    rails -v

    You should see:

    Rails 6.0.0
  8. You'll also need to install Node.js and install Yarn using the Windows Installers. This duo gives you a JavaScript runtime that's compatible with Rails.

    After installing Yarn, update its packages by running:

    yarn install --check-files
  9. Finally, you'll need to install Git (a distributed version control system) if you don't already have a version installed. You can check if you have Git installed by

    git --version

    We won't use Git until later in the course, but Rails will auto-generate some handy Git-related files if we have Git installed from the get-go.

Excellent! Now everything you need is installed.

Choose A Code Editor

Throughout the course we'll be creating a Rails application by writing Ruby code in one or more files. You'll need a code editor to create and edit these files. The editor doesn't need to have a lot of features. In fact, a basic code editor that has Ruby syntax highlighting and a file/directory browser works best.

We'll make the decision easy for you. Unless you already have a code editor that you're very comfortable using, we recommend using Visual Studio Code as we do in the videos. VS Code runs equally well on Mac, Windows, or Linux and it's completely free! We also recommend installing the Simple Ruby ERB extension which provides both Ruby and ERB syntax highlighting.

You're now ready to start creating Rails apps.

Linux

Folks who run Linux tend to already be comfortable with the command line, installing and building software, and configuring things just the way they like. We're not so bold as to tell you exactly how to tweak your Linux install. The important thing is that you get Ruby 2.6.5, Rails 6.0.0, and SQLite 3 installed to match the versions we'll use throughout this course.

Unless you have a strong preference, we recommend installing Ruby on Linux using rbenv. It's a command-line tool that makes it easy to install and manage Ruby versions.

  1. Start by updating apt-get and installing the dependencies required for rbenv and Ruby:

    sudo apt-get update
    
    sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
  2. Then install rbenv and the ruby-build plugin by cloning them into ~/.rbenv, like so:

    git clone https://github.com/rbenv/rbenv.git ~/.rbenv
    
    git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
  3. Then add their respective bin directories to your $PATH so you can access their command-line utilities:

    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    
    echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
  4. You also need to add rbenv init to your ~/.bashrc file so it loads rbenv automatically:

    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
  5. And then refresh your shell:

    source ~/.bashrc
  6. Once you have rbenv and ruby-build installed, it's then easy to get Ruby and and Rails installed by picking up with step 6 in the Mac OS X instructions above.

If you need additional help with other shells, more examples can be found in the Basic GitHub Checkout section of the official rbenv installation documentation.

Choose A Code Editor

Throughout the course we'll be creating a Rails application by writing Ruby code in one or more files. You'll need a code editor to create and edit these files. The editor doesn't need to have a lot of features. In fact, a basic code editor that has Ruby syntax highlighting and a file/directory browser works best.

We'll make the decision easy for you. Unless you already have a code editor that you're very comfortable using, we recommend using Visual Studio Code as we do in the videos. VS Code runs equally well on Mac, Windows, or Linux and it's completely free! We also recommend installing the Simple Ruby ERB extension which provides both Ruby and ERB syntax highlighting.

You're now ready to start creating Rails apps!