前回、Raisの勉強をはじめたつもりが、実はまだ始まってなかったようで、いつの間にかRailsのバージョンが4に。。。
とりあえず、今回はRVMでインストールしてみよう。
●rvmのインストール
[vagrant@localhost ~]$ curl -L get.rvm.io | bash -s stable
ではいるはずだけどエラーが出て怒られた。。。
エラーの内容に「これを試してみれ」と書いてあったので実行。
[vagrant@localhost ~]$ gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 4170B82D39DC0E303113804B9B6B1796C275462A
[vagrant@localhost ~]$ curl -L get.rvm.io | bash -s stable
今度は上手くインストールできた。
.bash_profileにrvmのパスの設定が勝手に追加されているので有効にします。
[vagrant@localhost ~]$ source .bash_profile
●rubyのインストール
[vagrant@localhost ~]$ rvm install 2.1.5
ちゃんと入ったっぽい
[vagrant@localhost ~]$ ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
●rails4用のgemの設定を追加
[vagrant@localhost ~]$ rvm gemset create rails4
ruby-2.1.5 - #gemset created /home/vagrant/.rvm/gems/ruby-2.1.5@rails4
ruby-2.1.5 - #generating rails4 wrappers........
[vagrant@localhost ~]$ rvm gemset use rails4 --default
Using ruby-2.1.5 with gemset rails4
[vagrant@localhost ~]$ rvm gemset list
gemsets for ruby-2.1.5 (found in /home/vagrant/.rvm/gems/ruby-2.1.5)
(default)
global
=> rails4
●railsのインストール
[vagrant@localhost ~]$ gem install rails --version "4.2.0" --nori --no-rdoc
●プロジェクトの作成
[vagrant@localhost ~]$ mkdir -p projects/rails
[vagrant@localhost ~]$ cd projects/rails/
[vagrant@localhost ~]$ rails new check_2ch
エラーが出て怒られたので、sqlite-develのインストール。
[vagrant@localhost ~]$ sudo yum install sqlite-devel
[vagrant@localhost ~]$ rails new check_2ch
今度は上手くいった
[vagrant@localhost ~]$ cd check_2ch/
[vagrant@localhost ~]$ bundle update
[vagrant@localhost ~]$ bundle install
[vagrant@localhost ~]$ rails server
エラーが出て怒られたので Gemfileを編集
[vagrant@localhost ~]$ vi Gemfile
# gem 'therubyracer', platforms: :ruby ← コメントを外す
[vagrant@localhost ~]$ bundle update
[vagrant@localhost ~]$ bundle install
[vagrant@localhost ~]$ rails server
ちゃんとport3000で動いた。