简体   繁体   English

为什么Rails无法识别新安装的Ruby版本?

[英]Why is Rails not recognizing newly installed version of Ruby?

I have recently installed ruby 2.5.1 seemingly successfully, however when I type the command ruby -v into the "Command Prompt with ruby and rails" it returns the old value of 2.2.6. 我最近似乎已经成功安装了ruby 2.5.1,但是当我在“带有ruby和rails的命令提示符”中键入命令ruby -v ,它将返回旧值2.2.6。 The strange thing is that when i type ruby -v into the normal Command prompt it returns the newly installed version 2.5.1. 奇怪的是,当我在常规命令提示符下键入ruby -v ,它将返回新安装的版本2.5.1。

I feel that I must change the configuration of the Rails environment somehow. 我觉得我必须以某种方式更改Rails环境的配置。

when I open the "command prompt with ruby and rails" it shows the following configuration 当我打开“使用ruby和rails的命令提示符”时,它显示以下配置

git:
  user.name:  USER_NAME_HERE
  user.email: EMAIL@********.com
  version:    git version 1.9.4.msysgit.2

ruby:
  bin:        C:/RailsInstaller/Ruby2.0.0/bin/ruby.exe
  version:    ruby 2.2.6p396 (2016-11-15 revision 56800) [i386-mingw32]

rails:
  bin:        C:/RailsInstaller/Ruby2.0.0/bin/rails.bat
  version:    Rails 5.1.6

How do I get Rails to recognize the newly installed version of ruby? 如何让Rails识别新安装的ruby版本?

RailsInstaller is hard coded to the version of Ruby it installs. RailsInstaller硬编码为它所安装的Ruby版本。 You can see this is the lines Ruby: bin and version. 您可以看到这是Ruby:bin和version行。 You probably installed Ruby 2.5 somewhere else. 您可能在其他地方安装了Ruby 2.5。 There are two approaches you can take 您可以采取两种方法

  • Before anything! 之前! Backup the RailsInstaller and Sites folders!!!! 备份RailsInstaller和Sites文件夹!!!! REALLY! 真!
  • Adjust the RailsInstaller scripts to point to your new Ruby 调整RailsInstaller脚本以指向您的新Ruby
  • Overwrite the older Ruby with the newer one and adjust the scripts where paths are different. 用较新的Ruby覆盖较旧的Ruby,并在路径不同的地方调整脚本。

The key file is C:\\RailsInstaller\\Rubyx.xx\\setup_environment.bat 密钥文件是C:\\ RailsInstaller \\ Rubyx.xx \\ setup_environment.bat

I suspect the key line (near line 11) is 我怀疑关键线(11号线附近)是

SET RUBY_DIR=%CD% SET RUBY_DIR =%CD%

I think that if this is changed to the path of the Ruby you want to use, operation will shift to that version. 认为 ,如果将其更改为要使用的Ruby的路径,则操作将转移到该版本。 Might also need to change 可能还需要改变

SET ROOT_DIR=%CD% SET ROOT_DIR =%CD%

To point to the RailsInstaller main folder. 指向RailsInstaller主文件夹。

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

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