简体   繁体   English

如何从RVM配置文件中指定要在Heroku上使用的ruby版本

[英]How can I specify the ruby version to use on Heroku from the RVM configuration files

I'd like to use a specific version of ruby when running my app in production on Heroku. 我想在Heroku上运行我的应用程序时使用特定版本的ruby。

As explained here , you only have to add a line like ruby "2.0.0" in your Gemfile. 正如解释在这里 ,你只需要添加一行ruby "2.0.0"在你的Gemfile。

However, as I use RVM locally, I already specified the ruby version to use in a .ruby-version file in the root directory of the project that only contains the line ruby-2.0.0-p0 . 但是,当我在本地使用RVM时,我已经在项目的根目录中的.ruby-version文件中指定了ruby版本,该文件只包含ruby-2.0.0-p0

To avoid code duplication, I'd like the version to be specified in only one place, so that I'm sure that the same version is always used in development and on Heroku. 为了避免代码重复,我希望只在一个地方指定版本,以便我确信在开发和Heroku中总是使用相同的版本。

Is there a way to do that ? 有没有办法做到这一点 ?

The Gemfile is ruby code, so you can write some ruby to read the version from .ruby-version and pass that value to the ruby method, rather than a hard-coded version string. Gemfile是ruby代码,因此您可以编写一些ruby来读取.ruby-version并将该值传递给ruby方法,而不是硬编码的版本字符串。

If the .ruby-version file is in the same directory, something like this should work: 如果.ruby-version文件位于同一目录中,那么这样的东西应该有效:

ruby File.read(".ruby-version").strip.split("-").first

If the .ruby-version file contains "1.9.3-p327", for example, that line would be equivalent to: 例如,如果.ruby-version文件包含“1.9.3-p327”,那么该行将等效于:

ruby "1.9.3"

No, you can't specify the patch level to be used on Heroku - they manage patch levels for you. 不,您无法指定要在Heroku上使用的补丁级别 - 它们可以为您管理补丁级别。 You need to track their changelog to know when patch levels change. 您需要跟踪其更改日志以了解修补程序级别何时更改。 So you need to make sure you are using the same patch level locally which for Ruby 2.0.0 it's present p195. 因此,您需要确保在本地使用相同的补丁级别,对于Ruby 2.0.0,它存在于p195。

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

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