Installing on macOS

Since macOS Catalina ships with Ruby 2.6.3, you can skip ahead to the gem install rails line below. If you are running a prior version of macOS, you need to download a newer version of Ruby that works with Rails 6. The easiest way to do this is to use Homebrew.

Before you start, go to your Utilities folder and drag the Terminal application onto your dock. You’ll be using this during the installation and then frequently as a Rails developer. Open the terminal and run the following command:

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

When it asks you to install the Xcode command line tools, say yes.

Next, you have a choice. You can let Homebrew update your version of Ruby to the latest (currently Ruby 2.6.5). Or you can install rbenv and install a parallel version of Ruby alongside the system version of Ruby.

Upgrading your version of Ruby is the most straightforward path and can be done with a single command:

 $ ​​brew​​ ​​install​​ ​​ruby

Alternatively, you can install rbenv and use it to install Ruby 2.6.5. Just be sure that you do not have RVM installed as those two applications don’t work well together.

Note that in macOS Catalina, the default shell is zsh, not bash as it had been historically. Assuming you are using Catalina and zsh, the Homebrew setup is as follows:

 $ ​​brew​​ ​​install​​ ​​rbenv​​ ​​ruby-build
 $ ​​rbenv​​ ​​init
 $ ​​echo​​ ​​'eval "$(rbenv init -)"'​​ ​​>>​​ ​​~/.zshrc
 $ ​​rehash

On older versions of macOS (or if you are using bash on Catalina), the instructions are similar:

 $ ​​brew​​ ​​install​​ ​​rbenv​​ ​​ruby-build
 $ ​​echo​​ ​​'export PATH="$HOME/.rbenv/bin:$PATH"'​​ ​​>>​​ ​​~/.bash_profile
 $ ​​~/.rbenv/bin/rbenv​​ ​​init
 $ ​​hash​​ ​​-r

Once you’ve done that, restart your terminal by typing exit and hitting return, and then opening a new terminal window. After that, you can install Ruby like so:

 $ ​​rbenv​​ ​​install​​ ​​2.6.5
 $ ​​rbenv​​ ​​global​​ ​​2.6.5

If you had previously installed ruby-build and it can’t find the definition for Ruby 2.6.5, you might need to reinstall ruby-build and try again:

 $ ​​brew​​ ​​reinstall​​ ​​--HEAD​​ ​​ruby-build
 $ ​​rbenv​​ ​​install​​ ​​2.6.5
 $ ​​rbenv​​ ​​global​​ ​​2.6.5

These are the two most popular routes for Mac developers. RVM and chruby are two other alternatives.[12][13]

Whichever path you take, run the following command to see which version of Ruby you’re working with:

 $ ​​ruby​​ ​​-v

You should see the following type of result:

 ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]

Next, run this command to update Rails to the version used by this book:

 $ ​​gem​​ ​​install​​ ​​rails​​ ​​--version=6.0.1​​ ​​--no-document

Finally, install Yarn and ChromeDriver:

 $ ​​brew​​ ​​install​​ ​​yarn
 $ ​​brew​​ ​​tap​​ ​​homebrew/cask
 $ ​​brew​​ ​​cask​​ ​​install​​ ​​chromedriver

OK, you OS X users are done. You can skip forward to join the Windows users in Choosing a Rails Version. See you there.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.82.78