自己チャレンジ用にRubyOnRails環境構築した時のメモ

## はじめに
自己チャレンジ・勉強用にRubyOnRailsでWebアプリを作りたい！リリースしたい！
と思いたち、環境構築したときの自分用メモです。
勉強用のページなので、間違いなどありましたらご指摘お願いしますm(_ _)m

## 作業環境
 * Windows 10 home 64bit
    * VMware(R) Workstation 14 Player利用
 * CentOS7 を仮想環境として利用.  

~~~
$ cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 

$ uname -a
Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
~~~

## rubyの更新
 * rubyのバージョン確認.

~~~
$ ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
~~~

 * rubyのバージョンアップをしようと[こちら](https://qiita.com/Fendo181/items/d14ebfb148223c8e5ecb)を参考にrbenvを導入する.

 * rbenv の最新であることを確認.

~~~
$ rbenv -v
rbenv 1.1.1-37-g1c772d5
~~~

 * インストールできるrubyバージョンからインストールバージョンを決定
    * 今回は、2.5.1をインストール.

~~~
$ rbenv install -l
Available versions:
  1.8.5-p52
  1.8.5-p113
  1.8.5-p114
  ...
~~~

### ハマったポイント.
~~~
$ rbenv install 2.5.1
Downloading ruby-2.5.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.bz2
Installing ruby-2.5.1...

BUILD FAILED (CentOS Linux 7 using ruby-build 20180618-7-gb6428c7)

Inspect or clean up the working tree at /tmp/ruby-build.20180729210820.13982
Results logged to /tmp/ruby-build.20180729210820.13982.log

Last 10 log lines:
The Ruby openssl extension was not compiled.
The Ruby readline extension was not compiled.
The Ruby zlib extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `yum install -y openssl-devel readline-devel zlib-devel` to fetch missing dependencies.

Configure options used:
  --prefix=/home/administrator/.rbenv/versions/2.5.1
  LDFLAGS=-L/home/administrator/.rbenv/versions/2.5.1/lib 
  CPPFLAGS=-I/home/administrator/.rbenv/versions/2.5.1/include 
~~~
となったので、ruby-build.20180729210820.13982.logを見てみる.

~~~
$ cat /tmp/ruby-build.20180729210820.13982.log
...
installing rdoc:                    /home/administrator/.rbenv/versions/2.5.1/share/ri/2.5.0/system
installing capi-docs:               /home/administrator/.rbenv/versions/2.5.1/share/doc/ruby
The Ruby openssl extension was not compiled.
The Ruby readline extension was not compiled.
The Ruby zlib extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `yum install -y openssl-devel readline-devel zlib-devel` to fetch missing dependencies.

Configure options used:
  --prefix=/home/administrator/.rbenv/versions/2.5.1
  LDFLAGS=-L/home/administrator/.rbenv/versions/2.5.1/lib 
  CPPFLAGS=-I/home/administrator/.rbenv/versions/2.5.1/include 
~~~
yum installが足りないと言われてるので（参考URLで最初にやれと書かれてますorz）、

~~~
$ sudo yum install -y openssl-devel readline-devel zlib-devel
...
インストール:
  openssl-devel.x86_64 1:1.0.2k-12.el7               readline-devel.x86_64 0:6.2-10.el7               zlib-devel.x86_64 0:1.2.7-17.el7              

依存性関連をインストールしました:
  keyutils-libs-devel.x86_64 0:1.5.8-3.el7             krb5-devel.x86_64 0:1.15.1-19.el7           libcom_err-devel.x86_64 0:1.42.9-12.el7_5        
  libselinux-devel.x86_64 0:2.5-12.el7                 libsepol-devel.x86_64 0:2.5-8.1.el7         libverto-devel.x86_64 0:0.2.5-4.el7              
  ncurses-devel.x86_64 0:5.9-14.20130511.el7_4         pcre-devel.x86_64 0:8.32-17.el7            

完了しました!
~~~
で必要なパッケージをインストールし、rubyのバージョンアップへ

~~~
$ rbenv install 2.5.1
Downloading ruby-2.5.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.bz2
Installing ruby-2.5.1...
Installed ruby-2.5.1 to /home/administrator/.rbenv/versions/2.5.1
~~~
となった後、

~~~
$ export $PATH:$HOME/.rbenv/versions/2.5.1/bin/
~~~
でやっと、rubyの2.5.1が使えるようになる.
※`$ rbenv rehash`/`$ rbenv global 2.5.1`を実行してもダメでした...

~~~
$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
~~~

## gem の更新
 * gemのVersionを確認.  

~~~
$ gem -v
2.7.6
~~~

 * gemをupdateする.

~~~
$ gem update --system
Updating rubygems-update
Fetching: rubygems-update-2.7.7.gem (100%)
Successfully installed rubygems-update-2.7.7
Parsing documentation for rubygems-update-2.7.7
Installing ri documentation for rubygems-update-2.7.7
Installing darkfish documentation for rubygems-update-2.7.7
Done installing documentation for rubygems-update after 45 seconds
Parsing documentation for rubygems-update-2.7.7
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 2.7.7
Bundler 1.16.2 installed
RubyGems 2.7.7 installed
Regenerating binstubs
Parsing documentation for rubygems-2.7.7
Installing ri documentation for rubygems-2.7.7
~~~

## rails をインストールする
 * 環境構築が正しく行えてれば、gem installするだけ(のはず).

~~~
[administrator@localhost ruby-build]$ gem install rails
Fetching: concurrent-ruby-1.0.5.gem (100%)
Successfully installed concurrent-ruby-1.0.5
Fetching: i18n-1.0.1.gem (100%)
Successfully installed i18n-1.0.1
Fetching: thread_safe-0.3.6.gem (100%)
Successfully installed thread_safe-0.3.6
Fetching: tzinfo-1.2.5.gem (100%)
Successfully installed tzinfo-1.2.5
Fetching: activesupport-5.2.0.gem (100%)
Successfully installed activesupport-5.2.0
Fetching: rack-2.0.5.gem (100%)
Successfully installed rack-2.0.5
Fetching: rack-test-1.1.0.gem (100%)
Successfully installed rack-test-1.1.0
Fetching: mini_portile2-2.3.0.gem (100%)
Successfully installed mini_portile2-2.3.0
Fetching: nokogiri-1.8.4.gem (100%)
Building native extensions. This could take a while...
Successfully installed nokogiri-1.8.4
Fetching: crass-1.0.4.gem (100%)
Successfully installed crass-1.0.4
Fetching: loofah-2.2.2.gem (100%)
Successfully installed loofah-2.2.2
Fetching: rails-html-sanitizer-1.0.4.gem (100%)
Successfully installed rails-html-sanitizer-1.0.4
Fetching: rails-dom-testing-2.0.3.gem (100%)
Successfully installed rails-dom-testing-2.0.3
Fetching: builder-3.2.3.gem (100%)
Successfully installed builder-3.2.3
Fetching: erubi-1.7.1.gem (100%)
Successfully installed erubi-1.7.1
Fetching: actionview-5.2.0.gem (100%)
Successfully installed actionview-5.2.0
Fetching: actionpack-5.2.0.gem (100%)
Successfully installed actionpack-5.2.0
Fetching: activemodel-5.2.0.gem (100%)
Successfully installed activemodel-5.2.0
Fetching: arel-9.0.0.gem (100%)
Successfully installed arel-9.0.0
Fetching: activerecord-5.2.0.gem (100%)
Successfully installed activerecord-5.2.0
Fetching: globalid-0.4.1.gem (100%)
Successfully installed globalid-0.4.1
Fetching: activejob-5.2.0.gem (100%)
Successfully installed activejob-5.2.0
Fetching: mini_mime-1.0.0.gem (100%)
Successfully installed mini_mime-1.0.0
Fetching: mail-2.7.0.gem (100%)
Successfully installed mail-2.7.0
Fetching: actionmailer-5.2.0.gem (100%)
Successfully installed actionmailer-5.2.0
Fetching: nio4r-2.3.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed nio4r-2.3.1
Fetching: websocket-extensions-0.1.3.gem (100%)
Successfully installed websocket-extensions-0.1.3
Fetching: websocket-driver-0.7.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed websocket-driver-0.7.0
Fetching: actioncable-5.2.0.gem (100%)
Successfully installed actioncable-5.2.0
Fetching: mimemagic-0.3.2.gem (100%)
Successfully installed mimemagic-0.3.2
Fetching: marcel-0.3.2.gem (100%)
Successfully installed marcel-0.3.2
Fetching: activestorage-5.2.0.gem (100%)
Successfully installed activestorage-5.2.0
Fetching: thor-0.20.0.gem (100%)
Successfully installed thor-0.20.0
Fetching: method_source-0.9.0.gem (100%)
Successfully installed method_source-0.9.0
Fetching: railties-5.2.0.gem (100%)
Successfully installed railties-5.2.0
Fetching: sprockets-3.7.2.gem (100%)
Successfully installed sprockets-3.7.2
Fetching: sprockets-rails-3.2.1.gem (100%)
Successfully installed sprockets-rails-3.2.1
Fetching: rails-5.2.0.gem (100%)
Successfully installed rails-5.2.0
Parsing documentation for concurrent-ruby-1.0.5
Installing ri documentation for concurrent-ruby-1.0.5
Parsing documentation for i18n-1.0.1
Installing ri documentation for i18n-1.0.1
Parsing documentation for thread_safe-0.3.6
Installing ri documentation for thread_safe-0.3.6
Parsing documentation for tzinfo-1.2.5
Installing ri documentation for tzinfo-1.2.5
Parsing documentation for activesupport-5.2.0
Installing ri documentation for activesupport-5.2.0
Parsing documentation for rack-2.0.5
Installing ri documentation for rack-2.0.5
Parsing documentation for rack-test-1.1.0
Installing ri documentation for rack-test-1.1.0
Parsing documentation for mini_portile2-2.3.0
Installing ri documentation for mini_portile2-2.3.0
Parsing documentation for nokogiri-1.8.4
Installing ri documentation for nokogiri-1.8.4
Parsing documentation for crass-1.0.4
Installing ri documentation for crass-1.0.4
Parsing documentation for loofah-2.2.2
Installing ri documentation for loofah-2.2.2
Parsing documentation for rails-html-sanitizer-1.0.4
Installing ri documentation for rails-html-sanitizer-1.0.4
Parsing documentation for rails-dom-testing-2.0.3
Installing ri documentation for rails-dom-testing-2.0.3
Parsing documentation for builder-3.2.3
Installing ri documentation for builder-3.2.3
Parsing documentation for erubi-1.7.1
Installing ri documentation for erubi-1.7.1
Parsing documentation for actionview-5.2.0
Installing ri documentation for actionview-5.2.0
Parsing documentation for actionpack-5.2.0
Installing ri documentation for actionpack-5.2.0
Parsing documentation for activemodel-5.2.0
Installing ri documentation for activemodel-5.2.0
Parsing documentation for arel-9.0.0
Installing ri documentation for arel-9.0.0
Parsing documentation for activerecord-5.2.0
Installing ri documentation for activerecord-5.2.0
Parsing documentation for globalid-0.4.1
Installing ri documentation for globalid-0.4.1
Parsing documentation for activejob-5.2.0
Installing ri documentation for activejob-5.2.0
Parsing documentation for mini_mime-1.0.0
Installing ri documentation for mini_mime-1.0.0
Parsing documentation for mail-2.7.0
Installing ri documentation for mail-2.7.0
Parsing documentation for actionmailer-5.2.0
Installing ri documentation for actionmailer-5.2.0
Parsing documentation for nio4r-2.3.1
Installing ri documentation for nio4r-2.3.1
Parsing documentation for websocket-extensions-0.1.3
Installing ri documentation for websocket-extensions-0.1.3
Parsing documentation for websocket-driver-0.7.0
Installing ri documentation for websocket-driver-0.7.0
Parsing documentation for actioncable-5.2.0
Installing ri documentation for actioncable-5.2.0
Parsing documentation for mimemagic-0.3.2
Installing ri documentation for mimemagic-0.3.2
Parsing documentation for marcel-0.3.2
Installing ri documentation for marcel-0.3.2
Parsing documentation for activestorage-5.2.0
Installing ri documentation for activestorage-5.2.0
Parsing documentation for thor-0.20.0
Installing ri documentation for thor-0.20.0
Parsing documentation for method_source-0.9.0
Installing ri documentation for method_source-0.9.0
Parsing documentation for railties-5.2.0
Installing ri documentation for railties-5.2.0
Parsing documentation for sprockets-3.7.2
Installing ri documentation for sprockets-3.7.2
Parsing documentation for sprockets-rails-3.2.1
Installing ri documentation for sprockets-rails-3.2.1
Parsing documentation for rails-5.2.0
Installing ri documentation for rails-5.2.0
Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, activesupport, rack, rack-test, mini_portile2, nokogiri, crass, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, arel, activerecord, globalid, activejob, mini_mime, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, thor, method_source, railties, sprockets, sprockets-rails, rails after 102 seconds
38 gems installed
~~~
※ここで、もし`Successfully`以外が出てれば、個別トラブルシューティング.

### 以上で、rails環境の準備OK.
~~~
$ rails -v
Rails 5.2.0
~~~