I had the same issue using zsh and this fixed it:

Copy$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
$ echo 'eval "$(rbenv init -)"' >> ~/.zshenv
$ echo 'source $HOME/.zshenv' >> ~/.zshrc
$ exec $SHELL
Answer from Ricardo Rojas on Stack Overflow
🌐
Moncef Belyamani
moncefbelyamani.com › troubleshooting-command-not-found-in-the-terminal
How to fix "command not found" after installing gems
March 17, 2023 - If you installed Ruby with Homebrew, you can get back on track by either running Ruby on Mac, or adding the Homebrew gems location to your PATH by following my guide to installing Ruby gems on a Mac. However, note that I don’t recommend installing Ruby with Homebrew because sooner or later you’ll regret it. Another reason why commands might not be found, or why the newer version of a tool is not being used, even though you updated the PATH in your shell startup file, is because those changes don’t take effect right away. You have to “refresh” it by either using the source command, such as: source ~/.zshrc ·
Discussions

zsh : command not found: pod | Apple Developer Forums
When i try to install podfiles after this command $ sudo gem install cocoapods its getting zsh command not found mac OS 13.4 More on developer.apple.com
🌐 developer.apple.com
ruby - Gem Command not found - Stack Overflow
I have installed gem on Ubuntu 10.10 32 bit with apt-get install gem -y But when I try to run gem install something.gem I get the error of the command not being found. bash: gem: command not fo... More on stackoverflow.com
🌐 stackoverflow.com
Cannot run gem executables

I did confirm that the rubocop executable is in /usr/local/lib/ruby/gems/2.7.0/bin. Do I need to add this directory to $PATH?

Yes, the bin directory needs to be in your path. A little trick I use to keep the current version's directory in the PATH is something like this in .bashrc (or .zshrc whatever it is for you)

export PATH="$PATH:$(ruby -e 'puts Gem.user_dir')/bin"
More on reddit.com
🌐 r/ruby
2
3
June 11, 2020
rubygems - Why does ZSH return "Command not found" error for my RVM gems? - Stack Overflow
I used to run the default bash terminal that comes with Mac Os X Lion but have recently upgraded to ZSH with the Oh My Zsh addon. Since then I get an odd error when using Ruby gems. In essence all gems return a "Command not found" error even though they are installed. More on stackoverflow.com
🌐 stackoverflow.com
May 12, 2014
🌐
Jekyll Talk
talk.jekyllrb.com › t › installation-probelm-zsh-command-not-found-jekyll › 4116
Installation probelm: zsh: command not found: jekyll - Jekyll Talk
March 23, 2020 - I am having difficulty installing Jekyll. The gem gets is installed but when I issue jekyll serve i get zsh: command not found: jekyll Would really appreciate it if somebody could help me out?
🌐
Moncef Belyamani
moncefbelyamani.com › the-definitive-guide-to-installing-ruby-gems-on-a-mac
Install Ruby on Mac. The Definitive Guide for 2025.
October 8, 2025 - But how did macOS recognize the rails command to begin with? That’s because there is a rails command in /usr/bin that Apple preinstalls for some reason. That message with the shocking suggestion to use sudo comes from Apple, not Rails. Other gems that don’t already exist in /usr/bin will also fail to be found after being installed, but with a different message: $ gem install jekyll $ jekyll -v zsh: command not found: jekyll
🌐
Super User
superuser.com › questions › 495465 › gem-binaries-not-found-with-oh-my-zsh
ruby - Gem Binaries not found with oh-my-zsh - Super User
October 29, 2012 - I'm using Oh-My-Zsh on Mountain Lion and have an issue with gem binaries not loading properly. For instance: If I load a new shell the binary still cannot be found. When using Bundler, I can load
🌐
Apple Developer
developer.apple.com › forums › thread › 730622
zsh : command not found: pod | Apple Developer Forums
When i try to install podfiles after this command $ sudo gem install cocoapods its getting zsh command not found mac OS 13.4
🌐
Reddit
reddit.com › r/ruby › cannot run gem executables
r/ruby on Reddit: Cannot run gem executables
June 11, 2020 -

I installed Ruby via Homebrew so I didn't f-up my system Ruby. I then started a project and installed some executable gems (Jekyll and rubocop). However, when I try to run either command, I receive the error zsh: command not found.

Here is my gem env output:

RubyGems Environment:
  - RUBYGEMS VERSION: 3.1.2
  - RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-darwin19]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.7.0
  - USER INSTALLATION DIRECTORY: /Users/onetwobus/.gem/ruby/2.7.0
  - RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
  - GIT EXECUTABLE: /usr/local/bin/git
  - EXECUTABLE DIRECTORY: /usr/local/lib/ruby/gems/2.7.0/bin
  - SPEC CACHE DIRECTORY: /Users/onetwobus/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/2.7.1_2/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-19
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/2.7.0
     - /Users/onetwobus/.gem/ruby/2.7.0
     - /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/gems/2.7.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/opt/ruby/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin

I did confirm that the rubocop executable is in /usr/local/lib/ruby/gems/2.7.0/bin. Do I need to add this directory to $PATH?

