how did you solve this issue?
I do this sometimes, might help you:
- git clone -b 7-0-stable --single-branch GitHub - rails/rails: Ruby on Rails ~/rails
- cd to ~/rails
- 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…
@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:
/opt/homebrew/lib/ruby/gems/3.1.0/bin
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: