I'm a beginner, please excuse me if I'm saying or doing things you perceive as utterly stupid. I'm not doing it on purpose.

How this started: I wanted to install gems, but got the following error message:

ERROR:  While executing gem ... (Gem::FilePermissionError)
   You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory

Somehow, my system is apparently still using the Ruby version that came with MacOS, which gives this permission error. It should be using the newly installed version, 2.6.1., which I installed using Homebrew.

So, upon internet research, I installed rvm, and tried to make Ruby 2.6.1 the default:

~rvm --default use 2.6.1
Required ruby-2.6.1 is not installed.

So rvm tells me Ruby 2.6.1 is not installed. But homebrew insists it is installed:

~brew upgrade ruby
Error: ruby 2.6.1 already installed

Should I uninstall the homebrew Ruby and install Ruby again via rvm?


First of all, nothing you say or do is going to sound stupid. We've all been beginners at some point.

The reason why your Mac didn't automatically recognize the Ruby version installed by Homebrew is because by default, the computer only looks for executable programs in certain directories. The list of directories, and the order in which the computer looks them up is called the PATH. If you type echo $PATH in Terminal, you will see the list of directories, separated by a colon. By default, on a brand new macOS installation, I believe the list looks like this:


During the Homebrew installation, a new directory /usr/local/bin gets created and added to the beginning of the PATH. However, when you install Ruby with Homebrew, Ruby is installed in /usr/local/opt/ruby/bin, which doesn't get added to the PATH automatically. I know this because it's mentioned by Homebrew at the end of the Ruby installation. Admittedly, the message might not mean much to a beginner:

If you need to have ruby first in your PATH run:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile

Since the Homebrew version of Ruby wasn't in your PATH, when you typed gem install [some gem], the computer looked for the program called gem in /usr/local/bin first and didn't find it, then it looked for it in /usr/bin and found it because that's where the system gem (the version of gem that comes with macOS) is installed.

If you want to know which version of a particular program is in use in the current Terminal session, you can use the which command. For example:

which ruby
which gem

This will tell you the location of the program where the computer first found it.

Another command you can use to see if you're using the right Ruby version is:

ruby -v

If you had run this command:

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile

and then opened a new Terminal window or tab (or ran source ~/.bash_profile) for the changes to take effect, the Homebrew Ruby directory would have been first in your PATH, which means your computer would have looked for gem there first, and it would have used the Homebrew version of Ruby.

To explain the command above, it takes everything between the single quotes and adds it (>>) to a file called .bash_profile in your user's root directory (~/). Every time you open a new Terminal window or tab, .bash_profile is read, and anything defined there is used.

Similarly, the reason why RVM couldn't recognize that Ruby 2.6.1 had been installed by Homebrew is because RVM and Homebrew install Ruby in two separate places that don't know about each other. When you first installed RVM, it installed version 2.6.0. I'm not sure why it didn't install 2.6.1, but I do recall in the past when I used RVM that it wouldn't always install the latest version. I personally prefer chruby and ruby-install to manage Ruby versions.

The nice thing about tools like RVM, chruby, and rbenv is that they allow you to install multiple versions of Ruby on the same computer, and you can switch from one to the other easily. Homebrew, on the other hand, can only manage one version of Ruby at a time.


I uninstalled Ruby using Homebrew. brew uninstall ruby

Then tried installing Ruby using RVM. rvm install ruby

It gave Already installed ruby-2.6.0. To reinstall use:

rvm reinstall ruby-2.6.0

So I chose to reinstall it with RVM. This finally fixed the issue, I was able to install gems. However I am still not sure why there was an issue with the Homebrew installation of Ruby.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.