Windows + pik環境へのvagrantインストール

pikがインストールできたので次はvagrantをインストールします。VirtualBoxはあらかじめインストールしてあるものとします。

$ pik use 1.9.2
$ gem install vagrant
ERROR:  Error installing vagrant:
        The 'json' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

jsonのgemをビルドするのに必要なツールがないためうまくいきませんでした。エラーメッセージに書いてあるDevKitをインストールします。

pikの機能によるdevkitのインストール

pikはdevkitをインストールする機能を持っているらしいので、それを使うことにします。

$ pik help package

Usage: pik package [options]

Downloads and installs packages.

  sqlite: 'pik package sqlite install'
  7zip:   'pik package 7zip install'
  devkit: 'pik package devkit install' # Installed to mingw versions only.

しかしながら実行してもエラーでインストールできませんでした。

$ pik package devkit install
INFO: Downloading:  http://cdn.rubyinstaller.org/archives/devkits/DevKit-tdm-32-4.5.1-20101231-1457.7z
      to:  C:\dev\pik\downloads\DevKit-tdm-32-4.5.1-20101231-1457.7z


There was an error.
 Error: Failed to download http://cdn.rubyinstaller.org/archives/devkits/DevKit-tdm-32-4.5.1-20101231-1457.7z: Forbidden

手動でのdevkitインストール

pikの機能が使えないので、手動でdevkitをインストールします。ダウンロードページからdevkitのファイルをダウンロードします。

ダウンロードファイルを見て気がついたのですが、pikはdevkitの4.5.1をダウンロードしようとしていたのに対して、現在は4.5.2にバージョンアップしたためダウンロードするファイルがなくてエラーになっているようでした。

ダウンロードしたファイルは自己解凍ファイルなので、これを C:\dev\devkit に展開しておきます。あとは手順に従ってインストールします。

まずはスクリプトを実行してconfig.ymlを生成します。

$ cd C:\dev\devkit
$ ruby dk.rb init
Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

これで C:\dev\devkit\config.yml が生成されるのですが、pikで使用しているrubyのパスがうまく追加されないようなので手動で追加しておきます(最後の行)

# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
# - C:/ruby19trunk
# - C:/ruby192dev
#
---
- C:/dev/pik/rubies/ruby-1.9.2-p136

あとはインストールすれば完了です。

$ ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/dev/pik/rubies/ruby-1.9.2-p136'
[INFO] Installing 'C:/dev/pik/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/devkit.rb'

念のためdevkitページに書いてあるテストを実行しておきます。

$ gem install rdiscount --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed rdiscount-1.6.8
1 gem installed
Installing ri documentation for rdiscount-1.6.8...
Installing RDoc documentation for rdiscount-1.6.8...

$ ruby -rubygems -e "require 'rdiscount'; puts RDiscount.new('**Hello RubyInstaller**').to_html"
<p><strong>Hello RubyInstaller</strong></p>

特にエラーも出ず正常に動作しているようでした。

vagrantのインストール

devkitさえ設定してしまえば、vagrantはすんなりインストールできました。

$ gem install vagrant
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed json-1.5.4
Successfully installed log4r-1.1.10
Successfully installed net-ssh-2.2.2
Successfully installed net-scp-1.0.4
Successfully installed vagrant-1.0.5
5 gems installed
Installing ri documentation for json-1.5.4...
Installing ri documentation for log4r-1.1.10...
Installing ri documentation for net-ssh-2.2.2...
Installing ri documentation for net-scp-1.0.4...
Installing ri documentation for vagrant-1.0.5...
Installing RDoc documentation for json-1.5.4...
Installing RDoc documentation for log4r-1.1.10...
Installing RDoc documentation for net-ssh-2.2.2...
Installing RDoc documentation for net-scp-1.0.4...
Installing RDoc documentation for vagrant-1.0.5...

vagrant動作確認

念のためvagrantも動作を確認しておきます。確認内容はGetting Startedページに書いてあるものを使います。

提供されているBoxを取り込んでそれを起動します。

$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
$ vagrant init lucid32
$ vagrant up

起動した仮想マシンにログインできれば確認完了ですが、Windowsというかputtyを使う場合は秘密鍵を変換しておく必要があります。鍵を変換する方法はvagrantのSSHページに書いてあるとおり、puttygenでinsecure_private_keyからppkを作ればOKです。

PuTTY may not recognize the insecure_private_key provided by vagrant as a valid private key. To remedy this, first grab the PuTTYgen app. Then use PuTTYgen and import the insecure_private_key (found in the .vagrant.d dir in your home directory) and save a ppk file from that private key. Use the ppk file instead of the default one when SSHing into your vagrant box.

http://docs.vagrantup.com/v1/docs/getting-started/ssh.html

あとはlocalhostのポート2222に対してユーザvagrantとputtygenで生成した秘密鍵でログインできることが確認できました。

確認が完了したので仮想マシンは破棄しておきます。

$ vagrant destroy