Вы находитесь на странице: 1из 4

Building Ruby | Devkit

Pik
Up to now we were managing multiple versions of Ruby through Console2s tabs. Even though we can use different Ruby versions in Console2s
tabs this approach has few drawbacks. Testing scripts or running existing applications that require specific Ruby version require opening new
or changing to specific tab. Adding new Ruby version is somewhat complex and soon we might finish up with too many different tabs in
Console2 so it would be hard to remember which tab corresponds to particular Ruby version. Especially if we decide to install other Rubies
besides MRI, like JRuby or IronRuby.
At the moment we have two versions of Ruby on our system. The first one is official 1.9.2p136 and the second one is the latest development
version. Since we have used installer for the 1.9.2 and have chosen to add it to the path, in each Command Prompt we open it will be the
only one available unless we add the path to the development version to the system path. So we have to choose either to use Ruby in
Console2s tabs or to constantly alter system path in order to change Ruby version we work with. This certainly is not the most comfortable
way and, fortunately, there is a much better solution Pik.
Pik gem is Ruby extension for managing multiple Ruby versions on Windows system. It is installed as any other Ruby gem. Open new Command
Prompt window (not Console2) and execute following command:
C:\>gem install pik
----------------------------------------------------------------------------
* If you're upgrading from a version <= 0.1.1, you'll want to delete the pik.bat
file from all of your ruby versions. Gem uninstall should do the trick.
* Install pik to a location that's in your path, but someplace other than your
ruby\bin dir If you're upgrading from a more recent version, pik_install will
overwrite the older files as needed.
>path
PATH=C:\tools\;C:\ruby\186-p368-mingw32\bin;C:\WINDOWS\system32;C:\WINDOWS
>pik_install C:\tools
* If this is a first-time install, add all the versions of ruby that you want to
use with pik
>pik add
Adding: 186: ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]
Located at: c:/ruby/186-p368-mingw32/bin
>pik add C:\ruby\IronRuby-091\bin
Adding: 091: IronRuby 0.9.1.0 on .NET 2.0.0.0
Located at: C:/ruby/IronRuby-091/bin
>pik add C:\ruby\jruby-1.4.0RC1\bin
Adding: 140: jruby 1.4.0RC1 (ruby 1.8.7 patchlevel 174) (2009-09-30 80c263b)
(Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]
Located at: C:/ruby/jruby-1.4.0RC1/bin
----------------------------------------------------------------------------
Successfully installed pik-0.2.8
1 gem installed
Installing ri documentation for pik-0.2.8...
Installing RDoc documentation for pik-0.2.8...
Command is executed in the new Command Prompt where the only Ruby available, at the moment, is 1.9.2, therefore gem will be installed in
it. Lets check that:
C:\>gem list
*** LOCAL GEMS ***
minitest (1.6.0)
pik (0.2.8)
rake (0.8.7)
rdoc (2.5.8)
As you can see Pik is available in the list of gems currently available to the default Ruby. But where other gems come from when we didnt
install it? They are bundled with Ruby and are available with Ruby installation.
It is time to finalize Pik installation. Comments displayed after gem is installed are self-explanatory but lets analyze them. We are not
upgrading Pik so we can skip the first one. The second one states that we must use pik_install command in order to install Pik, and we should
pass it, as argument, some directory that is in the path. It is recommended to avoid our ruby\bin directory.
Currently our path contains directories added during Windows installation, directory where Git is installed and, finally, bin directory of our Ruby
1.9.2 version. Since I like to keep things clear we will create new directory which we will use when we launch pik_install command. Well follow
Piks suggestion and create C:\tools directory. Before calling pik_install we must add new directory to the path.
Click on the Start button, right-click on the Computer and click on the Properties menu item in the context-menu. New window with basic
information about your computer opens. On the left side of window click on the Advanced system settings link and in dialog box that pops up
click on Environment variables... button. In the list of users variables you should see Path variable set to the bin directory of our installed
Ruby. Double click on it and at the end of value add:
;C:\tools
Do not forget to type semicolon (;) before tools directory path. Click on OK buttons three times and close System window. You must close all
Command Prompt windows and open new one, since changes made to Path variable will not be available in Command Prompt windows that
were opened while we were changing it. We have prepared everything needed for Pik and we are ready to go on.
C:\>pik_install C:\tools
Thank you for using pik.
mkdir -p C:\tools
mkdir -p C:\Users\bosko/.pik
Installing to C:\tools
Pik 6/7/2014
http://rubyonwindowsguides.github.io/book/ch02-03.html 1 / 4
cp c:/Ruby/192/lib/ruby/gems/1.9.1/gems/pik-0.2.8/tools/pik_runner.exe C:\tools
cp c:/Ruby/192/lib/ruby/gems/1.9.1/gems/pik-0.2.8/tools/pik.bat C:\tools
cp c:/Ruby/192/lib/ruby/gems/1.9.1/gems/pik-0.2.8/tools/pik.ps1 C:\tools
creating C:\Users\bosko/.pik/.pikrc
pik is installed
if you want to use pik with git bash, add the following line to your ~/.bashrc:
[[ -s $USERPROFILE/.pik/.pikrc ]] && source $USERPROFILE/.pik/.pikrc
As a good behaved tool, Pik displays everything it did during installation. First it created directory where it installed its files, C:\tools in our
case. If directory already exists Pik will do nothing. Next, it creates .pik directory in C:\Users\bosko. But why does Pik chose this directory?
On the Unix-like systems all user specific files and directories are kept in users home directory which is usually located at the
/home/<user_name> path and this value is stored in HOME system variable. On Windows, value that is used is stored in the USERPROFILE
variable and on my system its value is C:\Users\bosko. Pik stores its data within .pik directory in the users home folder. That it a reason why
it created .pik folder in it.
Further, it installed necessary scripts in the C:\tools folder by copying them from gem folder. At the end, Pik created .pikrc file in the .pik
folder. Dont be surprised by the name of the folder and the path. Naming convention on Unix-like systems is to hide them by prefixing names
with a dot. Actually files and directories which have names that start with a dot are not actually hidden but are not displayed in any tool
unless specifically requested. Pik follows this convention so it uses .pik and .pikrc for names of its folder and file within it.
Notice last comment printed out by pik_install script. It tells us that if we want to use Pik from Git bash shell we should add line:
[[ -s $USERPROFILE/.pik/.pikrc ]] && source $USERPROFILE/.pik/.pikrc
to ~/.bashrc file. Again tilda character is used on Unix-like systems to denote users home folder. As you might already guess it is
C:\Users\bosko on my system. Lets retain for a while on the .pikrc file. In the version 0.2.8 it contains following code:
#!/bin/sh
pik_path=/c/tools
function pik {
$pik_path/pik_runner.exe pik.sh $@
[[ -s $USERPROFILE/.pik/pik.sh ]] && source $USERPROFILE/.pik/pik.sh
}
The first line is the shebang line we mentioned earlier. Value /bin/sh means that the rest of the script should be executed in the shell. After
that there is a definition for pik_path variable and then a code that looks like, and is, function definition. As comment printed out at the end
of execution of pik_install script indicates, that this script is used for Git bash shell. Since Git uses Linux-like shell called Bash, it inherits
almost all functionalities from Linux system. In Windows Command Prompt invoking pik command means executing pik.bat, batch file, stored in
the C:\tools directory. On the other hand Git bash shell doesnt know how to start pik command. Open new Console2 window and type in the
Git bash tab (Ctrl-F2):
$ pik
sh.exe": pik: command not found
Therefore in order to use Pik in this shell we must execute it in such a way that pik function becomes available in it. You can do it by
executing following statement:
source $HOME/.pik/.pikrc
which tells Bash shell to apply changes from .pikrc configuration file. After that you can try Pik in the Gits Bash shell too:
$ pik -V
pik 0.2.8
If you do not want to source this configuration file every time you open Git Bash you should create .bashrc file in your home folder and put
[[ -s $USERPROFILE/.pik/.pikrc ]] && source $USERPROFILE/.pik/.pikrc
in it. Go ahead and try it. Close current Git tab in Console2, create .bashrc file and then open Git tab again. You will see that pik command is
available.
Up to now we havent actually tried Pik at all. We have only checked its availability in the Git Bash shell and its version. It is time to execute
Pik for the first time:
c:\>pik
** Adding: 192: ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
Located at: C:\Ruby\192\bin
Usage: pik command [options]
To get help with a command
pik help (command)
To list all commands and descriptions:
pik help commands
-V, --version Pik version
-d, --debug Outputs debug information
Amazing! Pik somehow found our installed Ruby and added it to its list of available Rubies. The question is how did Pik know what Ruby we
Pik 6/7/2014
http://rubyonwindowsguides.github.io/book/ch02-03.html 2 / 4
have. The answer is, again, Windows registry. If you open Registry Editor and navigate to HKEY_CURRENT_USER\Software\RubyInstaller key
you will see that it has MRI sub-key, and thats the place where it finds all necessary data about installed Ruby versions. If you are curious
what data is stored there click on the 1.9.2 sub-key within MRI and you will see that it holds information about platform Ruby is built on,
installation date, full path to the directory where Ruby is installed as well as a patch level. And thats all Pik has to know to add Ruby version
to itself.
Now go back to .pik folder in your home directory. You will see additional file created there, named config.yml. Extension .yml denotes it is
YAML file. YAML (YAML Aint Markup Language) is common format for serializing data in Ruby world. We will not dwell on it. If you are not
already familiar with YAML you can check the official YAML Web Site. Lets go further and open config.yml in your favorite editor.
---
"192: ruby 1.9.2p136 (2010-12-25) [i386-mingw32]":
:path: !ruby/object:Pathname
path: C:/Ruby/192/bin
--- {}
As you can see Pik has stored all data it needs about our Ruby in that configuration file. We should start exploring Pik features at this point.
Fire up Console2 and in the default tab check the list of all Ruby versions Pik is aware of by issuing pik list or pik ls command:
C:\>pik ls
* 192: ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
As expected, at the moment, Pik is aware only of our installed Ruby 1.9.2 version and it is marked as a default one, in the list that is printed
out, by the asterisk (*) sign at the beginning of the line.
More then just listing installed Ruby versions, Pik is capable of showing all Ruby versions that can be installed through it.
c:\>pik ls -r
---
DevKit:
3.4.5r3: http://rubyforge.org/frs/download.php/66888/devkit-3.4.5r3-20091110.7z
IronRuby:
0.3.0: http://rubyforge.org/frs/download.php/53552/ironruby-0.3.0.zip
0.5.0: http://rubyforge.org/frs/download.php/57126/ironruby-0.5.0.zip
0.6.0: http://rubyforge.org/frs/download.php/59717/ironruby-0.6.0.zip
0.9.0: http://rubyforge.org/frs/download.php/61382/ironruby-0.9.0.zip
0.9.1: http://rubyforge.org/frs/download.php/64504/ironruby-0.9.1.zip
0.9.2: http://rubyforge.org/frs/download.php/66606/ironruby-0.9.2.zip
"1.0": http://rubyforge.org/frs/download.php/70179/ironruby-1.0.zip
1.0-rc1: http://rubyforge.org/frs/download.php/67955/ironruby-1.0-rc1.zip
1.0-rc2: http://rubyforge.org/frs/download.php/69180/ironruby-1.0-rc2.zip
1.0.0rc: http://rubyforge.org/frs/download.php/69853/ironruby-1.0.0rc.zip
1.0rc3: http://rubyforge.org/frs/download.php/69665/ironruby-1.0rc3.zip
1.0v4: http://rubyforge.org/frs/download.php/70181/ironruby-1.0v4.zip
JRuby:
1.5.6: http://jruby.org.s3.amazonaws.com/downloads/1.5.6/jruby-bin-1.5.6.zip
1.6.0.RC1: http://jruby.org.s3.amazonaws.com/downloads/1.6.0.RC1/jruby-bin-1.6.0.RC1.zip
Ruby:
1.8.7-p302: http://rubyforge.org/frs/download.php/72087/ruby-1.8.7-p302-i386-mingw32.7z
1.8.7-p330: http://rubyforge.org/frs/download.php/73720/ruby-1.8.7-p330-i386-mingw32.7z
1.9.1-p429: http://rubyforge.org/frs/download.php/71496/ruby-1.9.1-p429-i386-mingw32.7z
1.9.1-p430: http://rubyforge.org/frs/download.php/72076/ruby-1.9.1-p430-i386-mingw32.7z
1.9.2-p0: http://rubyforge.org/frs/download.php/72160/ruby-1.9.2-p0-i386-mingw32.7z
1.9.2-p136: http://rubyforge.org/frs/download.php/73723/ruby-1.9.2-p136-i386-mingw32.7z
1.9.2-rc1: http://rubyforge.org/frs/download.php/71498/ruby-1.9.2-rc1-i386-mingw32.7z
1.9.2dev-preview3-1: http://rubyforge.org/frs/download.php/71175/ruby-1.9.2dev-preview3-i386-mingw32-1.7z
Omitting DevKit for the moment we can see that Pik can install various versions of IronRuby, JRuby and MRI. Well use this Piks feature and
install IronRuby. This version is not so important for usage throughout the book, but is installed just to show one of many Piks features.
Before we start IronRuby installation well configure Pik to install new Ruby versions where we want to in C:\Ruby.
pik config installs=C:\Ruby
Now we are ready to start IronRuby installation
c:\>pik install ironruby
** Downloading: http://rubyforge.org/frs/download.php/70181/ironruby-1.0v4.zip
to: C:\Users\bosko\.pik\downloads\ironruby-1.0v4.zip
ironruby-1.0v4.zip: 100% |ooooooooooooooooooooo| 2.9MB/ 2.9MB Time: 00:00:03
** Extracting: C:\Users\bosko\.pik\downloads\ironruby-1.0v4.zip
to: C:\ruby\IronRuby-10v4
done
** Adding: 100: IronRuby 1.0.0.0 on .NET 4.0.30319.1
Located at: C:\ruby\IronRuby-10v4\bin
This is simple and elegant way to install additional Ruby versions on your Windows system. Checking available Rubies now gives:
c:\>pik ls
100: IronRuby 1.0.0.0 on .NET 4.0.30319.1
* 192: ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
You must be aware of the fact that installing Rubies through Pik doesnt run full installer, if it is available. Rather Pik downloads Zip or 7Zip
archives, unpacks them and adds to its configuration file. This means that various configuration options that exist in installers like altering
Pik 6/7/2014
http://rubyonwindowsguides.github.io/book/ch02-03.html 3 / 4
system path, files associations, menu shortcuts, etc. will not be set.
Additionally Pik has command for displaying more information about Ruby setup that is active in the current shell pik info.
c:\>pik info
pik 0.2.8
ruby:
interpreter: "ruby"
version: "1.9.2"
date: "2010-12-25"
platform: "i386-mingw32"
patchlevel: "136"
full_version: "ruby 1.9.2p136 (2010-12-25) [i386-mingw32]"
homes:
gem: "C:\Ruby\192\lib\ruby\gems\1.9.1"
ruby: "C:\Ruby\192"
binaries:
ruby: "C:\Ruby\192\bin"
irb: "C:\Ruby\192\bin\irb.bat"
gem: "C:\Ruby\192\bin\gem.bat"
rake: "C:\Ruby\192\bin\rake.bat"
environment:
GEM_HOME: ""
HOME: "C:/Users/bosko"
IRBRC: ""
RUBYOPT: ""
file associations:
.rb: "c:\Ruby\192\bin\ruby.exe" "%1" %*
.rbw: "c:\Ruby\192\bin\rubyw.exe" "%1" %*
Output of Piks info command shows active interpreter version, full path where existing Ruby gems are and future ones will be installed, path
to Ruby binaries, environment variables and file associations.
Until now we have added two Ruby versions to Pik. First was added automatically when we first ran Pik and the second one was installed
through Pik itself. In the chapter Building Ruby we have built latest development version, copied it to C:\Ruby\193dev directory, but Pik is not
aware of it. We will use new Pik command to add this version. Logically command is called add and it accepts path to the directory where
ruby.exe is located.
C:\>pik add C:\Ruby\193dev\bin
** Adding: 193: ruby 1.9.3dev (2011-01-11 trunk 30511) [i386-mingw32]
Located at: C:\Ruby\193dev\bin
In a similar way we can add any Ruby version available on the system that is not installed through RubyInstaller installer. If we download any
of Ruby 1.8 archives from RubyInstallers download page all we have to do is to unpack archive to some directory and use pik add command to
add it to the list of versions that Pik can handle. Installing Ruby 1.8.7p330 is left for your exercise.
At the beginning of this chapter we said Piks main purpose is to manage various Ruby versions. At any time you can change active Ruby
version using Piks switch command
c:\>pik sw 187
c:\>ruby -v
ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
c:\>pik sw 193
c:\>ruby -v
ruby 1.9.3dev (2011-01-11 trunk 30511) [i386-mingw32]
c:\>pik switch 192
c:\>ruby -v
ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
Building Ruby | Devkit
Pik 6/7/2014
http://rubyonwindowsguides.github.io/book/ch02-03.html 4 / 4

Вам также может понравиться