Linux環境でのrubyのインストール方法。
全ユーザで使用できるようにインストールを行う。
前提
以下をインストールしておく。
なお、操作は全てrootユーザで行う。
- git
bash
yum install git
- その他
bash
yum install gcc openssl-devel libyaml-devel readline-devel zlib-devel
rbenvとruby-buildをインストール
bash
git clone https://github.com/sstephenson/rbenv.git /usr/local/rbenv
git clone https://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build
echo 'export RBENV_ROOT="/usr/local/rbenv"' >> /etc/profile.d/rbenv.sh
echo 'PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh
echo 'export PATH' >> /etc/profile.d/rbenv.sh
echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh
source ~/.bash_profile
rbenv --version
Rubyをインストール
インストール可能なRubyのバージョンの一覧を表示する
bash
rbenv install --list
表示されたバージョンから任意のものを選び、以下を実行
bash
rbenv install 2.1.2 #2.1.2を選んだ場合
インストールが完了したら、使用するRubyのバージョンを指定する
bash
rbenv global 2.1.2 #2.1.2を選んだ場合
rbenv rehash
Bundllerをインストール
bash
rbenv exec gem install bundler
rbenv rehash
その他
インストール済みのRubyのバージョンを表示する
bash
rbenv versions
ディレクトリ毎にrubyのバージョンを変える
bash
rbenv local 2.1.2 #2.1.2を選んだ場合