When Running Rails--version, it keeps recognizing old Ruby version and not letting me check version

Viewed 579

I'm trying to download rails onto my computer, and so the general version that it has is the following:

ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]

However, I keep trying to change it and have downloaded rbenv, and changed the global version to 3.1.2p20. It has downloaded rails successfully with the following output:

Successfully installed rails-7.0.3 Parsing documentation for rails-7.0.3 Done installing documentation for rails after 0 seconds 1 gem installed

However, when I run rails --version it gives me the error: `Rails 7 requires Ruby 2.7.0 or newer.

You're running
  ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]

Please upgrade to Ruby 2.7.0 or newer to continue.`

How do I fix this?

3 Answers

Maybe you are just using ruby 2.6.8 as your global version. So you need to use ruby 2.7.0 as your global version or you can just use it in your current project.

First, check if it's installed

rbenv versions

you should be able to see that ruby 2.7.0 is installed among the other versions. If not, you can install it by doing the following:

rbenv install 2.7.0

And to set it as your global ruby version, you need to do:

rbenv global 2.7.0

or you can use it locally in the project by moving to your project directory and doing the following:

rbenv local 2.7.0

It has downloaded rails, but not from the (newer) rbenv version of ruby. When in doubt, run which ruby to check the path of your ruby installation. If shims isn't present in the path, then you are very probably still using your OS's native ruby.

If that is the case, then your terminal isn't initializing rbenv on new shell sessions. You likely forgot to add rbenv's evaluation to your shell's source file (like ~/.bash_profile, ~/.bashrc, ~/.zshrc, etc), the one which is interpreted at each new shell session and which you are supposed to place configurations, aliases, shortcuts and other customizations.

These are instructions for Mac, these for Debian-based Linux Distros. Review the steps immediately after installation, which mention the files greyed out in this answer's second paragraph.

Switching to rvm instead of rbenv worked for me. Gotta make sure to call unset GEM_HOME and remove export GEM_HOME="$HOME/.gem" from bash profile.

Related