vagrantにRVMを使ってRuby on Rails環境を作るよ

構築時に切って貼ったコマンドとログをペタリと。。。

# 今回のお題
vagrant上でRuby on Railsが動く環境をつくろう

普段はvagrant環境でPHPを触っておりますが
必要に駆られたのでRuby on Railsの環境を作りますよ

## 各種バージョン
| モノ | バージョン |
|:-----------|------------:|
| CentOS | 6.7 |
| Ruby | 2.3.1 |
| Rails | 5.0.1 |
| DB | PostgreSQL 9.6 |


## vagrant 
前述したようにvagrantは既にインストール済みなので
boxの追加から始めますよ
今回はCentOS 6.7で

1.BOX追加

```:コマンド
vagrant box add centos6.7 https://github.com/CommanderK5/packer-centos-template/releases/download/0.6.7/vagrant-centos-6.7.box
```

```:実行結果
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos6.7' (v0) for provider: 
    box: Downloading: https://github.com/CommanderK5/packer-centos-template/releases/download/0.6.7/vagrant-centos-6.7.box
==> box: Successfully added box 'centos6.7' (v0) for 'virtualbox'!
```

2.仮想マシンを作成しますよ

```:コマンド
vagrant init centos6.7
```

```:実行結果
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.
```

3.vagrantfileを編集しますよ

```:コマンド
vi Vagrantfile 
```
以下のコメントを外してあげました

`config.vm.network "private_network", ip: "192.168.33.10"`

4.起動しましょう

```:コマンド
vagrant up
```

5.ログインしましょう

```:コマンド
vagrant ssh
```

## Ruby
1.まずはyumからRubyを削除しますよ

```:コマンド
sudo yum -y remove ruby
```

```:実行結果
Loaded plugins: fastestmirror
Setting up Remove Process
No Match for argument: ruby
Determining fastest mirrors
epel/metalink                                                         | 6.0 kB     00:00     
 * base: www.ftp.ne.jp
 * epel: mirror.lzu.edu.cn
 * extras: www.ftp.ne.jp
 * updates: mirror.qoxy.com
base                                                                  | 3.7 kB     00:00     
base/primary_db                                                       | 4.7 MB     00:04     
https://mirror.lzu.edu.cn/epel/6/x86_64/repodata/repomd.xml: [Errno 14] problem making ssl connection
Trying other mirror.
epel                                                                  | 4.3 kB     00:00     
epel/primary_db                                                       | 5.9 MB     00:15     
extras                                                                | 3.4 kB     00:00     
extras/primary_db                                                     |  37 kB     00:00     
puppetlabs-pc1                                                        | 2.5 kB     00:00     
puppetlabs-pc1/primary_db                                             | 117 kB     00:00     
updates                                                               | 3.4 kB     00:00     
updates/primary_db                                                    | 828 kB     00:00     
Package(s) ruby available, but not installed.
No Packages marked for removal
```

あれっ、なかったのかな・・・？

2.Git入れるよ
気を取り直してgitインストール

```:コマンド
sudo yum -y install git
```

