Introduction
I want to work on my Windows machine without installing all stuff with native ruby (compiler etc…).
Prerequisites
-
java only a jre is necessary
Download JRuby
Download the lastest zip archive of jruby
Uncompress it into any folder
Launch ruby
On dos command prompt, set PATH and create a alias for ruby=jruby.
@rem set JAVA_HOME if you want
@rem set JAVA_HOME=xxx
@rem where jruby was installed
set JRUBY_PATH=xxx
set PATH=%JRUBY_HOME%\bin;%JAVA_HOME%\bin;%PATH%
@rem create alias for ruby
doskey doskey ruby=jruby
on powershell, set PATH and create alias
$env:JAVA_HOME="xxx"
$env:JRUBY_HOME="xxx"
$env:PATH="${env:JRUBY_HOME}\bin;${env:JAVA_HOME}\bin;${env:path}"
New-alias ruby "$(resolve-path $env:JRUBY_HOME)\bin\jruby"
New-alias gem "$(resolve-path $env:JRUBY_HOME)\bin\gem"
New-alias irb "$(resolve-path $env:JRUBY_HOME)\bin\irb"
Rubyenv.bat
I have created a batch file to easily launch a ruby environment.
Download it on my gist (rubyenv.bat).
Create a rubyenv.ini on the same folder: * you need to indicate the path where java is installed (JAVA_HOME) if you must specify a particular jre. * you need to indicate the path where jruby was uncompressed (JRUBY_HOME) * you can specify a working dir if you want * you can modify the command prompt you want to use (cmd, powershell,etc..)
With rubyenv you can launch a one-liner script ruby
> rubyenv ruby -e "puts 'Hello'"
Hello
You can so launch a ruby environment
> rubyenv
> ruby -e "puts 'Hello'"
Hello
Associate rb file
If you want to associate the rb file to launch directly, you must indicate these commands with administrator rights
@rem Indicate jruby_home to simplify command
set JRUBY_HOME=D:\DEV\devRuby\jruby-9.1.7.0
@rem create a entry for rb file
assoc .rb=rbfile
@rem associate command with rbfile
ftype rbfile=%JRUBY_HOME%\bin\jruby "%1" %*
@rem associate jruby icon with rbfile
reg add "HKEY_CLASSES_ROOT\rbfile\defaultIcon" /ve /d "%JRUBY_HOME%\bin\jrubyw.exe,0"
If you want to unassociate rb files
assoc .rb=nothing
ftype rbfile=
reg delete "HKEY_CLASSES_ROOT\rbfile\defaultIcon" /f
these solutions doesn’t force JAVA_HOME. You can use rubyenv.bat with /assoc and /unassoc. |