LoginSignup
3
4

More than 3 years have passed since last update.

Rubyをインストールする(macOS)

Posted at

rbenvを使ってRubyをインストールします(2020/1/7実施)

環境

macOS Catalina 10.15.2

Homebrewのインストール

こちらにアクセス

記載されているコマンドを実行します

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

完了確認

brew -v

バージョンが表示されて完了です

Homebrew 2.2.2

rbenvのインストール

こちらの手順通りコマンドを実行します

brew install rbenv

初期設定を行います

rbenv init

以下のように表示されました

# Load rbenv automatically by appending
# the following to ~/.bash_profile:

eval "$(rbenv init -)"

.bash_profileを開きます。なければ新規作成になります

vim ~/.bash_profile

.bash_profileに以下を追記しましょう

eval "$(rbenv init -)"

.bash_profileの変更を反映します

source ~/.bash_profile

正しく設定できたか確認

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

このような表示ならOKです

Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20191225)
Counting installed Ruby versions: none
  There aren't any Ruby versions installed under `/Users/username/.rbenv/versions'.
  You can install Ruby versions like so: rbenv install 2.2.4
Checking RubyGems settings: OK
Auditing installed plugins: OK

インストールできるRubyのバージョンを確認します

rbenv install -l

現時点での最新(2.7.0)をインストールします

rbenv install 2.7.0

インストールしたバージョンを有効化します

rbenv rehash

バージョンを確認します

rbenv versions

インストールされたバージョンが表示されます。「*」がついているものが設定されています

* system (set by /Users/username/.rbenv/version)
  2.7.0

バージョンを切り替えます

rbenv global 2.7.0

バージョンを確認します

ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]

これで完了です

3
4
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
3
4