LearnRails.Dev
Home / Guides / Setting Up Your Development Environment

Setting Up Your Development Environment

min read Last updated: January 01, 2025

Table of Contents

To get started with the Ruby, you’ll need to install Ruby to your system. For simplicity, I’ll write instructions specifically for macOS, but if you’re on a Linux or Windows machine you’ll need to find and use another installation guide, like the one linked below from GoRails.

If you’ve already got an existing Ruby version manager installed, please use that and adapt the instructions to your version manager (i.e., rbenv).

Install Xcode or Command Line Tools for Xcode

You’ll have to install Xcode, or the Xcode Command Line Tools.

Open Terminal.app from Launchpad. (You’re free to use another terminal like iTerm 2, Hyper or Warp if you’d like, they will all work the same, but provide differing levels of features and functionality).

Then run:

$ xcode-select --install

Installing Homebrew

If you just purchased a new Mac, you might not have installed Homebrew, so please do so now.

Homebrew's website goes into more detail, and will provide up-to-date installation instructions if the instructions below are found to not be working.

In your Terminal run:

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

Next, close and re-open your terminal for the next step.

Installing development dependencies

In your Terminal run:

$ brew install git

Next, we need to configure git and create an SSH key that we will use to authenticate with GitHub, which is a source code repository to store our code.

Use the email you’ll use in the next step to create a GitHub account.

git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"
ssh-keygen -t rsa -b 4096 -C "YOUR@EMAIL.com"

Create a GitHub account here.

Next we must add our SSH key we created, this command should read the value and put it on your clipboard.

$ cat ~/.ssh/id_rsa.pub | pbcopy

Now on GitHub you can add the SSH key here.

Then to confirm everything works, back in your Terminal you can run:

$ ssh -T git@github.com

You should receive a message welcoming you, and returning the username you created for GitHub.

Hi afomera! Youve successfully authenticated, but GitHub does not provide shell access.

Installing and running services through Homebrew

If you’ll be using your computer to do Ruby on Rails development, you’ll need to install a few extra services.

SQLite SQLite is a flat file database, stored in the filesystem. By default, Ruby on Rails uses a SQLite database. In the past you may have heard not to use SQLite in production, and it’s true for some hosts like Heroku, but if you’re using the Rails defaults it’s perfectly ok to use. In fact this site uses sqlite!

brew install sqlite

MySQL If you come from another programming language where it’s common to use MySQL, like PHP, you may want to go ahead and ensure it’s installed on your system. You can use MySQL for Ruby on Rails' database as well, though if you’re not familiar with any databases, I would recommend using PostgreSQL instead.

brew install mysql

# To start mysql in the background at login
brew services start mysql

PostgreSQL (recommended for beginners / this book)

brew install postgresql

# To start postgres in the background at login
brew services start postgresql

Redis (recommended for Ruby on Rails development) Redis is an in-memory data store used by millions of developers as a database, cache, streaming engine, and message broker. This is a super powerful package that has a variety of uses. For Ruby on Rails development, we will use it to power our real-time functionality behind the scenes.

brew install redis

# to start redis in the background at login
brew services start redis

Brew Services

You’ve already seen how you can start services in the background at login, but there are three more commands that may be useful to know.

Listing services Listing the services running can also provide information on the current status of services, if they’re running, stopped, errored and so forth.

brew services list

Stopping services

$ brew services stop [name]

Restarting services

$ brew services restart [name]

Installing ASDF

We’ll be using a tool version manager called ASDF. ASDF is compatible with a wide variety of languages and provides one tool version manager to learn that you can use for other languages if needed. ASDF allows us to set a .tool-versions file at the root of our projects, and ASDF will automatically switch to the versions (if they’re installed on your system).

View ASDF’s website, which has a wide variety of additional information, so I’ll encourage you to check it out for more detailed information outside this book.

To install ASDF on macOS with Homebrew with your Terminal, run:

brew install asdf

Next, we need to tell your SHELL you use to start ASDF every time you open a terminal.

In Terminal run:

which $SHELL

ZSH

You should get back the following if you use macOS Catalina or higher, if you’re not using a newer version of macOS you should follow the Bash instructions below.

/bin/zsh

Which would mean you’re using a Zsh shell.

Next we need to modify our shells configuration file to tell ASDF to start on our Terminal’s open, so in Terminal run:

$ echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

This adds asdf.sh to your profile to ensure ASDF is loaded and runs correctly. To confirm it worked, close and re-open your Terminal and run asdf version to confirm asdf has been properly installed.

