VirtualBox+VagrantでWindowsにCentOSの環境を構築する
これまでに何度か、Ruby on Railsを勉強しようとしたものの、
やってみる → やらなくなる → 忘れる
というサイクルを繰り返していたため、備忘録を作ることにしました。
ほぼほぼ素人なので、間違っている箇所もあるかもしれませんが、参考までに。
ツールのインストール
Windowsマシンで勉強します。
Google先生に聞いてみたところ、
VirtualBox + Vagrant が良さそうかなと思ったので、
早速インストール。
VirtualBox
Downloads – Oracle VM VirtualBox
Vagrant
Download - Vagrant by HashiCorp
インストールが終わったら、コマンドプロンプトで
$vagrant -v
と打って、
Vagrant 1.8.1
と表示されたので、インストールOK。
Vagrantの設定
Boxの取得
OSのイメージはこちらから取得できる模様。
Discover Vagrant Boxes | Atlas by HashiCorp
テンプレートとなるBoxを取得します。こんな感じ?
vagrant box add CentOs6.6 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box
回線が遅いのか、かなり時間がかかりました。
Boxの確認
ダウンロードしたBoxを確認します。
vagrant box list
Boxの初期化
任意のディレクトリに移動して、初期化。
md CentOs6.6 cd CentOs6.6 vagrant init CentOs6.6
Vagrantfileを編集
Vagrantfileを編集します。
コメントアウトを外して、ポート番号を書き換えました。
config.vm.network "forwarded_port", guest: 3000, host: 3000
こちらもコメントアウトを外します。
config.vm.provider "virtualbox" do |vb| # Display the VirtualBox GUI when booting the machine vb.gui = true # Customize the amount of memory on the VM: vb.memory = "1024" end
仮想マシンを起動
vagrant up
仮想マシンにログイン
vagrant ssh
こういうエラーメッセージが表示されました。
`ssh` executable not found in any directories in the %PATH% variable. Is an SSH client installed? Try installing Cygwin, MinGW or Git, all of which contain an SSH client. Or use your favorite SSH client with the following authentication information shown below:
WindowsにはデフォルトでSSHクライアントがインストールされていないとのこと。
やり方は何種類かあるみたいですが、
これを入れればOKみたいです。
もう一度
vagrant ssh
としてみると、ログインできました。