LoginSignup
0
1

More than 5 years have passed since last update.

Vagrantのインストールと利用(MacOSX & Virtualbox)

Last updated at Posted at 2017-01-24

MacOSX(10.12.2)にVagrantとVirtualboxをインストールし、仮想環境を構築します。

Vagrantのインストール

上記より、Vagrantをダウンロードしてインストールします。
インストール後、vagrantコマンドが使用できるようになります。

$ vagrant -v
Vagrant 1.9.1

Virtualboxのインストール

次に、上記よりVirtualboxをダウンロードしてインストールします。
アプリケーションフォルダにVirtualBox.appが追加されます。
(今回インストールしたバージョンは5.1)

VagrantとBox

Vagrantを用いるとあらかじめ用意されたテンプレート(Box)を用いて、Virtualbox用の仮想環境を構築できます。

Box一覧(使用したいテンプレートを選択)
(1) https://atlas.hashicorp.com/boxes/search
(2) http://www.vagrantbox.es

まず、開発用のフォルダ(ディレクトリ)を作成して、移動します。

$ mkdir dev
$ cd dev

上記(1)のテンプレートを利用する際は、下記の最初のコマンドでVagrantfile(下記例はUbuntuのXenial)を作成し、次のコマンドでVirtualboxの仮想環境を構築して起動します。

$ vagrant init ubuntu/xenial64
$ vagrant up --provider virtualbox

上記(2)のテンプレートを利用する際は、box addオプションで最初にBox(下記ではhogeという名前で)を作成し、その後initとupを行います。

$ vagrant box add hoge https://atlas.hashicorp.com/gbarbieru/boxes/xenial
$ vagrant init hoge
$ vagrant up --provider virtualbox

作成した仮想環境を利用(ログイン)するには、開発用のフォルダ内で下記のコマンドを実行します。

$vagrant ssh

仮想環境を停止する際は「vagrant halt」、破棄する際は「vagrant destroy」を実行します。

0
1
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
0
1