Bash

Or you might get back the following result when running which $SHELL, which would mean you’re using a Bash shell.

/bin/bash

In terminal, run this instead, this is basically the same setup as the ZSH configuration, but it appends the text to a different file, in this case ~/.bash_profile instead of the .zshrc file.

$ echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.bash_profile

In most cases, you’re likely using ZSH on a new machine, as Apple switched to ZSH in macOS Catalina. If you’re not using either Bash or ZSH, follow the instructions on the ASDF installation guide.

Installing asdf plugins

By default, installing ASDF won’t really help with anything on its own, we need to install plugin managers so that asdf knows how to manage Ruby and Node for this example.

If you’re just going to do Ruby you can skip the NodeJS steps, but if you plan to do Ruby on Rails development, please go ahead and install the NodeJs plugin.

Installing the Ruby Plugin

$ asdf plugin-add ruby

Now we can install the latest version of Ruby 3, which at the time of writing is Ruby 3.4.1

$ asdf install ruby 3.4.1

Then we can set Ruby 3.4.1 to be available globally on the system

$ asdf global ruby 3.4.1

To confirm Ruby is running through ASDF, in your Terminal run:

$ which ruby

You should get something like the following back, where the username for your computer is replaced.

/Users/afomera/.asdf/shims/ruby

That’s all! Ruby is installed on your system, and you’re ready for the next step.

Installing the NodeJS plugin

First, add the plugin for NodeJS to ASDF.

$ asdf plugin add nodejs

Then we can install the NodeJS

$ asdf install nodejs 22.12.0

Lastly, let’s set NodeJS to be globally available.

$ asdf global nodejs 22.12.0

To confirm Ruby is running through ASDF, in your Terminal run:

$ which node

You should get something like the following back, where the username for your computer is replaced.

/Users/afomera/.asdf/shims/node

That’s all! NodeJS is installed on your system, and you’re ready for the next step.

Listing versions

With ASDF, you can list versions of a specific plugin

$ asdf list-all nodejs 18

This command will list all the versions of NodeJS that start with 18

To list all the Ruby 3 versions you can install:

$ asdf list-all ruby 3 # list all versions of Ruby 3 that can be installed

Updating ASDF / the plugins

Occasionally, you’ll want to update the Ruby or NodeJS version on your system to take advantage of the improvements in those languages, so how do we update ASDF so it knows about the new versions?

asdf update # update ASDF itself
asdf plugin-update --all # update all plugin

# or you can update just one plugin
asdf plugin-update ruby

Then you should now be able to list-all the versions for that language and see the new one available for installation.

That’s all for this chapter, great work if you made it this far. Setting up your machine is one area where it really can take a while, so if you’ve got Ruby installed, you’re already a step ahead of where you were before.

Installing a Text Editor

There are dozens of editors you could choose to write your code inside of, with varying features or benefits. I’ll list a few of the most common editors, but please note this is a very personal choice and many developers spend time customizing their editor with themes or different syntax highlighting.

For the sake of brevity I’ll be using VSCode for writing my code, but use whatever you feel most productive in. I’d recommend avoiding trying out multiple editors at once, as it can be a bit overwhelming to switch between them. Try to stick with one for a while before switching to another.

VSCode

  • Download VSCode

  • Install it per the instructions for your operating system

  • Open VSCode and press CMD+SHIFT+P if you’re on a Mac or CTRL+SHIFT+P if you’re on Linux or Windows and type >install code when the box pops up.

VSCode install code
Figure 1. VSCode Command Line Tools Installation
  • Select “Install 'code' command in PATH”

This will allow you from your Terminal to open VSCode in the current directory.

For example inside of ~/code/learn_ruby you can run code . to open the learn_ruby directory into VSCode.

Other options

  • Sublime Text

  • VIM (though unless you’re already familiar I wouldn’t recommend this for beginners at this point).

  • RubyMine

Whew, that was a lot!

Well dang! Look at us go. That was a lot of setup and with time you’ll likely get faster at installing everything you need when you get a new computer or you need to re-setup your machine.

If you’re still with me, you’re ready for the next chapter, where we will start writing our first Ruby code. But feel free to take a break, go for a walk, or grab a snack. You’ve earned it.

Want to Read More?

This is just a preview. Get access to the full course and learn how to build complete web and mobile applications with Rails.

Get Full Access (coming soon!)