Skip to content

Instantly share code, notes, and snippets.

@tokunami
Last active August 29, 2015 14:10
Show Gist options
  • Save tokunami/98401bb011081235a22f to your computer and use it in GitHub Desktop.
Save tokunami/98401bb011081235a22f to your computer and use it in GitHub Desktop.

Installing VirtualBox and Vagrant on Mac

1. VirtualBox
  • 無料で使用できるx86仮想化ソフトウェア・パッケージのひとつ

  • 開発はOracle

  • 他のVM には VMware Fusion や Parallels 等があるが、有償

  • タウンロード ⇒ インストール https://www.virtualbox.org/wiki/Downloads

今回はVirtualBox4.3.20 for OS X hosts amd64をダウンロードした

2. Vagrant
  • 仮想環境をプログラミングするツール(?)
  • ダウンロード

今回は ver 1.3.5 をダウンロード

http://downloads.vagrantup.com/

または gem でインストール

$ sudo gem install vagrant

インストール後、バージョン確認

$ vagrant -v
Vagrant 1.3.5
3. box ファイルのインストール
  • box ファイル…仮想マシンのテンプレートのこと。自作も可能
  • 下記から希望 OS の box ファイルダウンロード URL を取ってきて box add コマンドで追加

http://www.vagrantbox.es/

$ vagrant box add <boxname> <downloadurl>
Downloading or copying the box...
Extracting box...te: 287k/s, Estimated time remaining: --:--:--)
Successfully added box 'Ubuntu64' with provider 'virtualbox'!

ダウンロードの確認

$ vagrant box list
<boxname> (virtualbox)

参考1) vagrant box コマンドのヘルプ

$ vagrant box -h

参考2) box の削除

$vagrant box remove
4. Vagrantfile の作成

任意の場所にディレクトリ作成&移動

$ mkdir <directoryname>
$ cd <directoryname>

vagrang init コマンドで初期化( Vagrantfile が作成される)

$ vagrant init <boxname>
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.
5. 仮想マシンの起動

vagrant up コマンドで仮想マシンを起動

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box <boxname>...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[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 installed version of
VirtualBox! In most cases this is fine, but in rare cases it can
cause things such as shared folders to not work properly. If you see
shared folder errors, please update the guest additions within the
virtual machine and reload your VM.

Guest Additions Version: 4.3.10
VirtualBox Version: 4.2
[default] Mounting shared folders...
[default] -- /vagrant
Tokunaga-no-MacBook-Pro:vagrant tokunaga$ vagrant ssh
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-40-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Fri Dec  5 01:15:36 UTC 2014

  System load:  0.5               Processes:           86
  Usage of /:   2.7% of 39.34GB   Users logged in:     0
  Memory usage: 18%               IP address for eth0: 10.0.2.15
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.

仮想マシン起動後に VirtualBox を立ち上げて見てみたらちゃんと動いていた。

エラー

エラーが出たのでVirtualBoxのバージョンを4.3 ⇒ 4.2にダウングレードした

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

https://www.virtualbox.org/wiki/Download_Old_Builds_4_2

参考URL

http://www.webcyou.com/?p=4632

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment