Ruby

audience developer
level all
topic Ruby
subtopic Installation

Uninstall Ruby on Mac

I've written a guide Install Ruby on Mac that will help you select either Homebrew or a version manager to install Ruby. It is just as important to know how to completely remove Ruby.

Before you get started

You'll need a terminal application to uninstall Ruby. Apple includes the Mac terminal but I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and worth a try.

Why Uninstall Ruby

Here are reasons you may need this article:

  • You're not sure how Ruby was installed on your Mac.
  • The Ruby version that runs is not the version you want (use ruby -v for version information).
  • You've got the Homebrew package manager and it automatically updated Ruby to a newer version.
  • You need a different Ruby version and you don't have a version manager installed.
  • You want to use a different version manager (say, switching from RVM to asdf).
  • You've installed Ruby previously for an application such as Jekyll and you need to begin development using a different Ruby version (for example, for Rails).
  • Ruby isn't behaving as you expect and you want to install it from scratch.
  • A Ruby application fails and you want to eliminate all dependencies (including any gems) and start from a clean install.
  • You want to intentionally break Ruby applications that may not be using the Ruby version you wish to support.
  • You've got Ruby versions you no longer need and you want to free storage space.

Take note that though you can remove any Ruby version installed by Homebrew or a version manager, experienced developers don't remove the system Ruby which comes pre-installed on macOS. Instead, you'll set your shell configuration to override or pre-empt the system Ruby after installing Homebrew or a version manager. Instructions in the guide Install Ruby on Mac will show you how to install Homebrew or a version manager and set your shell configuration.

Steps

This is a guide to remove Ruby on a Mac.

  1. Use which -a ruby to see how Ruby was installed.
  2. Don't remove the system Ruby!
  3. Uninstall Ruby (detailed instructions in this guide).
  4. Update the shell configuration ~/.zshrc file (if necessary).

How was Ruby Installed?

Check how Ruby was installed.

The command which -a ruby will show you where Ruby is installed.

$ which -a ruby

The installation location will show you how Ruby was installed. Results will also show if more than one Ruby executable is installed.

Here is a list of possible results.

The system Ruby

$ which -a ruby
/usr/bin/ruby

If you see /usr/bin/ruby, it is the system Ruby which comes pre-installed on macOS to support scripting. See the article Do Not Use the MacOS System Ruby for an explanation (the system Ruby is there for macOS, not you). Don't try to remove the system Ruby. Leave it in place and use Homebrew or a version manager to install a newer Ruby version. See Install Ruby on Mac for recommendations of version managers. Installation of Homebrew or a version manager will require setting your shell configuration to override or pre-empt the system Ruby.

Homebrew

$ which -a ruby
/usr/local/bin/ruby

or

$ which -a ruby
/opt/homebrew/opt/ruby/bin/ruby

If Ruby was installed by Homebrew, you'll see /usr/local/bin/ruby (on Intel silicon) or /opt/homebrew/opt/ruby/bin/ruby (on Apple silicon).

RVM

$ which -a ruby
~/.rvm/rubies/

If Ruby was installed with rvm, it will be in ~/.rvm/rubies/ by default. You won't see the tilde character; instead you'll see your user home directory.

rbenv

$ which -a ruby
~/.rbenv/versions/

If Ruby was installed with rbenv (with the ruby-build utility), it will be in ~/.rbenv/versions/ by default.

chruby

$ which -a ruby
~/.rubies/

If Ruby was installed with chruby (with the ruby-install utility), it will be in ~/.rubies/ by default.

frum

$ which -a ruby
/var/folders/...

If Ruby was installed with frum, it will be in /var/folders/... by default.

asdf

$ which -a ruby
~/.asdf/shims/ruby

If Ruby was installed with asdf, you will see the ~/.asdf/shims/ruby directory.

Ruby versions are installed by default in ~/.asdf/installs/ruby.

Uninstall Ruby with Homebrew

Homebrew is a package manager, not a version manager. It only installs one version of Ruby. You cannot switch among Ruby versions with Homebrew (install a version manager if you need to switch among Ruby versions).

Before removing Ruby, run diagnostics

Run a diagnostic to list all the packages you've installed with Homebrew. You should see Ruby and its dependencies.

$ brew list
==> Formulae
ca-certificates	libyaml		openssl@3	readline	ruby

You can also display a list of packages with their dependencies.

$ brew deps --tree --installed
ca-certificates

libyaml

openssl@3
└── ca-certificates

readline

ruby
├── libyaml
├── openssl@3
│   └── ca-certificates
└── readline

Finally, you can see a list of Ruby files installed with Homebrew. This example is from Homebrew on Apple silicon, where Homebrew files are installed in /opt/homebrew.