```:実行結果
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: mirror.lzu.edu.cn
 * extras: www.ftp.ne.jp
 * updates: mirror.qoxy.com
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.7.1-8.el6 will be installed
--> Processing Dependency: perl-Git = 1.7.1-8.el6 for package: git-1.7.1-8.el6.x86_64
--> Processing Dependency: rsync for package: git-1.7.1-8.el6.x86_64
--> Processing Dependency: perl(Git) for package: git-1.7.1-8.el6.x86_64
--> Processing Dependency: perl(Error) for package: git-1.7.1-8.el6.x86_64
--> Running transaction check
---> Package perl-Error.noarch 1:0.17015-4.el6 will be installed
---> Package perl-Git.noarch 0:1.7.1-8.el6 will be installed
---> Package rsync.x86_64 0:3.0.6-12.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
 Package               Arch              Version                       Repository       Size
=============================================================================================
Installing:
 git                   x86_64            1.7.1-8.el6                   base            4.6 M
Installing for dependencies:
 perl-Error            noarch            1:0.17015-4.el6               base             29 k
 perl-Git              noarch            1.7.1-8.el6                   base             29 k
 rsync                 x86_64            3.0.6-12.el6                  base            335 k

Transaction Summary
=============================================================================================
Install       4 Package(s)

Total download size: 5.0 M
Installed size: 15 M
Downloading Packages:
(1/4): git-1.7.1-8.el6.x86_64.rpm                                     | 4.6 MB     00:04     
(2/4): perl-Error-0.17015-4.el6.noarch.rpm                            |  29 kB     00:00     
(3/4): perl-Git-1.7.1-8.el6.noarch.rpm                                |  29 kB     00:00     
(4/4): rsync-3.0.6-12.el6.x86_64.rpm                                  | 335 kB     00:00     
---------------------------------------------------------------------------------------------
Total                                                        340 kB/s | 5.0 MB     00:15     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 1:perl-Error-0.17015-4.el6.noarch                                         1/4 
  Installing : rsync-3.0.6-12.el6.x86_64                                                 2/4 
  Installing : perl-Git-1.7.1-8.el6.noarch                                               3/4 
  Installing : git-1.7.1-8.el6.x86_64                                                    4/4 
  Verifying  : git-1.7.1-8.el6.x86_64                                                    1/4 
  Verifying  : rsync-3.0.6-12.el6.x86_64                                                 2/4 
  Verifying  : perl-Git-1.7.1-8.el6.noarch                                               3/4 
  Verifying  : 1:perl-Error-0.17015-4.el6.noarch                                         4/4 

Installed:
  git.x86_64 0:1.7.1-8.el6                                                                   

Dependency Installed:
  perl-Error.noarch 1:0.17015-4.el6               perl-Git.noarch 0:1.7.1-8.el6              
  rsync.x86_64 0:3.0.6-12.el6                    

Complete!
```

completeって出たし大丈夫でしょ

3.ファイアウォール削除
開発環境には不要ってことで

```:コマンド
sudo service iptables stop
sudo chkconfig iptables off
```

4.RVMインストールするよ

```:コマンド
curl -sSL https://get.rvm.io | bash -s stable
```

```:実行結果
Downloading https://github.com/rvm/rvm/archive/1.29.1.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.1/1.29.1.tar.gz.asc
gpg: Signature made Sun 19 Feb 2017 20:02:47 GMT using RSA key ID BF04FF17
gpg: Can't check signature: No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).

GPG signature verification failed for '/home/vagrant/.rvm/archives/rvm-1.29.1.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.1/1.29.1.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -

the key can be compared with:

    https://rvm.io/mpapis.asc
    https://keybase.io/mpapis

NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above.
```

ん？GPG signature verification failed...？
Try to install GPG v2 and then fetch the public key とあるので以下を実行するよ

```:コマンド
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
```

```:実行結果
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpgkeys: HTTP fetch error 6: Couldn't resolve host 'keys.gnupg.net'
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
```

no valid OpenPGP data found...？
むむむ

```:コマンド
curl -#LO https://rvm.io/mpapis.asc
gpg --import mpapis.asc
```

```:コマンド
\curl -sSL https://get.rvm.io | bash
```

```:実行結果
Downloading https://github.com/rvm/rvm/archive/master.tar.gz

Installing RVM to /home/vagrant/.rvm/
    Adding rvm PATH line to /home/vagrant/.profile /home/vagrant/.mkshrc /home/vagrant/.bashrc /home/vagrant/.zshrc.
    Adding rvm loading line to /home/vagrant/.profile /home/vagrant/.bash_profile /home/vagrant/.zlogin.
Installation of RVM in /home/vagrant/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/vagrant/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# User,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: https://rvm.io/help and https://twitter.com/rvm_io
```

お、いけた気がする♪

```
rm -rf ~/.gnupg/
```

ここからは気を取り直して

```:コマンド
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
```

```:実行結果
gpg: directory `/home/vagrant/.gnupg' created
gpg: new configuration file `/home/vagrant/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/vagrant/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/vagrant/.gnupg/secring.gpg' created
gpg: keyring `/home/vagrant/.gnupg/pubring.gpg' created
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpg: /home/vagrant/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
```

良いんじゃない！
改めてもういっちょ！

```:コマンド
curl -sSL https://get.rvm.io | bash -s stable
```

```:実行結果
Downloading https://github.com/rvm/rvm/archive/1.29.1.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.1/1.29.1.tar.gz.asc
gpg: Signature made Sun 19 Feb 2017 20:02:47 GMT using RSA key ID BF04FF17
gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>"
gpg:                 aka "Michal Papis <michal.papis@toptal.com>"
gpg:                 aka "[jpeg image of size 5015]"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
     Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
