如何在 Windows 上拥有多个版本的 Ruby AND Rails 及其组合?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3648744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to have multiple versions of Ruby AND Rails, and their combinations on Windows?
提问by nonopolarity
Since Windows doesn't support rvm (Ruby version Manager), how do we have
由于 Windows 不支持 rvm(Ruby 版本管理器),我们如何拥有
- Ruby 1.8.7, Rails 2.3.8
- Ruby 1.8.7, Rails 3.0.0
- Ruby 1.9.2, Rails 3.0.0
- 红宝石 1.8.7,Rails 2.3.8
- 红宝石 1.8.7,Rails 3.0.0
- 红宝石 1.9.2,Rails 3.0.0
on the same PC? Virtual machines can be used but it is kind of troublesome.
在同一台电脑上?可以使用虚拟机,但是有点麻烦。
回答by Harish Shetty
Use uru. It is a multi-platform ruby environment manager. You can download the Windows version here: https://bitbucket.org/jonforums/uru/wiki/Downloads
使用uru。它是一个多平台的 ruby 环境管理器。你可以在这里下载 Windows 版本:https: //bitbucket.org/jonforums/uru/wiki/Downloads
Install the tool
安装工具
Assuming C:\toolsis on PATH and uru_rt.exewas extracted to C:\tools
假设C:\tools在 PATH 上uru_rt.exe并被提取到C:\tools
C:\tools>uru_rt admin install
This adds uru.batfile to the tools directory.
这会将uru.bat文件添加到工具目录。
Register ruby
注册红宝石
uru admin add C:\ruby200\bin
List available rubies
列出可用的红宝石
uru ls
174 : jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM)
200p255 : ruby 2.0.0p255 (2013-07-07 revision 41812) [i686-linux]
=> system : ruby 2.1.0dev (2013-07-06 trunk 41808) [i686-linux]
Switch ruby version
切换 ruby 版本
uru 174
---> Now using jruby 1.7.4 tagged as `174`
More commands can be found here: https://bitbucket.org/jonforums/uru/wiki/Examples
更多命令可以在这里找到:https: //bitbucket.org/jonforums/uru/wiki/Examples
Old answer
旧答案
I use Pikto manage multiple versions of ruby on a Windows machine.
我使用Pik在 Windows 机器上管理多个版本的 ruby。
Install the pik gem
安装pik gem
> gem install pik
Successfully installed pik-0.2.6
1 gem installed
Install pik to a location that's in your path, but someplace other than your ruby\bin dir.
将 pik 安装到您路径中的某个位置,但不是您的 ruby\bin 目录。
>echo %path%
PATH=c:\pik;c:\ruby\Ruby187\bin;
>pik_install C:\pik
Thank you for using pik.
Installing to C:\pik
pik is installed
Install Rubt 1.9.2 using RubyInstaller and add the new Ruby version to pikregistry.
使用 RubyInstaller 安装 Rubt 1.9.2 并将新的 Ruby 版本添加到pik注册表。
>pik add C:\Ruby192\bin
List the available Ruby versions:
列出可用的 Ruby 版本:
>pik list
187: ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32] *
192: ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
To switch to Ruby 1.9.2:
切换到 Ruby 1.9.2:
>pik 192
>pik list
187: ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]
192: ruby 1.9.2p0 (2010-08-18) [i386-mingw32] *
To switch between different versions of Rails:
在不同版本的 Rails 之间切换:
In Rails 2.x, set the RAILS_GEM_VERSION in config/environment.rbfile:
在 Rails 2.x 中,在config/environment.rb文件中设置 RAILS_GEM_VERSION :
RAILS_GEM_VERSION = '= 2.3.8' unless defined? RAILS_GEM_VERSION
In rails 3, use the Gemfileto specify the Rails version:
在 rails 3 中,使用Gemfile来指定 Rails 版本:
gem "rails", "3.0.0"
回答by Steffen Roller
I wrote myself a little batch file which creates a junction (aka symlinks) on the NTFS.
The idea is to keep the PATH untouched. The path always contains c:\devkit\bin;c:\ruby\bin;.... The following Batch file changes the links to the actual directories.
我自己写了一个小批处理文件,它在 NTFS 上创建了一个结点(又名符号链接)。这个想法是保持 PATH 不变。路径始终包含c:\devkit\bin;c:\ruby\bin;.... 以下批处理文件更改了指向实际目录的链接。
@echo off
echo 1 - Ruby 1.9.3
echo 2 - Ruby 2.0.0 (32 bit)
echo 3 - Ruby 2.0.0 (64 bit)
choice /C 123 /M "Which Ruby? "
if errorlevel 255 goto confused
if errorlevel 3 goto 3
if errorlevel 2 goto 2
if errorlevel 1 goto 1
if errorlevel 0 goto 0
goto confused
:1
if exist c:\ruby rmdir c:\ruby
if exist c:\devkit rmdir c:\devkit
mklink /j c:\ruby c:\ruby193
mklink /j c:\devkit c:\devkit-4.5.2
goto end
:2
if exist c:\ruby rmdir c:\ruby
if exist c:\devkit rmdir c:\devkit
mklink /j c:\ruby c:\ruby2-x86
mklink /j c:\devkit c:\devkit-x64
goto end
:3
if exist c:\ruby rmdir c:\ruby
if exist c:\devkit rmdir c:\devkit
mklink /j c:\ruby c:\ruby2-x64
mklink /j c:\devkit c:\devkit-x64
goto end
:confused
echo I'm confused ...
:end
ruby -v
回答by space2earth
From what I could tell, uru only manages versions of RUBY.
据我所知, uru 只管理 RUBY 的版本。
For versions of RAILS, where you've already 2 or more versions on your local maching, to open a project in one's development environment, using an older version of rails, you enter the following in the command window:
对于本地机器上已经有 2 个或更多版本的 RAILS 版本,要在开发环境中使用旧版本的 rails 打开项目,请在命令窗口中输入以下内容:
rails _3.2.11_ s
轨道_3.2.11_s
where 3.2.11 represents the version of RAILS you want it to use, which you want to be the same version as listed in your project's file:
其中 3.2.11 表示您希望它使用的 RAILS 版本,您希望该版本与项目文件中列出的版本相同:
Gemfile.lock
Gemfile.lock
回答by Rajkaran Mishra
After installing and registering all your ruby installations with uru, you'll need to install DevKitfor each of the ruby versions installed. For installation follow these instructions.
使用uru安装和注册所有 ruby 安装后,您需要为每个安装的 ruby 版本安装DevKit。按照这些说明进行安装。
I generally store the DevKit next to the version of Ruby to which it belongs, for example, C:\Ruby\Ruby193\DevKitwhere Ruby193 is the folder containing the 193 version of Ruby that I registered with uru.
我通常将 DevKit 存储在它所属的 Ruby 版本旁边,例如,C:\Ruby\Ruby193\DevKit其中 Ruby193 是包含我注册的 193 版本 Ruby 的文件夹uru。

