How to have multiple versions of Ruby AND Rails, and their combinations on Windows?
Use uru. It is a multi-platform ruby environment manager. You can download the Windows version here: https://bitbucket.org/jonforums/uru/wiki/Downloads
Install the tool
Assuming C:\tools
is on PATH and uru_rt.exe
was extracted to C:\tools
C:\tools>uru_rt admin install
This adds uru.bat
file to the tools directory.
Register ruby
uru admin add C:\ruby200\bin
List available rubies
uru ls174 : 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
uru 174---> Now using jruby 1.7.4 tagged as `174`
More commands can be found here: https://bitbucket.org/jonforums/uru/wiki/Examples
Old answer
I use Pik to manage multiple versions of ruby on a Windows machine.
Install the pik gem
> gem install pikSuccessfully installed pik-0.2.61 gem installed
Install pik to a location that’s in your path, but someplace other than your ruby\bin dir.
>echo %path%PATH=c:\pik;c:\ruby\Ruby187\bin;>pik_install C:\pikThank you for using pik.Installing to C:\pikpik is installed
Install Ruby 1.9.2 using RubyInstaller and add the new Ruby version to pik
registry.
>pik add C:\Ruby192\bin
List the available Ruby versions:
>pik list187: 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:
>pik 192>pik list187: 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:
In Rails 2.x, set the RAILS_GEM_VERSION in config/environment.rb
file:
RAILS_GEM_VERSION = '= 2.3.8' unless defined? RAILS_GEM_VERSION
In rails 3, use the Gemfile
to specify the Rails version:
gem "rails", "3.0.0"
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.
@echo offecho 1 - Ruby 1.9.3echo 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 confusedif errorlevel 3 goto 3if errorlevel 2 goto 2if errorlevel 1 goto 1if errorlevel 0 goto 0goto confused:1if exist c:\ruby rmdir c:\rubyif exist c:\devkit rmdir c:\devkitmklink /j c:\ruby c:\ruby193mklink /j c:\devkit c:\devkit-4.5.2goto end:2if exist c:\ruby rmdir c:\rubyif exist c:\devkit rmdir c:\devkitmklink /j c:\ruby c:\ruby2-x86mklink /j c:\devkit c:\devkit-x64goto end:3if exist c:\ruby rmdir c:\rubyif exist c:\devkit rmdir c:\devkitmklink /j c:\ruby c:\ruby2-x64mklink /j c:\devkit c:\devkit-x64goto end:confusedecho I'm confused ...:endruby -v
From what I could tell, uru only manages versions of 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:
rails _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:
Gemfile.lock