GPG verified '/home/vagrant/.rvm/archives/rvm-1.29.1.tgz'

Upgrading the RVM installation in /home/vagrant/.rvm/
    RVM PATH line found in /home/vagrant/.mkshrc /home/vagrant/.profile /home/vagrant/.bashrc /home/vagrant/.zshrc.
    RVM sourcing line found in /home/vagrant/.profile /home/vagrant/.bash_profile /home/vagrant/.zlogin.
Upgrade of RVM in /home/vagrant/.rvm/ is complete.

# User,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: https://rvm.io/help and https://twitter.com/rvm_io

Upgrade Notes:


  * WARNING: You have '~/.profile' file, you might want to load it,
    to do that add the following line to '/home/vagrant/.bash_profile':

      source ~/.profile

  * No new notes to display.
```

多分いけてる!

プロフィールをいじって
`source ~/.profile`

バージョン確認

```:コマンド
rvm -v
```

```:実行結果
rvm 1.29.1 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]
```

入った！！
一覧を拝見。。。

```:コマンド
rvm list known
```

```:実行結果
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.6]
[ruby-]2.3[.3]
[ruby-]2.4[.0]
ruby-head

# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2

# JRuby
jruby-1.6[.8]
jruby-1.7[.26]
jruby[-9.1.7.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx[-3.71]
rbx-head

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1[.2.0]
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Topaz
topaz

# MagLev
maglev[-head]
maglev-1.0.0

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head
```

これでOK！
バージョンを選択してインストール

```:コマンド
rvm install 2.3.1
```

確認！

```:コマンド
ruby -v
```

```:実行結果
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
```

大丈夫なのでデフォルトに設定

```:コマンド
rvm use 2.3.1
```

## Rails
やっとここからRailsですよ

1./vagtant_dataにプロジェクト作ってみましょ

```:コマンド
cd /vagrant_data/
mkdir prj
cd prj/
bundle init
```

2.Gemfile編集

```:コマンド
view Gemfile
```

`gem "rails", "5.0.1"`だって

3.インストールしまっす

```:コマンド
bundle install --path vendor/bundle
```

```:実行結果
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies....
Installing rake 12.0.0
Installing concurrent-ruby 1.0.5
Installing i18n 0.8.1
Installing minitest 5.10.2
Installing thread_safe 0.3.6
Installing builder 3.2.3
Installing erubis 2.7.0
Installing mini_portile2 2.1.0
Installing rack 2.0.3
Installing nio4r 1.2.1 with native extensions
Installing websocket-extensions 0.1.2
Installing mime-types-data 3.2016.0521
Installing arel 7.1.4
Using bundler 1.12.5
Installing method_source 0.8.2
Installing thor 0.19.4
Installing tzinfo 1.2.3
Installing nokogiri 1.7.2 with native extensions
Installing rack-test 0.6.3
Installing sprockets 3.7.1
Installing websocket-driver 0.6.5 with native extensions
Installing mime-types 3.1
Installing activesupport 5.0.1
Installing loofah 2.0.3
Installing mail 2.6.5
Installing rails-dom-testing 2.0.3
Installing globalid 0.4.0
Installing activemodel 5.0.1
Installing rails-html-sanitizer 1.0.3
Installing activejob 5.0.1
Installing activerecord 5.0.1
Installing actionview 5.0.1
Installing actionpack 5.0.1
Installing actioncable 5.0.1
Installing actionmailer 5.0.1
Installing railties 5.0.1
Installing sprockets-rails 3.2.0
Installing rails 5.0.1
Bundle complete! 1 Gemfile dependency, 38 gems now installed.
Bundled gems are installed into ./vendor/bundle.
```

行けたのかな？
たぶん行けた

## PostgreSQL

1. yumからPostgreSQL消すのです

```:コマンド
sudo yum remove postgresql postgresql-devel postgresql-libs postgresql-server
```

```:実行結果
Loaded plugins: fastestmirror
Setting up Remove Process

No Match for argument: postgresql
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: mirror.lzu.edu.cn
 * extras: www.ftp.ne.jp
 * updates: mirror.qoxy.com
Package(s) postgresql available, but not installed.
No Match for argument: postgresql-devel
Package(s) postgresql-devel available, but not installed.
No Match for argument: postgresql-libs
Package(s) postgresql-libs available, but not installed.
No Match for argument: postgresql-server
Package(s) postgresql-server available, but not installed.
No Packages marked for removal
```

2.新しいバージョンのを入れるのです

```:コマンド
sudo rpm -ivh https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
sudo yum install postgresql96-server postgresql96-devel
```

```:実行結果
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: mirror.lzu.edu.cn
 * extras: www.ftp.ne.jp
 * updates: mirror.qoxy.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql96-devel.x86_64 0:9.6.3-1PGDG.rhel6 will be installed
--> Processing Dependency: postgresql96-libs(x86-64) = 9.6.3-1PGDG.rhel6 for package: postgresql96-devel-9.6.3-1PGDG.rhel6.x86_64
--> Processing Dependency: postgresql96(x86-64) = 9.6.3-1PGDG.rhel6 for package: postgresql96-devel-9.6.3-1PGDG.rhel6.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql96-devel-9.6.3-1PGDG.rhel6.x86_64
--> Processing Dependency: libpgtypes.so.3()(64bit) for package: postgresql96-devel-9.6.3-1PGDG.rhel6.x86_64
--> Processing Dependency: libecpg_compat.so.3()(64bit) for package: postgresql96-devel-9.6.3-1PGDG.rhel6.x86_64
--> Processing Dependency: libecpg.so.6()(64bit) for package: postgresql96-devel-9.6.3-1PGDG.rhel6.x86_64
---> Package postgresql96-server.x86_64 0:9.6.3-1PGDG.rhel6 will be installed
--> Running transaction check
---> Package postgresql96.x86_64 0:9.6.3-1PGDG.rhel6 will be installed
---> Package postgresql96-libs.x86_64 0:9.6.3-1PGDG.rhel6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
 Package                     Arch           Version                     Repository      Size
=============================================================================================
Installing:
 postgresql96-devel          x86_64         9.6.3-1PGDG.rhel6           pgdg96         1.7 M
 postgresql96-server         x86_64         9.6.3-1PGDG.rhel6           pgdg96         4.8 M
Installing for dependencies:
 postgresql96                x86_64         9.6.3-1PGDG.rhel6           pgdg96         1.4 M
 postgresql96-libs           x86_64         9.6.3-1PGDG.rhel6           pgdg96         282 k

Transaction Summary
=============================================================================================
Install       4 Package(s)

Total download size: 8.1 M
Installed size: 33 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): postgresql96-9.6.3-1PGDG.rhel6.x86_64.rpm                      | 1.4 MB     00:04     
(2/4): postgresql96-devel-9.6.3-1PGDG.rhel6.x86_64.rpm                | 1.7 MB     00:02     
(3/4): postgresql96-libs-9.6.3-1PGDG.rhel6.x86_64.rpm                 | 282 kB     00:00     
(4/4): postgresql96-server-9.6.3-1PGDG.rhel6.x86_64.rpm               | 4.8 MB     00:04     
---------------------------------------------------------------------------------------------
Total                                                        429 kB/s | 8.1 MB     00:19     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : postgresql96-libs-9.6.3-1PGDG.rhel6.x86_64                                1/4 
  Installing : postgresql96-9.6.3-1PGDG.rhel6.x86_64                                     2/4 
  Installing : postgresql96-devel-9.6.3-1PGDG.rhel6.x86_64                               3/4 
  Installing : postgresql96-server-9.6.3-1PGDG.rhel6.x86_64                              4/4 
  Verifying  : postgresql96-devel-9.6.3-1PGDG.rhel6.x86_64                               1/4 
  Verifying  : postgresql96-libs-9.6.3-1PGDG.rhel6.x86_64                                2/4 
  Verifying  : postgresql96-9.6.3-1PGDG.rhel6.x86_64                                     3/4 
  Verifying  : postgresql96-server-9.6.3-1PGDG.rhel6.x86_64                              4/4 

