LoginSignup
2
0

More than 5 years have passed since last update.

Windows環境でRubyの開発環境を構築する

Posted at

すでに多くの人が公開されている情報ですが、備忘の為にまとめる。

  • FOO:ディレクト名で利用

1. 全体の流れ

VirtualBox、Vagrantなどをインストールし、プレーンな仮想イメージを作り、そこにRrails等をインストールするという流れ。

2. VirtualBoxをインストールする。

先ず、はじめに仮想マシンを動かすためにVirtualBoxをインストールする。

Oracle社のVirtualBoxダウンロードサイト

3. Vagrantをインストールする。

同様にVagrantのインストーラーも下記からインストールする。
Vagrantのダウンロードサイト

3. Vagrant経由で仮想マシンを作成する。

仮想マシンについては、GUIツールのVirtualBox (Oracle VM VirtualBox マネージャー) を起動し、[新規]をクリックして、[仮想マシンの作成]と進んでいく従来のやり方も勿論あるけれども、やはり、誰かが作ったイメージ(BOX)をインターネット上からダウンロードして、使わせてもらうvagrant add方式の方が簡単なので、この方法で作成する。

(1) 作業ディレクトリ作成
 Vagrantで開発をする際に使用するファイルを格納するディレクトリを作成する必要があるため、一旦ローカルPCに戻り作業する必要がある。
 他の方のQiitaを見たり、実際に環境を作っていて思ったが、複数の開発環境を作る場合(会社用、プライベート用等)別ディレクトリの方がやりやすいと思い、現在はその考え方で環境を構築している。

コマンドプロンプト
$ mkdir C:\Users\FOO\mywork
$ cd C:\Users\FOO\mywork

(2) 開発イメージをダウンロードし、仮想イメージを作成する
 以下のWEBサイトに行き、自分のがダウンロードしたいBOXイメージを選び、決まったらbox addコマンドで仮想イメージをダウンロードする。
http://www.vagrantbox.es/

コマンドプロンプト
$ C:\Users\FOO\mywork>vagrant box add MYDEV ダウンロード対象のBoxのURL
$==> box: Box file was not detected as metadata. Adding it directly...
$==> box: Adding box 'MYDEV' (v0) for provider:
$    box: Downloading: https://github.com/CommanderK5/packer-centos-template/releases/download/0.6.7/vagrant-centos-6.7.box
$     box: Progress: 100% (Rate: 8884k/s, Estimated time remaining: --:--:--)
$ ==> box: Successfully added box 'MYDEV' (v0) for 'virtualbox'!

(3) 仮想イメージを確認する
 vagrant box listコマンドを実行し、作成したイメージを確認する。今回は2つ目のイメージを作ったため、2行表示されている。

コマンドプロンプト
$ C:\Users\FOO\mywork>vagrant box list
$ CentOS6.7 (virtualbox, 0)
$ MYDEV     (virtualbox, 0) ← 今回作った仮想イメージ

(4) Vagrantfileを作る
 vagrant initコマンドを実行し作業フォルダ内(mywork)にVagrantfileを作成する。

コマンドプロンプト
$ C:\Users\FOO\mywork>vagrant init MYDEV
$ 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を利用して、仮想イメージを起動する
 ここまででやっと仮想イメージのOSを起動する準備が整ったので、起動する。

コマンドプロンプト
$ C:\Users\FOO\Documents\mywork>vagrant up
$ Bringing machine 'default' up with 'virtualbox' provider...
$ ==> default: Importing base box 'MYDEV'...
$ ==> default: Matching MAC address for NAT networking...
$ ==> default: Setting the name of the VM: mywork_default_1515144697676_55339
$ ==> default: Clearing any previously set network interfaces...
$ ==> default: Preparing network interfaces based on configuration...
$     default: Adapter 1: nat
$ ==> default: Forwarding ports...
$     default: 22 (guest) => 2222 (host) (adapter 1)
$ ==> default: Booting VM...
$ ==> default: Waiting for machine to boot. This may take a few minutes...
$     default: SSH address: 127.0.0.1:2222
$     default: SSH username: vagrant
$     default: SSH auth method: private key
$     default:
$     default: Vagrant insecure key detected. Vagrant will automatically replace
$     default: this with a newly generated keypair for better security.
$     default:
$     default: Inserting generated public key within guest...
$     default: Removing insecure key from the guest if it's present...
$     default: Key inserted! Disconnecting and reconnecting using new SSH key...
$ ==> default: Machine booted and ready!
$ ==> default: Checking for guest additions in VM...
$     default: The guest additions on this VM do not match the installed version of
$     default: VirtualBox! In most cases this is fine, but in rare cases it can
$     default: prevent things such as shared folders from working properly. If you see
$     default: shared folder errors, please make sure the guest additions within the
$     default: virtual machine match the version of VirtualBox you have installed on
$     default: your host and reload your VM.
$     default:
$     default: Guest Additions Version: 4.3.30
$     default: VirtualBox Version: 5.1
$ ==> default: Mounting shared folders...
$     default: /vagrant => C:/Users/hiroyuki.katayama/Documents/mywork
2
0
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
2
0