LoginSignup
13
17

More than 5 years have passed since last update.

rbenvで複数のバージョンのRubyを管理する

Posted at

はじめに

rbenvで複数のバージョンのRubyを管理する方法を記述します。
なお、Rubyのインストールには、ruby-buildを使用します。

環境

  • CentOS 6.5
  • git 1.7.1

gitのインストール

$ sudo yum install git

rbenvのインストール

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ type rbenv
rbenv is a function
rbenv ()
{
...(省略)...
}

ruby-buildのインストール

推奨されているとおりにrbenvのプラグインとしてインストールします。

pluginsディレクトリが存在しないため、gitからcloneする際に
ディレクトリも作成します。

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv install --version
ruby-build 20140702-16-g85369d2

rubyのインストール

  • 必要なパッケージのインストール
$ sudo yum install gcc openssl-devel

2.0.0-p481 では、 openssl-devel が必要となります。

  • インストール可能なRubyのバージョンを確認します。
$ rbenv install --list
Available versions:
  1.8.6-p383
  1.8.6-p420
  1.8.7-p249
...(省略)...
  • 1.8.6-p420をインストール
$ rbenv install 1.8.6-p420
$ rbenv versions
  1.8.6-p420
  • 1.9.3-p547をインストール
$ rbenv install 1.9.3-p547
$ rbenv --versions
  1.8.6-p420
  1.9.3-p547
  • 2.0.0-p481をインストール
$ rbenv install 2.0.0-p481
$ rbenv versions
  1.8.6-p420
  1.9.3-p547
  2.0.0-p481
  • 2.1.2をインストール
$ rbenv install 2.1.2
$ rbenv versions
  1.8.6-p420
  1.9.3-p547
  2.0.0-p481
  2.1.2

バージョンの切替

  • デフォルトのバージョンを2.1.2とする
$ rbenv global 2.1.2
$ rbenv version
2.1.2 (set by ~/.rbenv/version)
$ rbenv versions
  1.8.6-p420
  1.9.3-p547
  2.0.0-p481
* 2.1.2 (set by ~/.rbenv/version)
$ ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
  • 2.0.0-p481を利用する
$ mkdir -p ~/src/ruby/2.0.0
$ cd src/ruby/2.0.0
$ rbenv local 2.0.0-p481
$ rbenv version
2.0.0-p481 (set by ~/src/ruby/2.0.0/.ruby-version)
$ ruby --version
  • 1.9.3-p547を利用する
$ mkdir -p ~/src/ruby/1.9.3
$ cd ~/src/ruby/1.9.3
$ rbenv local 1.9.3-p547
$ rbenv version
1.9.3-p547 (set by ~/src/ruby/1.9.3/.ruby-version)
$ ruby --version
ruby 1.9.3p547 (2014-05-14 revision 45962) [x86_64-linux]

参考

*rbenv
*ruby-build
*rbenv を利用した Ruby 環境の構築
*Ruby 2.1.0 以降のセマンティックバージョニングについて

13
17
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
13
17