Rails is not currently installed on this system: how to fix this error

Updated

Did you just install Rails on your Mac, but got “Rails is not currently installed on this system” when you tried to use it?

Depending on how you installed Rails, the fix could be easy or complicated. Whatever you do, please don’t follow the instructions to simply type sudo gem install rails. Learn why you should never use sudo to install gems.

This error could also be due to how you installed Ruby. If you used rbenv, your system might not immediately recognize gems after installing them. This isn’t an issue with chruby, which is why it’s the Ruby version manager I recommend.

Here are four ways to fix the error “Rails is not currently installed on this system”:

Quit and restart Terminal

When you make changes to your development environment, they might not take effect right away. This is one of the most common sources of confusion, and quitting and restarting Terminal will solve many problems. Just like turning it off and on again.

If that doesn’t work, try the next solution in this guide.

Install Rails again

Another common scenario where a gem might not be found is when switching between Ruby versions. If you installed Ruby with a version manager (such as chruby, rbenv, asdf, or rvm), you’ll need to install gems separately in each version of Ruby.

For example, if you first installed Rails while using Ruby 3.1.0, and then you installed and switched to Ruby 2.7.5, Rails won’t be there automatically. You’ll need to run gem install rails again in each version of Ruby that you install.

If that doesn’t work either, try the next solution in this guide.

Install Rails with chruby and ruby-install (most reliable)

Of all the possible ways to install Rails on a Mac, I recommend using a Ruby manager. This allows you to have multiple versions of Ruby installed at the same time, and makes it easy to switch between them. And of all the Ruby managers, I recommed chruby and ruby-install because they’re the most reliable and easiest to use.

Even if you don’t think you’ll need more than one version now, it’s worth your time to learn how to use a Ruby version manager because you will inevitably need one.

The good news is that my Ruby on Mac script will get you back on track in minutes. Over the past ten years, I’ve helped thousands of people like you set up Ruby properly on their Mac.

Read what people say about the script.

Not only will Ruby on Mac set up a proper Ruby environment, it will also automatically install Rails, and all the other tools you’ll need for Rails. All with a single command. It will save you so much time and frustration.

It doesn’t just have a one-time use. You can run it over and over to keep your system up to date and secure. And the next time you get a new Mac, it will save you half a day because it can also automatically install all your Mac apps, in addition to a complete development environment. You get all of these time savings now and in the future for a one-time cost.

When you buy Ruby on Mac today, you’ll be supporting an independent developer, and you get it at a very reasonable price given how much time it saves.

If you’re trying to set up Rails on a work computer, you should be able to expense the one-time cost of Ruby on Mac.

Update your PATH (time-consuming and complicated)

For your computer to know about a command, gem, or other executable program, it has to be told where to look for it. It wouldn’t be efficient for the computer to search the entire hard drive for the program. Instead, it looks in a specific list of locations, which are stored in an environment variable called PATH. You can view this list by running this command in your terminal:

echo $PATH

When you install new programs, such as Rails, they might get installed in a location that is not already included in the PATH. If you don’t add this new location to the PATH, the computer won’t know to look for it there, and so it thinks it doesn’t exist.

With my Ruby on Mac script, you don’t have to worry about any of this. It detects and configures everything automatically.

For a more in-depth guide on PATH and how to add locations to it, read my guide about troubleshooting command not found.

The location where Rails was installed depends on how you installed Ruby. If you installed Ruby with Homebrew (which I don’t recommend), you probably missed this instruction to add the Homebrew gems location to your PATH:

By default, binaries installed by gem will be placed into:
  /usr/local/lib/ruby/gems/3.1.0/bin

You may want to add this to your PATH.

On an M1 Mac, depending on whether or not you ran Terminal in Rosetta mode, it might refer to /opt/homebrew instead of /usr/local.

But if you don’t know how to add things to your PATH, that message is not very helpful. Here’s one way to add it to your PATH:

echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.1.0/bin:$PATH"' >> ~/.zshrc

Replace .zshrc with .bash_profile if you’re using bash. If you’re not sure, read my guide to find out which shell you’re using.

And if you’re on an M1 Mac and you didn’t use Rosetta when you installed Homebrew, then replace all instances of /usr/local in the command above with /opt/homebrew.

The 3.1.0 in the command above assumes Homebrew installed a Ruby version that starts with 3.1. If you’re using a different version (which you can check with ruby -v), replace 3.1 with the first two digits of your Ruby version.

Once you’ve updated your PATH, quit and restart your terminal, then verify that the Homebrew gems directory is included in the GEM PATHS section when running this command:

gem env

Then install Rails again to be sure it’s installed:

gem install rails

Then quit and restart your Terminal, and now you should be able to use the rails command:

rails -v

While this solution works, I don’t recommend continuing to use Ruby as managed by Homebrew because you won’t be able to easily switch between different Ruby versions. This will cause you confusion and headaches sooner or later.

Instead, I recommend using a version manager like chruby, which is what my Ruby on Mac script uses to set up a proper Ruby environment so you can be up and running with Rails in minutes.