简体   繁体   English

带有rbenv的多个Rails应用和Ruby版本

[英]Multiple Rails apps and Ruby versions with rbenv

I have multiple Rails apps from 3.2.14 to 3.2.18 in my development environment. 我的开发环境中有从3.2.14到3.2.18的多个Rails应用程序。 I'm using Ruby 1.9.3 (yes, I know) for these apps and it's installed and managed via rbenv. 我正在为这些应用程序使用Ruby 1.9.3(是的,我知道),并且它是通过rbenv安装和管理的。 I'm about to build a couple of new apps with Rails 4.1 and Ruby 2.1. 我将使用Rails 4.1和Ruby 2.1构建几个新应用。 My question is, what is the best way to handle installing multiple versions of Ruby using rbenv. 我的问题是,使用rbenv处理多个版本的Ruby的最佳方法是什么。 Currently 1.9.3 is set to global, but I want different Rails apps (4.1) to use Ruby 2.1. 当前1.9.3设置为global,但是我希望其他Rails应用程序(4.1)使用Ruby 2.1。

I guess I'm a bit behind the curve with Ruby management so I could use a hand here. 我想我在Ruby管理方面落后了一些,所以我可以在这里帮忙。 Again, looking to have multiple Rails apps (different versions 3.2.14-4.1.x) and multiple Ruby instances to support each app. 同样,希望拥有多个Rails应用程序(不同版本3.2.14-4.1.x)和多个Ruby实例来支持每个应用程序。

I appreciate the help in advance. 我先感谢您的帮助。

Create a .ruby-version file in your application root directory and specify the ruby version you want. 在应用程序根目录中创建一个.ruby-version文件,并指定所需的红宝石版本。 For instance, if you want one application to use 1.9.3 and the other 2.1.0, you'll have a .ruby-version file each in those two applications, specifying the version: 例如,如果您希望一个应用程序使用1.9.3,而另一个使用2.1.0,则在这两个应用程序中每个都有一个.ruby-version文件,并指定版本:

/application1/.ruby-version
1.9.3

/application2/.ruby-version
2.1.0

Update 更新资料

不同的Ruby / Gem版本

For every installed version of ruby, you'll have a shims directory which will house all your gems for that particular version. 对于每个已安装的ruby版本,您将有一个shims目录,该目录将存放该特定版本的所有宝石。 When you switch between ruby versions, rbenv will simply set the environment variables to the one you select. 在红宝石版本之间切换时,rbenv只需将环境变量设置为您选择的环境变量。

In the example above, I set the local ruby version for the directory ruby_cookbook to 2.1.2 and a gem list will only show gems installed for 2.1.2. 在上面的示例中,我将目录ruby_cookbook的本地ruby版本设置为2.1.2,并且gem list将仅显示为2.1.2安装的gem。

I also created a .ruby-version with ruby version 1.9.3-p547 in my try_stuff directory. 我还创建了一个.ruby-version在我的红宝石版本1.9.3-p547 try_stuff目录。 As you can see, gem list only shows gems installed for 1.9.3. 如您所见,gem列表仅显示为1.9.3安装的gem。

The gems you install are specific to the current version of ruby. 您安装的宝石特定于当前版本的ruby。

If your project root has a .ruby-version file, your environment will automatically set the current ruby version to the one specified. 如果项目根目录具有.ruby-version文件,则您的环境将自动将当前的ruby版本设置为指定的版本。 So, yes, your production environment will need the version you mention in your .ruby-version . 因此,是的,您的生产环境将需要您在.ruby-version提到.ruby-version If you use git for source control, you can add that file to your .git-ignore and you won't see it in your prod version. 如果使用git进行源代码控制,则可以将该文件添加到.git-ignore中,而您的prod版本中将看不到该文件。

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

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