Lesson Weekend

Mac


If you're using Ruby on a Mac, it is set up by default, but you can't modify or upgrade it. However, most developers don't use the pre-installed version of Ruby on their Macs. Instead, they configure several systems to help them manage Ruby installation (and other programs), and manage different versions of Ruby. In this lesson, we'll cover installing the version of Ruby that is used on Epicodus computers. In the next lesson, we'll discuss the tools we're using in more detail.

If you have installed Ruby before, you may be using RVM (Ruby Version Manager). You may stay with RVM if it is working for you but we recommend using chruby and ruby-install, which we will go over here. To uninstall RVM, type $ rvm implode.

Here are the instructions for installing the Ruby version used at Epicodus:

  1. Run $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)". This will install Homebrew, a package manager for OS X that makes it easy to install developer software. When you finish, Homebrew might tell you how to install a compiler (it differs depending on your version of OS X).
  2. Run $ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile. This tells your system where to find the programs you install with Homebrew. Then, run $ source ~/.bash_profile to add this configuration to your open terminal window.
  3. Run $ brew doctor and fix any problems it tells you about.
  4. Run $ brew install ruby-install to install ruby-install, a tool for installing Ruby. Then run $ ruby-install ruby 2.6.5 to install Ruby. If you get the following error configure: error: clang version 3.0 or later is required, you'll need to install Xcode developer tools first: xcode-select –-install.
  5. Optionally, you can run $ rm -rf ~/src/ to remove the source code that ruby-install downloaded as you won't need it anymore. As always, be very careful using the $ rm -rf command. Alternatively, once you are using VS Code, you can use $ code ~/src/ to open the directory in VS Code, look at the Ruby source code there, and remove it manually.
  6. Run $ brew install chruby. This will install chruby, a program to manage which versions of Ruby you're using.
  7. Run $ echo 'source /usr/local/opt/chruby/share/chruby/chruby.sh' >> ~/.bash_profile and $ echo 'source /usr/local/opt/chruby/share/chruby/auto.sh' >> ~/.bash_profile. This will set up Bash to use chruby and also set up auto-switching of Ruby versions. Then run $ echo "ruby-2.6.5" > ~/.ruby-version to set your default Ruby version to 2.6.5. Again, run $ source ~/.bash_profile to add this configuration to your open terminal window.
  8. The last configuration I'd recommend is that you run $ echo "gem: --no-rdoc --no-ri" > ~/.gemrc so that when you install Ruby gems (more on this later), you won't install the documentation by default. (It takes longer than installing the gems themselves, and better documentation is available online.)
  9. Finally, verify that you can install Rails: $ gem install rails -v 5.2.0.
  10. You can verify that Rails is working by navigating to the desktop and creating a new project: $ rails new test_project. It will take a little time for Rails to spin up a new project. After you confirm the project has been created, delete the test_project directory.

And with that, you're ready to go. Check out the READMEs for chruby and ruby-install, or at least bookmark them for later, so you know how to install other versions of Ruby and switch between them as needed.

Windows


Note: Why doesn't Epicodus have more detailed Windows installation instructions? Unfortunately, there is no "one size fits all" installation setup for Windows machines. Installations are often riddled with errors and it can take some serious persistence to get Ruby set up on a Windows machine.

On Windows, the easiest way to install Ruby is with the RubyInstaller, which includes Ruby and a few other tools we'll use throughout these lessons. Make sure to install the Ruby+Devkit 2.6.6-2 version, to have a compatible version with the tools used in the curriculum. There is both a 64 bit (x64) and 86 bit (x86) version available. The built-in System Information program on Windows machines has information on which version your machine is using. Because the instructions on where to find this information vary based on your Windows version, if you don't know how to find this information, we recommend a quick Google search to determine with version you should download.

If you have trouble installing Ruby on your computer, you can try an online development environment like SourceLair.

After installing Ruby, you might run into issues using Ruby on the command line. Enable this for future lessons with the following: $ echo $'alias irb=\'winpty "$(which irb).cmd"\'' >> ~/.bash_profile. Then, verify that you can install Rails: $ gem install rails -v 5.2.0. Then verify that Rails is working by navigating to the desktop and creating a new project: $ rails new test_project. It will take a little time for Rails to spin up a new project. After you confirm the project has been created, delete the test_project directory.

Lesson 3 of 6
Last updated February 11, 2021