简体   繁体   English

升级Ruby版本和Rails兼容性

[英]Upgrading Ruby version And Rails Compatibility

Hi guys I wonder if someone could explain the problem I'm having so that I can understand whats going on. 嗨,大家好,我想知道是否有人可以解释我遇到的问题,以便我能理解最新情况。

I am currently running ruby 2.2.2 and rails 5. I have a small test app and all is working fine. 我目前正在运行ruby 2.2.2和rails 5.我有一个小测试应用程序,一切正常。 I decided to upgrade ruby to version 2.4.0, for no other reason than I think I should know how to do it and the resulting pitfalls etc, so a learning exercise. 我决定将ruby升级到版本2.4.0,除了我认为我应该知道如何做以及由此产生的陷阱等,没有其他原因,所以这是一个学习练习。

After updating ruby to 2.4.0 which goes fine the command rails -v returns rails not installed. 将ruby更新到2.4.0之后,命令rails -v返回未安装的rails。 If i then revert to the older ruby 2.2.2 rvm use ruby-2.2.2 run rails -v then rails 5.0.1 is returned. 如果我然后恢复到旧的ruby 2.2.2 rvm use ruby-2.2.2运行rails -v然后返回rails 5.0.1。 Whats happening here? 这里发生了什么事?

Thanks 谢谢

RVM gives you a separate gem directory for each and every Ruby version and gemset. RVM为每个Ruby版本和gemset提供单独的gem目录。 This means that gems must be explicitly installed for each revision and gemset. 这意味着必须为每个修订版和gemset显式安装gem。 Usually the migration process is as follows: 通常迁移过程如下:

rvm use ruby-2.4.0 
# or `rvm --default use ruby-2.4.0` if you want to use 2.4.0 from now on
gem install rails -v 5.0.1 # an example, use any version you like
gem install bundler
bundle install # to install all other project gems

See the RVM gemsets documentation page . 请参阅RVM gemsets文档页面

Extending @Slava.K 's answer 扩展@ Slava.K的答案

I have a small test app and all is working fine. 我有一个小测试应用程序,一切正常。 I decided to upgrade ruby to version 2.4.0, for no other reason than I think I should know how to do it and the resulting pitfalls etc, so a learning exercise. 我决定将ruby升级到版本2.4.0,除了我认为我应该知道如何做以及由此产生的陷阱等,没有其他原因,所以这是一个学习练习。

  • When you upgrade ruby to 2.4.0, this becomes your new ruby version number, thus you won't have any reference to rails and bundler . 当您将ruby升级到2.4.0时,这将成为您的新ruby版本号,因此您将不会引用railsbundler
  • You would need to do gem install rails -v xxx and gem install bundler . 你需要做gem install rails -v xxxgem install bundler
  • Now when you do rails -v , this will print a version number of the installed rails for your given Ruby. 现在当你执行rails -v ,这将打印给定Ruby的已安装rails的版本号。

After updating ruby to 2.4.0 which goes fine the command rails -v returns rails not installed. 将ruby更新到2.4.0之后,命令rails -v返回未安装的rails。 If i then revert to the older ruby 2.2.2 rvm use ruby-2.2.2 run rails -v then rails 5.0.1 is returned. 如果我然后恢复到旧的ruby 2.2.2 rvm使用ruby-2.2.2运行rails -v然后返回rails 5.0.1。 Whats happening here? 这里发生了什么事?

  • As I have mentioned above already, installing rails is imperative when you upgrade Ruby. 正如我上面已经提到的,升级Ruby时必须安装rails。 So no rails installed, no version number to display 因此没有安装rails,也没有要显示的版本号

  • gem env home => ../versions/jruby-1.7.12/lib/ruby/gems/shared gem env home => ../versions/jruby-1.7.12/lib/ruby/gems/shared
    • Will show you the location of installed the gems. 将显示安装宝石的位置。
  • I perefer to use rbenv over rvm 我倾向于使用rbenv而不是rvm

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

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