LoginSignup
22
23

More than 5 years have passed since last update.

WindowsでのVagrant環境構築

Last updated at Posted at 2013-04-10

Windows7 にて Ruby 2.0.0-p0 (32bit) + Vagrant の環境構築をした際のメモ

実行ファイル インストールパス
rubyinstaller-2.0.0-p0.exe C:\Ruby200
DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe C:\Ruby200\dk
VirtualBox-4.2.10-84105-Win.exe C:\Program Files\Oracle\VirtualBox
  • Windowsに環境変数を追加
変数名
Path C:\Ruby200\bin;C:\Program Files\Oracle\VirtualBox

※インストールしたRubyのバージョンやインストールパスによって異なるので、必要に応じて適宜読み替えること

  • %UserProfile% に以下のファイルを作る ドットファイルの作成は、 cmd.exe から type nul > .gemrc などでできる
---
:update_sources: true
:sources:
- http://gems.rubyforge.org/
- http://gems.github.com
:benchmark: false
:bulk_threshold: 1000
:backtrace: false
:verbose: true
gem: --no-ri --no-rdoc
  • rubygems をアップデートする ※ 現状では、 invalid byte sequence in Windows-31J になるから、しばらくは省略 cmd.exe から以下を実行する
gem install rubygems-update
set LANG=ja_JP.UTF-8
update_rubygems
  • bundler をインストールする cmd.exe から以下を実行する
gem install bundler
md working-veewee
cd working-veewee
bundle init
  • 各種 gem のインストール 作成された Gemfile を以下のように編集する
source "https://rubygems.org"

gem 'vagrant'
gem 'sahara'
gem 'vagrant-vbguest'
gem 'veewee'

cmd.exe から以下を実行する

bundle --path vendor/bundle --binstubs

Windows だと、Linux系と違って --binstubs を付けても、意味が無さそうなので省略可

  • 利用可能なベーステンプレートの一覧を確認する cmd.exe から以下を実行する
bundle exec vagrant basebox templates
  • ベーステンプレートから、テスト用の box を作成してみる cmd.exe から以下を実行する
bundle exec vagrant basebox define box-test freebsd-9.0-RELEASE-amd64

definitions ディレクトリ以下に、box-test と言う box が作られ、中にあるスクリプトファイルを編集して、任意の VM テンプレートを作成することができるようになります

  • テスト用の box を以下のように編集して、 FreeBSD 9.1-RELEASE な VM を作成する
definition.rb
  :iso_file => "mfsbsd-9.1-RELEASE-amd64.iso",
  :iso_src => "http://mfsbsd.vx.sk/files/iso/amd64/9/mfsbsd-9.1-RELEASE-amd64.iso",
  :iso_md5 => "cbe0f0eaaf5e46545292313dfb939891",
  :shutdown_cmd => "shutdown -h now",
  • テスト用の box をビルドする cmd.exe から以下を実行する
bundle exec vagrant basebox build box-test

ビルドが成功すると、以下のようなメッセージが表示される

[box-test] The box box-test was build successfully!
  • 作成した box のイメージを取得する cmd.exe から以下を実行する
bundle exec vagrant basebox export box-test
  • box のイメージファイルから、 VM を起動する cmd.exe から以下を実行して、 box を登録する
md %UserProfile%\working-vagrant
cd %UserProfile%\working-vagrant
copy %UserProfile%\working-veewee\Gemfile Gemfile
bundle --path vendor/bundle --binstubs
bundle exec vagrant box add test-vm %UserProfile%\working-veewee\box-test.box

cmd.exe から以下を実行して、登録した box のリストを確認

bundle exec vagrant box list

結果
DL is deprecated, please use Fiddle
test-vm

cmd.exe から以下を実行して、 VM を起動する

md test-vm
cd test-vm
bundle exec vagrant init test-vm
bundle exec vagrant up
22
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
23