Installed:
  postgresql96-devel.x86_64 0:9.6.3-1PGDG.rhel6                                              
  postgresql96-server.x86_64 0:9.6.3-1PGDG.rhel6                                             

Dependency Installed:
  postgresql96.x86_64 0:9.6.3-1PGDG.rhel6    postgresql96-libs.x86_64 0:9.6.3-1PGDG.rhel6   

Complete!
```

コンプリート！
早速起動するべ

```:コマンド
sudo service postgresql-9.6 initdb
```

```:実行結果
Initializing database:                                     [  OK  ]
```

```:コマンド
sudo service postgresql-9.6 start
```

```:実行結果
Starting postgresql-9.6 service:                           [  OK  ]
```

`sudo chkconfig postgresql-9.6 on`

## プロジェクト実行

```:コマンド
bundle exec rails new . --database=postgresql --skip-spring
```

```:実行結果
An error occurred while installing pg (0.20.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.20.0'` succeeds before bundling.
```

んー・・・

```:コマンド
sudo yum -y install postgresql-devel
```

```:実行結果
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: mirror.lzu.edu.cn
 * extras: www.ftp.ne.jp
 * updates: mirror.qoxy.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql-devel.x86_64 0:8.4.20-7.el6 will be installed
--> Processing Dependency: postgresql-libs(x86-64) = 8.4.20-7.el6 for package: postgresql-devel-8.4.20-7.el6.x86_64
--> Processing Dependency: postgresql(x86-64) = 8.4.20-7.el6 for package: postgresql-devel-8.4.20-7.el6.x86_64
--> Running transaction check
---> Package postgresql.x86_64 0:8.4.20-7.el6 will be installed
---> Package postgresql-libs.x86_64 0:8.4.20-7.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
 Package                     Arch              Version                 Repository       Size
=============================================================================================
Installing:
 postgresql-devel            x86_64            8.4.20-7.el6            base            816 k
Installing for dependencies:
 postgresql                  x86_64            8.4.20-7.el6            base            2.6 M
 postgresql-libs             x86_64            8.4.20-7.el6            base            202 k

Transaction Summary
=============================================================================================
Install       3 Package(s)

Total download size: 3.6 M
Installed size: 18 M
Downloading Packages:
(1/3): postgresql-8.4.20-7.el6.x86_64.rpm                             | 2.6 MB     00:02     
(2/3): postgresql-devel-8.4.20-7.el6.x86_64.rpm                       | 816 kB     00:00     
(3/3): postgresql-libs-8.4.20-7.el6.x86_64.rpm                        | 202 kB     00:00     
---------------------------------------------------------------------------------------------
Total                                                        427 kB/s | 3.6 MB     00:08     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : postgresql-libs-8.4.20-7.el6.x86_64                                       1/3 
  Installing : postgresql-8.4.20-7.el6.x86_64                                            2/3 
  Installing : postgresql-devel-8.4.20-7.el6.x86_64                                      3/3 
  Verifying  : postgresql-8.4.20-7.el6.x86_64                                            1/3 
  Verifying  : postgresql-devel-8.4.20-7.el6.x86_64                                      2/3 
  Verifying  : postgresql-libs-8.4.20-7.el6.x86_64                                       3/3 

Installed:
  postgresql-devel.x86_64 0:8.4.20-7.el6                                                     

Dependency Installed:
  postgresql.x86_64 0:8.4.20-7.el6           postgresql-libs.x86_64 0:8.4.20-7.el6          

Complete!
```
コンプリート！

```:コマンド
gem install pg -v '0.20.0'
```

```:実行結果
Building native extensions.  This could take a while...
Successfully installed pg-0.20.0
Parsing documentation for pg-0.20.0
Installing ri documentation for pg-0.20.0
Done installing documentation for pg after 2 seconds
1 gem installed
```

よし！今度こそ・・・

```:コマンド
bundle exec rails new . --database=postgresql --skip-spring
```

```:実行結果
Could not find gem 'pg (~> 0.20.0)' in any of the gem sources listed in your Gemfile or available on this machine.
Run `bundle install` to install missing gems.
```

反映されてない。。。

```:コマンド
rm Gemfile.lock
bundle install
bundle exec rails s -b 0.0.0.0
```

```:実行結果
/usr/local/lib/ruby/gems/2.3.1/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in
`rescue in block (2 levels) in require': There was an error while trying to load
 the gem 'uglifier'. (Bundler::GemRequireError)
```

むむむ・・・

```:コマンド
vi Gemfile
```


以下のコメントを外す
`// gem 'therubyracer', platforms: :ruby`

```:コマンド
bundle install
bundle exec rails s -b 0.0.0.0
```

やった！動いた！

ということで、エラーの解決含めて参考になれば。。。
というより、完全に~~備忘録~~作業記録でした