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 OverflowI 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
You seem to be after installing bundler system-wide. To do this, you need to pass --no-user-install flag to gem and execute it with sudo:
Copysudo gem install bundler --no-user-install
After this, you should see bundle in /usr/bin/ just fine:
Copy$ ls /usr/bin/bundle
/usr/bin/bundle*
zsh : command not found: pod | Apple Developer Forums
ruby - Gem Command not found - Stack Overflow
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
rubygems - Why does ZSH return "Command not found" error for my RVM gems? - Stack Overflow
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
- /sbinI 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?
check your rc files
- .zshenv
- .zshrc
- .zlogin
- .zprofile
most likely in one of those PATH is reset after RVM was sourced
also some oh-my-zsh plugins can break stuff, try disabling them and enabling one by one.
In my case, this was related to ZSH complains about RVM __rvm_cleanse_variables: function definition file not found , and following the instructions there solved it.
It's evident that you've managed to mess up your PATH variable. (Your current PATH doesn't contain any location where common utilities are located.)
Try:
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:${PATH}
export PATH
Alternatively, for "resetting" zsh, specify the complete path to the shell:
exec /bin/zsh
or
exec /usr/bin/zsh
On MacOS BigSur Click Terminal >> Preferences change the from /bin/zsh to /bin/bash Close and reopen the terminal
FROM

TO

You can now go back to .zshrc file to revert the last change you made
Your $PATH variable needs to include the exact path to your Ruby's bin directory. Adding a directory to the PATH does not include it's subfolders. Try adding the bin directory via:
export PATH=$PATH:/home/adam/.gem/ruby/1.8/bin
or if you installed the gem using sudo:
export PATH=$PATH:/usr/lib/ruby/gems/1.8/bin
You might want to add this to your .bashrc file, so that you don't have to set this manually every time your open up a new bash.
(Just stealing @John Franklin's comment)
$ gem environment
Will tell you the EXECUTABLE DIRECTORY. Then put whatever that value is in your PATH like so (in your .bashrc or other shell config file).
export PATH="$PATH:/path/to/bin"
Reload your shell and you should then be able to use the installed gem.
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.
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
Question:
➜ ~ mvn
zsh: command not found: mvn
Answer:
step 1:
vim ~/.zshrc
step 2:(Add at the end of the file)
source ~/.bash_profile;
step 3:(Execution shell)
> source ~/.bash_profile
You can use mvn :
➜ / mvn
[INFO] Scanning for projects...
.......
Just add:
source ~/.bash_profile
to .zshrc