VagrantをMac OSXにセットアップ


バーチャルボックスのインストール

[bash gutter=”false”]
Vagrant has detected that you have a version of VirtualBox installed
that is not supported. Please install one of the supported versions
listed below to use Vagrant:

4.0, 4.1, 4.2
[/bash]

2014.2.3現在VagrantはVirtualBoxの最新4.3をサポートしていないので、Download VirtualBox (Old Builds): VirtualBox 4.2 よりインストーラをダウンロードしてインストールしました。

vagrantのインストール

[bash gutter=”false”]
$ gem install vagrant
Fetching: archive-tar-minitar-0.5.2.gem (100%)
archive-tar-minitar’s executable "minitar" conflicts with minitar
Overwrite the executable? [yN] y

Done installing documentation for archive-tar-minitar, childprocess, log4r, net-scp, net-ssh, vagrant after 7 seconds
6 gems installed
[/bash]

OS イメージ “box” の追加

以下のコマンドでOSイメージを追加できる
[bash gutter=”false”]
vagrant box add {title} {url}
[/bash]

通常利用するようなOSのboxイメージは http://www.vagrantbox.es に公開されています。

Ubuntu 12.04を選択して起動してみます。
[bash gutter=”false”]
$ vagrant box add Ubuntu1204 http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box
[/bash]
title にデフォルトの “base” 以外を指定した場合は Vagrantfile に設定が必要です。
[ruby title=”Vagrantfile”]
Vagrant::Config.run do |config|

# Every Vagrant virtual environment requires a box to build off of.
# config.vm.box = "base"
config.vm.box = "Ubuntu1204"

end
[/ruby]
設定後 init して upします。
[bash gutter=”false”]
$ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
$ vagrant up
[default] Importing base box ‘Ubuntu1204’…
[default] Matching MAC address for NAT networking…
[default] Clearing any previously set forwarded ports…
[default] Forwarding ports…
[default] — 22 => 2222 (adapter 1)
[default] Creating shared folders metadata…
[default] Clearing any previously set network interfaces…
[default] Booting VM…
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.

Guest Additions Version: 4.1.12
VirtualBox Version: 4.2.22
[default] Mounting shared folders…
[default] — v-root: /vagrant
[/bash]
ssh で起動したboxにアクセスします。
[bash gutter=”false”]
$ vagrant ssh
[/bash]

追記 2014/4/21

久しぶりにboxを追加しようとしたら以下のエラーになった
[bash gutter=”false”]
$ vagrant box add CentOS_6_5 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
[vagrant] Downloading with Vagrant::Downloaders::HTTP…
[vagrant] Downloading box: https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
[vagrant] Downloading box: https://s3.amazonaws.com/github-cloud/releases/9086871/062c1990-5dbe-11e3-8636-484e1779fc04.box?response-content-disposition=attachment%3B%20filename%3Dcentos65-x86_64-20131205.box&AWSAccessKeyId=AKIAISTNZFOVBIJMK3TQ&Expires=1398065366&Signature=9l7%2BBA06F7tX0NYrP3ydB%2FGgNYY%3D
[vagrant] Extracting box…
[vagrant] Cleaning up downloaded box…
Failed to untar the box file. This is usually because you’re
attempting to add a box that isn’t a valid box file. Please
double check that the box file is properly packaged.
[/bash]
そこで、vagrantをupdateしたところ、RubyGem版はもうサポートしないのでインストーラからインストールしろとのこと
[bash gutter=”false”]
$ gem update vagrant
Vagrant version 1.0.7
localhost@hrendoh:~ $ gem update vagrant
Updating installed gems
Updating vagrant
Fetching: vagrant-1.5.0.gem (100%)
Thanks for wanting to use Vagrant! Unfortunately, this is not the way
to install Vagrant anymore. We now make installers for the various operating
systems Vagrant supports.

Vagrant is no longer distributed as a RubyGem. Please download the latest
version for your operating system from the URL below. If you still wish
to use the RubyGem version, you can manually install version 1.0.7. Note that
the RubyGem version hasn’t been updated in over a year and will no longer
receive any updates.

Prior to installing Vagrant using the installer, make sure you uninstall
all your Vagrant gems, since they sometimes conflict.

http://www.vagrantup.com

If you want to learn more about why we don’t distribute using RubyGems
anymore, please read this: http://mitchellh.com/abandoning-rubygems
Successfully installed vagrant-1.5.0
Parsing documentation for vagrant-1.5.0
Installing ri documentation for vagrant-1.5.0
Installing darkfish documentation for vagrant-1.5.0
Done installing documentation for vagrant after 0 seconds
Gems updated: vagrant
[/bash]

RubyGemのVagrantをアンインストールして
[bash gutter=”false”]
$ gem uninstall vagrant

Select gem to uninstall:
1. vagrant-1.0.7
2. vagrant-1.5.0
3. All versions
> 3
Successfully uninstalled vagrant-1.0.7
Remove executables:
vagrant

in addition to the gem? [Yn] y
Removing vagrant
Successfully uninstalled vagrant-1.5.0
[/bash]

http://www.vagrantup.com/downloads.html
からインストーラ(vagrant_1.5.3.dmg)をダウンロードしてインストール

boxを追加してみると成功
[bash gutter=”false”]
$ vagrant box add CentOS6.5_64 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
==> box: Adding box ‘CentOS6.5_64’ (v0) for provider:
box: Downloading: https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
==> box: Successfully added box ‘CentOS6.5_64’ (v0) for ‘virtualbox’!
[/bash]
追加したboxをVagrantfileに指定して
[ruby title=”Vagrantfile”]
# config.vm.box = "hashicorp/precise32"
config.vm.box = "CentOS6.5_64"
[/ruby]
起動
[bash gutter=”false”]
$ vagrant up
[/bash]

,