简体   繁体   English

Rails没有使用我的全局Ruby版本

[英]Rails is not using my global Ruby version

I want to use Rails with Ruby 2.1.0, but it's using Ruby 1.9.3 (the system's version). 我想在Ruby 2.1.0中使用Rails,但它使用的是Ruby 1.9.3(系统版本)。

I'm using rbenv to manage my Ruby versions. 我正在使用rbenv来管理我的Ruby版本。 My steps were something along the lines of: 我的步骤是:

$ rbenv install 2.1.0
$ rbenv global 2.1.0
$ sudo gem install rails -v 4.0.2
$ rbenv rehash
$ rbenv versions
  system
* 2.1.0 (set by /home/dennis/.rbenv/version)
$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
$ rails new app && cd app
$ rails server

Rails is using is Ruby 1.9.3 (x86_64-linux), according to localhost:3000/rails/info/properties . 根据localhost:3000/rails/info/properties ,Rails使用的是Ruby 1.9.3(x86_64-linux)。 A log message from rails server gives: INFO ruby 1.9.3 (2012-04-20) [x86_64-linux] . 来自rails server日志消息给出: INFO ruby 1.9.3 (2012-04-20) [x86_64-linux]

I think Rails is using the system version of Ruby because the versions match. 我认为Rails使用的是Ruby的系统版本,因为版本匹配。

$ rbenv local system
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ rbenv local --unset  # Unset local Ruby version, go back to 2.1.0

Some things I've tried with no luck: 有些事情我试过没有运气:

  • setting the local and shell versions of Ruby to 2.1.0 with rbenv 使用rbenv将Ruby的本地和shell版本设置为2.1.0
  • rehash rbenv shims (rbenv says to do this after installing executables) rehash rbenv shims(rbenv说安装可执行文件后执行此操作)
  • made new Rails projects after switching to 2.1.0 just in case I made the projects while using 1.9.3 切换到2.1.0之后制作了新的Rails项目,以防我在使用1.9.3时制作项目
  • putting 2.1.0 in a .ruby-version file in the root of my project (suggested by @Agis) 2.1.0放在项目根目录中的.ruby-version文件中(由@Agis建议)
  • restarting terminal session and starting a login bash shell (suggested by @Russel) 重启终端会话并启动登录bash shell(由@Russel建议)
  • specifying the desired Ruby version in the project's Gemfile (suggested by @rlecaro2) 在项目的Gemfile中指定所需的Ruby版本(由@ rlecaro2建议)

FWIW, I'm using Ubuntu 13.10 with the fish shell. FWIW,我正在使用带有鱼壳的Ubuntu 13.10。

Sounds silly, but did you restart terminal session? 听起来很傻,但你重启终端会话了吗?

Otherwise try and type 否则尝试输入

 /bin/bash --login

You didn't tell how you installed rbenv , but I think it is per-user installation (which is default). 您没有告诉您如何安装rbenv ,但我认为这是每用户安装(默认情况下)。 In this case you should install gems without using sudo . 在这种情况下,您应该在不使用sudo情况下安装gem。 When you did sudo gem install rails , it was installed in system ruby, not rbenv's selected one. 当你做了sudo gem install rails ,它安装在系统ruby中,而不是rbenv的选择。

Solution - install rails without sudo: 解决方案 - 安装没有sudo的rails:

rbenv global 2.1.0
gem install rails
rbenv rehash

尝试使用以下内容在项目的根目录中创建.ruby-version文件:

2.1.0

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

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