スポンサーリンク

Windows8.1で、VirtualBox+Vagrant+putty+CentOS7.2+Rails+MariaDB

毎度おなじみの時間ばっかりかかる環境構築。

Windows 8.1
VirtualBox 5.x.x
Vagrant 1.8.1
CentOS7.2 (bento/centos-7.2)
Ruby 2.3.0
Rails
PHP
MariaDB

puttyごった煮 (SSHでログインするためのソフト)
Atom (テキストエディタ)

●参考ページ (というより、以下のページのほぼコピペです。)

Vagrant 1.8 + CentOS 7 + VirtualBox 5 + Ruby on Rails + Mysqlで開発環境構築
SanoHiroshiが2016/02/26に投稿(2016/03/11に編集)
http://qiita.com/SanoHiroshi/items/892a8516f4a6445e1e05

Railsインストール on CentOS7 (最小手順?)
egnr-in-6matroomが2015/07/28に投稿(2015/09/07に編集)
http://qiita.com/egnr-in-6matroom/items/c84a1d3896f1015be8d2

(0)VirtualBox, Vagrant, puttyごった煮をインストール。

(1)Windowsのコマンドプロンプトで、

cd c:
mkdir vm
cd vm
mkdir mycentos
cd mycentos
vagrant init bento/centos-7.2

mycentosフォルダに、Vagrantfile が作成されるので、Atomで開いて編集。

image

25行目

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

29行目

[sourcecode language='ruby' ]
  config.vm.network "private_network", ip: "192.168.33.10"
[/sourcecode]

image

Vagrantfileを保存してから、Windowsコマンドプロンプトで、

vagrant up

しばらく時間がかかる。

(2)共有ファイルシステムの設定

VagrantfileをAtomで開き、40行目を、以下のように変更。

[sourcecode language='ruby' ]
  config.vm.synced_folder "../mycentos", "/vagrant"
[/sourcecode]

image

puttyごった煮imageを起動して、

image

のように、

ホスト名: 192.169.33.10と入れて、開く。

vagrant, vagrant でログイン。

image

ファイル共有のためのソフト?をインストール

[sourcecode language='ruby' ]
sudo yum -y install kernel-devel
sudo yum -y install gcc make
[/sourcecode]

Windowsコマンドプロンプトで、

vagrant plugin install vagrant-vbguest

vagrant vbguest

image

vagrant reload

image

途中、puttyでエラーが出るので、puttyを終了。少し待つと、Windowsコマンドプロンプトに、vagrant boxの再起動が終了したという表示が出る。

image

ファイル共有ができているかを確認する。

puttyを起動してログイン。

image

image

CentOSの、/vagrant フォルダ内に作成したtext.txtが、Windows8.1の、c:vmmycentos フォルダ内に同時に作成されていることを確認した。OK.

(3)Rubyのインストール

gitのインストール

[sourcecode language='ruby' ]
sudo yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison git
[/sourcecode]

gitが入ったか確認してから、rbenvを入れる。

[sourcecode language='ruby' ]
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bashrc
exec $SHELL -l
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
cd ~/.rbenv/plugins/ruby-build
sudo ./install.sh
#以下のコマンドが使えるか確認
rbenv install -l
#Rubyのインストール
rbenv install 2.3.0; rbenv rehash
rbenv global 2.3.0
[/sourcecode]

とにかく、Rubyのインストール

image_thumb1

のところは、本当に時間がかかる。30分くらい?

入ったかを確認

ruby -v

which gem

which ruby

(4)Railsのインストール

[sourcecode language='ruby' ]
gem install bundler --no-rdoc --no-ri
rbenv rehash
gem install rails -v 4.2.2
rbenv rehash
rails -v
which rails
[/sourcecode]

gem install rails -v 4.2.2のところで、以下のような画面

image

下の部分で結構時間がかかる

image

image

15分以上かかったらしい。

(5)MySQL(MariaDB)のインストール

[sourcecode language='ruby' ]
sudo yum -y install mariadb-server
[/sourcecode]

あとは、

http://qiita.com/SanoHiroshi/items/892a8516f4a6445e1e05#mysql%E3%81%AE%E8%A8%AD%E5%AE%9A%E4%BB%AE%E6%83%B3%E3%83%9E%E3%82%B7%E3%83%B3%E5%81%B4

にしたがってMariaDBを設定。

(6)httpdのインストール

参考:https://centossrv.com/apache.shtml

yum -y install httpd

yum -y install php php-mbstring

あとは、

https://centossrv.com/apache.shtml

http://qiita.com/tamamius/items/448c350ca34e4db9f6f5

を参考にごちゃごちゃやると、

http://192.168.33.10/

image

にアクセスできるようになる。

(7)また、Rubyの勉強をしたいときに、

●vagrantで、CentOS7を起動

●Windowsの c:mycentos7ruby_lessons フォルダを作成し、その中にhello.rbなどのrubyファイルを作成し、Atomで編集

●puttyで、CentOS7にログインして、hello.rbなどの、rbファイルを実行

cd /vagrant/ruby_lessons

ruby hello.rb

image

image

これで、ドットインストールの講義のときとそっくりの環境で勉強できる。

http://dotinstall.com/lessons/basic_ruby_v2/26902

スポンサーリンク