Find elsewhere
🌐
GitHub
github.com › athityakumar › colorls › issues › 264
zsh: command not found: colorls · Issue #264 · athityakumar/colorls
February 28, 2019 - zsh: command not found: colorls#264 · Copy link · Labels · question · dylanjm · opened · on Feb 28, 2019 · Issue body actions · After running gem install colorls I get this message: ******************************************************************* Changes introduced in colorls Sort by dirs : -sd flag has been renamed to --sd Sort by files : -sf flag has been renamed to --sf Git status : -gs flag has been renamed to --gs Clubbed flags : `colorls -ald` works Help menu : `colorls -h` provides all possible flag options Tab completion enabled for flags -t flag : Previously short for --tree, has been re-allocated to sort results by time -r flag : Previously short for --report, has been re-allocated to reverse sort results Man pages have been added.
Author   dylanjm
🌐
GitHub
github.com › CocoaPods › cocoapods-try › issues › 64
Catalina Mac OS X 10.15.2 (19C57) zsh: command not found: Building · Issue #64 · CocoaPods/cocoapods-try
January 25, 2020 - sudo gem install cocoapods --pre · zsh: command not found: Building · What did you expect to happen? Run without error Google-Mobile-Ads-SDK · What happened instead? zsh: command not found: Building · Probably related to Catalina Mac OSX encountered wit Firebase pod install which became successful.
Author   deepBlueC
Top answer
1 of 7
172

Homebrew is nice. However unlike brew and npm, gem does not make aliases in /usr/local/bin automatically.

Solution

I went for a very simple approach (updated December 2025):

# https://stackoverflow.com/a/14138490/319266
# Based on "`brew --prefix ruby`/bin"
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
# Based on "`gem environment gemdir`/bin"
export PATH="/opt/homebrew/lib/ruby/gems/3.3.0/bin:$PATH"

Add this to your .bashrc (or .bash_profile, .zshrc, etc.).

That's it! Now all Ruby bins and installed gems will be available from your shell!

In older versions of Homebrew (before 2017), there was a separate package for Ruby 2 called ruby20, for which you'd use the following snippet instead:

export PATH=/usr/local/opt/ruby20/bin:$PATH

This line was the only line needed at the time. But, in Ruby 2.1 the gems got moved to a separate directory. No longer under /usr/local/opt/ruby/bin, but instead at /usr/local/lib/ruby/gems/2.0.0/bin (where "2.0.0" is the last major Ruby version for Gem's purposes).

How it works

Homebrew keeps track of where it installed a package, and maintains a symbolic link for you that points there.

# Mac Intel
$ brew --prefix ruby
/usr/local/opt/ruby

# Apple Silicon (M-series)
$ brew --prefix ruby
/opt/homebrew/opt/ruby

$ l /usr/local/opt/ruby
/usr/local/opt/ruby@ -> ../Cellar/ruby/3.3.4

Effectively, adding /opt/homebrew/opt/ruby/bin to PATH is the same as the following:

export PATH=/opt/homebrew/Cellar/ruby/3.3.4/bin:$PATH

Except, this expanded path would hardcode the currently installed version of Ruby and would stop working next time you upgrade Ruby.

As for Gem, the following command will tell you the exact directory Gem adds new packages to:

# Example as of 2019
$ gem environment gemdir
/usr/local/lib/ruby/gems/2.7.0

# Example as of 2025
$ gem environment gemdir
/opt/homebrew/lib/ruby/gems/3.3.0

Tools

These tools were meant to automatically bridge between Homebrew and Gem:

  • josh/brew-gem (no longer exists)
  • indirect/brewbygems (unmaintained)

I haven't used these but they might work for you.

2 of 7
24

brew unlink ruby; brew link ruby might add symlinks to /usr/local/bin/:

$ which sass
$ brew unlink ruby; brew link ruby
Unlinking /usr/local/Cellar/ruby/2.0.0-p0... 20 links removed
Linking /usr/local/Cellar/ruby/2.0.0-p0... 31 symlinks created
$ which sass
/usr/local/bin/sass

brew --prefix ruby is still pretty slow, but you could also just add /usr/local/opt/ruby/bin to the path.

$ time brew --prefix ruby
/usr/local/opt/ruby
0.216
$ time brew --prefix ruby
/usr/local/opt/ruby
0.076
$ stat -f%Y /usr/local/opt/ruby
../Cellar/ruby/2.0.0-p0
🌐
Jesse Squires
jessesquires.com › blog › 2020 › 08 › 26 › zsh-could-not-find-cocoapods
zsh could not find CocoaPods · Jesse Squires
August 26, 2020 - The bad advice on Stack Overflow that I saw on numerous posts was to use sudo, which is considered bad practice for various reasons. Another bad suggestion was specifying the bindir to /usr/local/bin when installing the gem, which is not typically where you would want gems installed.
🌐
Medium
janhenner.medium.com › how-to-fix-zsh-command-not-found-on-the-macos-terminal-433332b9d4bf
How To Fix “zsh: command not found: …” on the macOS terminal | by Jan Henner | Medium
October 14, 2021 - I found this using the finder in the paths /users/<my_user>/.profile and /users/<my_user>/.bash_profile. Another approach might be to type “locate rust” in the terminal and look out for a .bin file — or to add code to the command to filter the output: ... 3. Open the file “users/<my_user>/.zshrc with the finder.
🌐
Super User
superuser.com › questions › 851621 › gems-installed-with-the-user-install-option-into-the-os-x-home-folder-arent-w
macos - Gems installed with the --user-install option into the OS X home folder aren't working properly afterwards. - Super User
0 On my mac, under rvm, my gem library for jruby is corrupted · 4 zsh returns bad interpreter after Catalina upgrade · 0 zsh: command not found: brew while it exists · Is there a "hook" to expand a macro after the end of a path in TikZ? Indifference and budget curve ·