Not able to use rails command on m1 mac air, keep asking me to install

➜ ~ which ruby /opt/homebrew/opt/ruby/bin/ruby ➜ ~ ruby --version ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]

how did you solve this issue?

1 Like

I do this sometimes, might help you:

  1. git clone -b 7-0-stable --single-branch GitHub - rails/rails: Ruby on Rails ~/rails
  2. cd to ~/rails
  3. bundle exec railties/exe/rails --version

If you’re using rbenv then try:

rbenv rehash

or if you use RVM then try:

source ~/.rvm/scripts/rvm

otherwise try closing / reopening the Terminal window, or in lieu of that, this:

source ~/.bashrc
source ~/.zshrc

Use sudo gem pristine --all, this solved it for me.

I thought sudo was to be avoided, that is, never used for higher level things like gems. I think if you think sudo is necessary, it’s the wrong approach. You’ll end up with similar problems later.

I agree with you. The main idea I wanted to get across is to restore the gems, no matter the mode, it can be with bundle pristine, gem pristine…

1 Like

@venkman from your screenshot, I see that you installed Ruby with Homebrew. Instead, I recommend using a Ruby version manager (such as chruby, rbenv, or asdf). The reason why rails is not being recognized is because your PATH does not include the Homebrew directory where gems were installed. The second directory in your PATH is almost the right one. It’s just missing the bin at the end. So, it should be this:


You’re probably adding that directory to your PATH in your ~/.zshrc file, so open that file, add the bin at the end, then quit and restart your Terminal.

I’ve written about this issue in more detail in these articles of mine: