スポンサーリンク

Windows8.1+Vagrant+CentOS7.2でRails5.0.0.rc1

開発環境の構築としては、Cloud9が一番簡単であろう。

しかし、私は、どうしてもオフラインで開発したい!
以下にまとめてみた。

(参考)

【Windows7】VirtualBox + Vagrant + Ruby + Rails4 開発環境の構築【初心者必見】
Gin326Mが2014/11/05に投稿(2014/11/10に編集)
http://qiita.com/Gin326M/items/01c8aef45f9a55b9b028

Ruby on Rails 5.0 スタートアップガイド (OIAX BOOKS) Kindle版
黒田 努 (著)

(環境)

Windows8.1
VirtualBox
Vagrant
CentOS7.2
Ruby 2.3.1
Rails 5.0.0.rc1

●VirtualBoxと、Vagrantと、TeraTermをインストールしておく。

cドライブの、vmフォルダの、centos72フォルダに作成する。

●VagrantでCentOS7.2をセットアップ

cmd.exe(コマンドプロンプト)を開く。

image

[sourcecode language=”ruby” padlinenumbers=”true”]
cd c:/vm
mkdir centos72
cd centos72

vagrant init bento/centos-7.2
vagrant up
[/sourcecode]

image

image

image

5分くらいかかったか?

●TeraTermでログイン

127.0.0.1

2222

vagrant

vagrant

image

ここは「続行」

image

vagrant

vagrant

image

 

[sourcecode language=”ruby”]
sudo yum -y update
sudo yum -y install git gcc make openssl-devel zlib-devel readline* gcc-c++
sudo yum -y install epel-release
sudo yum -y install nodejs
sudo yum -y install sqlite-devel
[/sourcecode]

image

162個くらいインストールされる。だいぶ時間かかる。

image

image

(参考)CentOS 7 に Node.js をインストールする

morisが2014/09/29に投稿

http://qiita.com/moris/items/4850d4e19392186e34f0

image

●rubyのインストール

[sourcecode language=”ruby”]
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo ‘export PATH="$HOME/.rbenv/bin:$PATH"’ >> ~/.bash_profile
echo ‘eval "$(rbenv init -)"’ >> ~/.bash_profile
. ~/.bash_profile
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install -l
rbenv install -v 2.3.1.
[/sourcecode]

image

image

image

すんごく待つ、とにかく待つ。20分くらい?

image

[sourcecode language=”ruby”]
rbenv rehash
rbenv global 2.3.1
ruby -v
[/sourcecode]

image

●Rails 5.0.0.rc1のインストール

[sourcecode language=”ruby”]
gem install rails –version=5.0.0.rc1
[/sourcecode]

image

image

10分くらいかかったかな?

[sourcecode language=”ruby”]
gem install bundler
[/sourcecode]

image

●一旦、TeraTermをcloseする。

●コマンドプロンプトで、vagrant halt

image

●c:vmcentos72 の中の、Vagrantfileをテキストエディタ(Atomなど)で開いて、以下のように編集。

image

(訂正前)

image

25行目を、以下のように訂正する。

(訂正後)

image

[sourcecode language=”ruby”]
config.vm.network "forwarded_port", guest: 3000, host: 3000
[/sourcecode]

●コマンドプロンプトで、vagrant up

image

image

vagrant upするたびに、毎回、Guest Additions moduleをインストールしなおしたりしていて時間がかかる(5分くらい?)のが気になるが、あきらめる(2016年5月にDockerを使って時間短縮しようと試みたが、ややこしくて私には無理であった)。

image

●TeraTermでログイン

127.0.0.1

2222

vagrant

vagrant

●Railsアプリの作成

[sourcecode language=”ruby”]
cd /vagrant
rails new sample
cd sample
rails s -b 0.0.0.0
[/sourcecode]

image

image

image

image

●ホストOS(Windows8.1)のブラウザで、

http://localhost:3000

と入力すると、以下のように表示される。

image

●ちなみに、

Windows(ホストOS)の、

c:vmcentos72vagrant フォルダ

と、

CenOS7.2(VirtualBox上のゲストOS)の、

/vagrant フォルダ

が共有されるので、

Windows上の、

c:vmcentos72vagrantsample フォルダ

をAtomで開いて、編集することにより、

CentOS7.2上の、

/vagrant/sample フォルダの中身を編集することになり、RailsアプリをホストOS上から開発することができる。

image

image

スポンサーリンク