1
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 3 years have passed since last update.

[VirtualBox]Macでの仮想環境の構築方法

Last updated at Posted at 2020-08-17

仮想環境とは

「仮想環境」は、1台のPC内に、あたかも別のPCが入っているような環境をバーチャルで(仮想的に)作ることです。

仮想環境を構築すると、現在のPCの設定に影響を与えずに、別のPCとして開発環境を試すことができます。仮想環境は、不要になったら削除も可能です。

1.VirtualBoxをインストール

まず、VirtualBoxをインストールして、PC上に仮想環境を構築します。
下のリンクからOSに合わせてVirtualboxをダウンロードします。

OSがMojave・Catalina
https://download.virtualbox.org/virtualbox/6.0.14/VirtualBox-6.0.14-133895-OSX.dmg

それ以外
http://download.virtualbox.org/virtualbox/5.2.6/VirtualBox-5.2.6-120293-OSX.dmg

2.Vagrantをインストール

Vagrantは、仮想マシンを管理するツールで、Windows、Mac OS X、Linuxで動作します。
Vagrant自体には仮想化する機能はないため、仮想ソフトの操作をVirtualBoxで代行させています。

下記、Mac用のvagrantダウンロードページからダウンロードします。
https://releases.hashicorp.com/vagrant/2.2.4/vagrant_2.2.4_x86_64.dmg

3.Vagrantを起動する準備

3-1.「vagrant-vbguest」プラグインをインストール

vagrant-vbguestプラグインは、仮想マシンでの面倒な操作を肩代わりしてくれるプラグインです。 Macはターミナルを起動し、以下を入力します。
エラーが起きなければ、成功です。

$ vagrant plugin install vagrant-vbguest

3-2.Vagrantの初期設定を行う

初期設定を行うには、「Vagrantfile」を利用します。Vagrantfileは、Vagrantの初期設定が記述されたファイルです。

下記からファイルをダウンロードします。
https://wals.s3-ap-northeast-1.amazonaws.com/uploads/unit/vagrant/Vagrantfile

ダウンロードが完了したら、以下のコマンドを実行します。

$ cd Desktop
$ mkdir vagrant 
$ cd vagrant 

ディレクトリの作成を確認できたら、先ほどダウンロードした「Vagrantfile」を「vagrant」フォルダ内にコピーまたは移動します。

4.Vagrantを起動

以下のコマンドでvagrantを起動します。
起動までは1時間以上かかる場合があります。

$ vagrant up

5.仮想環境へSSH接続

vagrantを起動しただけでは、仮想環境へは接続できていませんので、SSH接続を行います。

SSH接続とは、自分のPCから他のPCへ安全に接続するために接続手法です。
以下の通り、接続します。

$ vagrant ssh

以下のようになれば、仮想環境への接続は成功です。

[vagrant@localhost ~]$
1
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
1
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?