LoginSignup
5
6

More than 5 years have passed since last update.

Mac に rbenv を利用して Ruby をインストールする

Last updated at Posted at 2018-08-02

Mac に rbenv を利用して Ruby をインストールする手順。

xcode-select のインストール

$ xcode-select --install

rbenv のインストール

Homebrew でもインストールできるが、 git clone でインストールする。手順は rbenv のドキュメントを参照する。

$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ cd ~/.rbenv && src/configure && make -C src

.bash_profile に下記を追記する。

# rbenv
export RBENV_ROOT="$HOME/.rbenv"
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

.bash_profile を読み込む。

$ source .bash_profile

ruby-build の plugin を入れる。

$ mkdir -p "$(rbenv root)"/plugins
$ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

rbenv の使い方

インストール可能なバージョンを確認する。

$ rbenv install -l

指定のバージョンをインストールする。

$ rbenv install 2.4.3
$ rbenv rehash

指定のバージョンをグローバルで利用する。

$ rbenv global 2.4.3

指定のバージョンをローカル(そのディレクトリ)で利用する。

$ rbenv local 2.4.3

マシンにインストールされているバージョンを確認する。

$ rbenv versions

rbenv を更新する方法

$ cd $(rbenv root)
$ git pull

ruby-build を更新する方法

$ cd "$(rbenv root)"/plugins/ruby-build
$ git pull
5
6
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
5
6