$ brew list ruby
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/bundle
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/bundler
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/erb
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/gem
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/irb
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/racc
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/rake
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/rbs
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/rdbg
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/rdoc
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/ri
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/ruby
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/typeprof
/opt/homebrew/Cellar/ruby/3.2.2_1/include/ruby-3.2.0/ (193 files)
/opt/homebrew/Cellar/ruby/3.2.2_1/lib/libruby.3.2.dylib
/opt/homebrew/Cellar/ruby/3.2.2_1/lib/pkgconfig/ruby-3.2.pc
/opt/homebrew/Cellar/ruby/3.2.2_1/lib/ruby/ (4160 files)
/opt/homebrew/Cellar/ruby/3.2.2_1/lib/libruby.dylib
/opt/homebrew/Cellar/ruby/3.2.2_1/libexec/gembin/ (2 files)
/opt/homebrew/Cellar/ruby/3.2.2_1/share/emacs/site-lisp/ruby/ruby-style.el
/opt/homebrew/Cellar/ruby/3.2.2_1/share/man/ (4 files)
/opt/homebrew/Cellar/ruby/3.2.2_1/share/ri/ (12222 files)

Remove Ruby and dependencies from Homebrew

You can uninstall Ruby from Homebrew with brew uninstall --force ruby:

$ brew uninstall --force ruby

The brew autoremove command will remove unused dependencies.

$ brew autoremove

After removing Ruby, run diagnostics

Run Homebrew diagnostics to confirm you've uninstalled Ruby from Homebrew.

$ brew list
==> Formulae
$ brew deps --tree --installed
$ brew list ruby
Error: No such keg: /opt/homebrew/Cellar/ruby

Remove artifacts

You should also remove the shell configuration that gives the Ruby version installed by Homebrew priority over the system Ruby. Open the ~/.zshrc file with a text editor and remove the lines shown below.

On Mac M1, M2, M3:

if [ -d "/opt/homebrew/opt/ruby/bin" ]; then
  export PATH=/opt/homebrew/opt/ruby/bin:$PATH
  export PATH=`gem environment gemdir`/bin:$PATH
fi

On Mac Intel:

if [ -d "/usr/local/opt/ruby/bin" ]; then
  export PATH=/usr/local/opt/ruby/bin:$PATH
  export PATH=`gem environment gemdir`/bin:$PATH
fi

If you need to reinstall Ruby with Homebrew, see Install Ruby with Homebrew. For a guide that compares version managers for Ruby, see Install Ruby on a Mac.

Uninstall Ruby on Mac with RVM

There are two ways to remove rubies from RVM:

  • rvm remove removes Ruby and cleans up most of the install
  • rvm uninstall removes only Ruby (leaves anything else)

rvm uninstall just removes the folder under ~/.rvm/rubies. In most cases, you should use rvm remove. For example:

$ rvm list rubies
ruby-3.4.1
$ rvm remove ruby-3.4.1

See Removing Rubies with RVM.

If you want to reinstall Ruby, see Install Ruby on Mac for recommendations of newer version managers.

Uninstall Ruby on Mac with rbenv

For rbenv, use rbenv versions to see which versions you have installed.

Use the uninstall command to remove a version.

$ rbenv versions
3.4.1
$ rbenv uninstall 3.4.1

This will remove any gems associated with the version as well.

If you want to reinstall Ruby, see Install Ruby on Mac for recommendations of newer version managers.

Uninstall Ruby on Mac with Chruby

Chruby installs versions of Ruby in the ~/.rubies/ folder, so version 3.4.1 is in the ~/.rubies/ruby-3.4.1 folder. Gems for the version are in the ~/.gem/ruby/3.4.1/gems folder.

If you wish to remove a Ruby version, you can run:

$ rm -rf ~/.rubies/ruby-3.4.1
$ rm -rf ~/.gem/ruby/ruby-3.4.1

If you want to reinstall Ruby with chruby, see Install Ruby with Chruby.

Uninstall Ruby on Mac with frum

For frum, use frum versions to see which versions you have installed.

Use the uninstall command to remove a version.

$ frum versions
3.4.1
$ frum uninstall 3.4.1

This will remove any gems associated with the version as well.

If you want to reinstall Ruby with frum, see Install Ruby with Frum.

Uninstall Ruby on Mac with asdf

If you have installed Ruby using asdf, first list all installed versions.

$ asdf list ruby
3.4.1

Then uninstall any version.

$ asdf uninstall ruby 3.4.1

You may want to remove the asdf ~/.tool-versions file that sets the default versions.

If you want to reinstall Ruby with asdf, see Install Ruby with Asdf.

Here's a guide if you need to Uninstall Asdf.