LoginSignup
35
35

More than 5 years have passed since last update.

rbenvでRuby2.1.3,Rails4.1.6インストール on CentOS6.5 (Vagrant)

Last updated at Posted at 2014-09-18

前回、VirtualBox + vagrantで仮想環境を作成したcentos6.5にrubyの開発環境を作っていきます。

※前回はこちら
http://qiita.com/icche/items/571ad97680a13836c404

0. 事前準備

vagrantを起動してアクセス。

vagrant up
vagrant ssh

以下、gitが必要になりますが、前回作成したcentos6.5にはgitはインストール済みなので、gitインストールは省略します。

下記コマンドで必要なパッケージを入手

yum install -y gcc gcc-c++ make git openssl-devel

※JRubyを使うときはJavaをインストールして下さい。
※javaのインストールはこちら。
http://qiita.com/icche/items/d1dd976d8cb9221f11d7

1. rbenvのインストール

rbenv を ~/.rbenv (ホームディレクトリ直下の .rbenv フォルダ) にgit cloneします。

$ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv

続いて、ruby-buildプラグインのインストール

$ mkdir -p ~/.rbenv/plugins
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ cd ~/.rbenv/plugins/ruby-build
$ sudo ./install.sh

rbenv のコマンドが使えるよう、環境変数の設定

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

以下のコマンドのでrbenvの確認。

$ rbenv
rbenv 0.4.0-98-g13a474c

2. Rubyのインストール

rbenvでインストールできるパッケージを確認する。

$ rbenv install -l

現時点で最新の安定版2.1.3をインストールする。

$ rbenv install 2.1.3

※OpenSSLが入っていない怒られた場合は、インストールしてから再度rubyをインストール

$ sudo yum -y install openssl openssl-devel
$ rbenv install 2.1.3

rehashしてruby 2.1.3を標準に

$ rbenv rehash
$ rbenv global 2.1.3

rubyのバージョン確認

$ ruby -v
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]

3. Bundlerのインストール

Bundlerを単品でインストール

$ rbenv exec gem install bundler

インストールしたので rehash する

$ rbenv rehash

バージョンを確認する

$ bundler -v
Bundler version 1.11.2

あとは、Railsのプロジェクトrootで

$ bundle install --path=vendor/bundle

必要に応じて

$ bundle exec rake db:create
$ bundle exec rake db:migrate
$ bundle exec rake db:seed

お疲れ様でした♪

35
35
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
35