0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrantチュートリアル(1)

0
Last updated at Posted at 2017-05-15

環境はMacです
コンソールはもちろんターミナルを使います。
VirutualBoxはすでにインストールしている前提です

Install Vagrant

自分のPCにまずVagrantをインストールします。

install_2.png
  • あとはいつも通りインストールします
    install_3.pnginstall_4.png

Verifying the Installation

次にインストール状況の確認です。

$ vagrant -v

$ vagrant -v
Vagrant 1.9.4

以上のようにインストールされたVagratのバージョンがわかります
※2017/5/15現在の最新バージョンです

Vagrant command

以下のコマンドで
vagrantコマンドの一覧を確認できます

$ vagrant -h

Project Setup

  • Vagrantの設定ファイルを置くディレクトリを用意します
    ※場所はどこでもいいようです

$ mkdir vagrant_getting_started

  • 作ったディレクトリに移動します

$ cd vagrant_getting_started

  • initコマンドを実行します

$ vagrant init

  • initコマンドを実行するとVagrantFileが生成されます
init1.png

VagrantFileはRubyで書かれた設定ファイルです
これの設定に通ずることができれば環境構築がより速くなります

Boxes

仮想マシンの大元になるイメージを設定します

  • Boxの設定
$ vagrant box add hashicorp/precise64

※取得先は公式に載っているものになります - Discover Vagrant Boxes

  • Boxの確認
$ vagrant box list

$ vagrant box list
hashicorp/precise64 (virtualbox, 1.1.0)

Up And SSH

Vagrant up

いよいよvagrantを立ち上げるコマンドを打ちます
※ VagrantFileがあるディレクトリであることを確認してください

$ vagrant up

Error

おそらくこの流れで行くと以下のようなエラーが表示されます

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'base' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'base' (v0) for provider: virtualbox
    default: Downloading: base
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

Couldn't open file /Users/ユーザ名/VagrantFileがあるディレクトリ/base

VagrantFile Edit

ファイルを開き以下の箇所を編集します
スクリーンショット 2017-05-15 17.31.36.png

仮装マシンを立ち上げるのに参照するBOX名を示していますので
先ほど入れたhashicorp/precise64に変えます

config.vm.box = "base"
↓
config.vm.box = "hashicorp/precise64"

再度、試しましょう

$ vagrant up

うまくいったら次はログインしましょう

Vagrant ssh

$ vagrant ssh

$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
New release '14.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2

これで成功です。

あとがき

自分用に公式のチュートリアルをまとめてみようと思ったものです
詳細は公式また他にもわかりやすい記事は色々あるのでご参考に
Vagrant公式
ドットインストール

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?