Lesson Weekend

If you're using Ruby on a Mac, it is set up by default, but you can't modify or upgrade it. 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 two installation options to get started with Ruby: (1) using Docker, and (2) installing the version of Ruby and version management tools that are used on Epicodus computers.

Docker Containers

One option is to use a tool called Docker to containerize our applications. A container has everything we need to run our application - the complete set of tools and processes to for our development environment. Whenever we introduce important new tools in the Ruby/Rails course, we'll provide the basic scaffolding for an application with a Docker configuration so that you can easily use Docker to containerize your Ruby, Sinatra, and Rails configurations. Other than having Docker installed on your local machine, there's no other installation needed (including Postgres)!

Using Docker ultimately decreases requirements for software installation and troubleshooting, version management, and debugging complex environment issues. We dive into the details of Docker, containerization, and the benefits of learning and using this tool in the Introduction to Docker lesson. Please know that using Docker is entirely optional.

To install Docker, follow the instructions in Installing Docker, and then work through the pre-work in the Docker with Ruby Pre-Work.

Please know, this curriculum is in beta. Even though this will be our recommended approach going forward, challenges may come up. You can always use the other option below, and you can switch to and from using Docker at any point in the coursework.


The other option is to install Ruby (and Postgres) directly to your machine. 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.

Homebrew Installation

If you do not have Homebrew installed yet, you may install it now by copy and pasting this command into the command line:

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This installs Homebrew on your device, a package manager for OS X that makes it easy to install developer software.

Next, ensure Homebrew packages are run before the system versions of the same (which may be dated or not what we want) by executing the following:

For bash users: shell $ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile

For zsh users: shell $ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.zshrc

Install ruby-install

To install ruby-install, a tool for installing Ruby, run this command:

$ brew install ruby-install

Install Ruby

To install the version of Ruby we use at Epicodus, run this command:

$ ruby-install ruby 2.6.5

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.

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.

Install and Configure chruby

To install chruby, a program to manage which versions of Ruby you're using, run this command:

$ brew install chruby

Next, configure your shell's environment variables for chruby by running the following two commands. This will set up bash or zsh to use chruby and also set up auto-switching of Ruby versions.

For bash users:

$ echo 'source /usr/local/opt/chruby/share/chruby/chruby.sh' >> ~/.bash_profile
$ echo 'source /usr/local/opt/chruby/share/chruby/auto.sh' >> ~/.bash_profile

For zsh users:

$ echo 'source /usr/local/opt/chruby/share/chruby/chruby.sh' >> ~/.zshrc
$ echo 'source /usr/local/opt/chruby/share/chruby/auto.sh' >> ~/.zshrc

To set your default Ruby version to 2.6.5, run this command:

$ echo "ruby-2.6.5" > ~/.ruby-version

The last configuration I'd recommend is to not install documentation when you install Ruby gems (more on this later). Why? It takes longer than installing the gems themselves, and better documentation is available online. Optionally, run this command:

$ echo "gem: --no-rdoc --no-ri" > ~/.gemrc

Install Rails

Finally, verify that you can install Rails at the same version we use at Epicodus:

$ gem install rails -v 5.2.0

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!

Next steps

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.

Also, read through the upcoming lesson on Managing Ruby Versions that goes into detail about using the tools ruby-install and chruby.

Not sure whether to install Ruby or use Docker?

Or perhaps you have questions about the benefits and drawbacks of working with Docker instead of installing Ruby? Read through the FAQ: Should I Install Ruby or Use Docker?.

Lesson 3 of 8
Last updated October 13, 2021