简体   繁体   English

运行 Rails--version 时,它一直识别旧的 Ruby 版本,不让我检查版本

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

I'm trying to download rails onto my computer, and so the general version that it has is the following:我正在尝试将 rails 下载到我的计算机上,因此它的通用版本如下:

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.但是,我一直在尝试更改它并下载了 rbenv,并将全局版本更改为 3.1.2p20。 It has downloaded rails successfully with the following output:它已使用以下 output 成功下载了 rails:

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.但是,当我运行rails --version时,它给了我错误:`Rails 7 需要 Ruby 2.7.0 或更高版本。

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?我该如何解决?

Maybe you are just using ruby 2.6.8 as your global version.也许您只是使用 ruby 2.6.8 作为您的全球版本。 So you need to use ruby 2.7.0 as your global version or you can just use it in your current project.所以你需要使用 ruby 2.7.0 作为你的全局版本,或者你可以在你当前的项目中使用它。

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.您应该能够看到 ruby 2.7.0 安装在其他版本中。 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:并将其设置为您的全局 ruby 版本,您需要执行以下操作:

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.它已经下载了 rails,但不是从(更新的)rbenv 版本的 ruby 下载的。 When in doubt, run which ruby to check the path of your ruby installation.如有疑问,请运行which ruby以检查 ruby 安装的路径。 If shims isn't present in the path, then you are very probably still using your OS's native ruby.如果路径中不存在shims ,那么您很可能仍在使用操作系统的本机 ruby。

If that is the case, then your terminal isn't initializing rbenv on new shell sessions.如果是这种情况,那么您的终端不会在新的 shell 会话上初始化 rbenv。 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.您可能忘记将 rbenv 的评估添加到您的 shell 的源文件(如~/.bash_profile~/.bashrc~/.zshrc等),每个新的 shell session 和您应该放置配置的文件都会被解释、别名、快捷方式和其他自定义。

These are instructions for Mac , these for Debian-based Linux Distros .这些是Mac的说明,这些是基于 Debian 的 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.切换到rvm而不是rbenv对我有用。 Gotta make sure to call unset GEM_HOME and remove export GEM_HOME="$HOME/.gem" from bash profile.必须确保调用unset GEM_HOME并从 bash 配置文件中删除export GEM_HOME="$HOME/.gem"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM