简体   繁体   English

如何在Heroku上选择Ruby版本?

[英]How can I choose Ruby version on Heroku?

I use Ruby 1.9.x syntax in my Rails 3 app, but after pushing it to Heroku it crashes due to older Ruby version (1.8). 我在我的Rails 3应用程序中使用了Ruby 1.9.x语法,但在将其推送到Heroku后,由于旧的Ruby版本(1.8)而崩溃。 How can I control it? 我该如何控制它?

Heroku's current stack, Cedar, uses 1.9.2 by default. Heroku目前的堆栈Cedar默认使用1.9.2。 Cedar also supports specifying the Ruby version in your Gemfile . Cedar还支持在Gemfile中指定Ruby版本 Currently, 1.9.2 and 1.9.3 are valid options . 目前, 1.9.2和1.9.3是有效选项

# Gemfile
source "https://rubygems.org"
ruby "1.9.3"
...

More details are available in the Ruby support article: https://devcenter.heroku.com/articles/ruby-support 有关更多详细信息,请参阅Ruby支持文章: https//devcenter.heroku.com/articles/ruby-support


If you are currently using Aspen or Bamboo, you can switch to 1.9.2 by using the stack:migrate command: 如果您当前正在使用Aspen或Bamboo,则可以使用stack:migrate命令切换到1.9.2:

$ heroku stack:migrate bamboo-mri-1.9.2

You cannot automatically migrate to the Cedar stack at this time, but there is a guide on how to do so: https://devcenter.heroku.com/articles/cedar-migration 您目前无法自动迁移到Cedar堆栈,但有关于如何执行此操作的指南: https//devcenter.heroku.com/articles/cedar-migration

You can now explicitly specify a Ruby version on Heroku . 您现在可以在Heroku上显式指定Ruby版本

Simply setup your Gemfile as so 只需设置您的Gemfile

# Gemfile
source "https://rubygems.org"
ruby "1.9.3"

# Gems go here

I wanted to use the version I already had defined in the .ruby-version file so I ended up creating a buildpack that can be used before heroku-buildpack-ruby that injects the version from the .ruby-version into the Gemfile . 我想使用我已经在.ruby-version文件中定义.ruby-version所以我最终创建了一个buildpack,可以在heroku-buildpack-ruby之前使用,它将.ruby-version中的版本注入到Gemfile It also support versions without patch or aliases. 它还支持没有补丁或别名的版本。

https://github.com/platanus/heroku-buildpack-ruby-version https://github.com/platanus/heroku-buildpack-ruby-version

This way you can have your version defined only in one place. 这样,您只能在一个地方定义您的版本。

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

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