あかんわ

ブログで日誌でも書くようにすれば多少はやる気が出るかと思ったんです

Macのrbenvで追加されたばかりのRuby2.4.0を使う手順

Homebrewupdateして最新にして*1ruby-build*2upgradeして最新にしたら、rbenvのリストにRuby 2.4.0が表示されてインストールできました。

$brew update
$brew upgrade ruby-build
$rbenv install 2.4.0

ついでに、Ruby 2.4.0Bundlerが使えるようにしておきます。

$rbenv global 2.4.0
$gem install bundler

今までruby-buildの存在を知らずにrbenvを使っており、何も考えずにrbenv installしようとして所々で躓いたので書き留めておきます。

邂逅

rbenvにRuby2.4.0が追加されたと知り、rbenv install -lしてみるもRuby 2.4.0が表示されなくて困惑しました。

$rbenv install -l                        
Available versions:
・
・
・
  2.3.0
  2.4.0-dev
  jruby-1.5.6
・
・
・

2.4.0-dev?(´゚д゚`)

錯綜

『rbenv 表示されない』で検索してみたら、こちらの記事にそのものズバリな内容が記載されていたので、そういえば長いことupdateしてないな〜とか考えながらbrew updateをしてみたらErrorが出ました。

$brew update
Error: /usr/local must be writable!

oh…(;´Д`)

なにやら見覚えのある/usr/local must be writable!の文字に、あ〜これEl Capitanになった時にセキュリティのやつであったな〜と考え、『elcapitan homebrew』で検索して辿り着いたこちらの記事を参考に/usr/localパーミッションを修正しました。

$sudo chown -R $(whoami):admin /usr/local

掃討

パーミッションを修正したら無事にbrew updateできるようになり、Ruby 2.4.0のインストールもできました。

brew update
$brew update
==> Migrating Homebrew to v0.9.9
remote: Counting objects: 954, done.
remote: Compressing objects: 100% (890/890), done.
remote: Total 954 (delta 182), reused 301 (delta 38), pack-reused 0
Receiving objects: 100% (954/954), 895.72 KiB | 219.00 KiB/s, done.
Resolving deltas: 100% (182/182), completed with 105 local objects.
From https://github.com/Homebrew/brew
 + 5a9e19f...aaf70eb master     -> origin/master  (forced update)
HEAD is now at aaf70eb Merge pull request #1676 from MikeMcQuaid/doctor-tap-repo-bad-ruby-files
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  https://git.io/brew-analytics

==> Tapping homebrew/core
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 3801, done.
remote: Compressing objects: 100% (3683/3683), done.
remote: Total 3801 (delta 20), reused 318 (delta 6), pack-reused 0
Receiving objects: 100% (3801/3801), 3.03 MiB | 381.00 KiB/s, done.
Resolving deltas: 100% (20/20), done.
Checking connectivity... done.
Tapped 3677 formulae (3,829 files, 9.5M)
Already up-to-date.
==> Migrating HOMEBREW_REPOSITORY (please wait)...
==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!
Homebrew no longer needs to have ownership of /usr/local. If you wish you can
return /usr/local to its default ownership with:
  sudo chown root:wheel /usr/local
brew upgrade ruby-build
$brew upgrade ruby-build
Updating Homebrew...
==> Upgrading 1 outdated package, with result:
ruby-build 20161225
==> Upgrading ruby-build 
==> Installing dependencies for ruby-build: pkg-config, openssl
==> Installing ruby-build dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.1_2.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.29.1_2.el_capitan.bottle.tar.gz
?  /usr/local/Cellar/pkg-config/0.29.1_2: 10 files, 627.4K
==> Installing ruby-build dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2j.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2j.el_capitan.bottle.tar.gz
==> Using the sandbox
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, youll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include
    PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

==> Summary
?  /usr/local/Cellar/openssl/1.0.2j: 1,695 files, 12M
==> Installing ruby-build 
==> Downloading https://github.com/rbenv/ruby-build/archive/v20161225.tar.gz
==> Downloading from https://codeload.github.com/rbenv/ruby-build/tar.gz/v20161225
######################################################################## 100.0%
==> ./install.sh
?  /usr/local/Cellar/ruby-build/20161225: 323 files, 173.7K, built in 8 seconds
rbenv install -l
$rbenv install -l                        
Available versions:
・
・
・
  2.3.0
  2.3.1
  2.3.2
  2.3.3
  2.4.0-dev
  2.4.0-preview1
  2.4.0-preview2
  2.4.0-preview3
  2.4.0-rc1
  2.4.0
  jruby-1.5.6
・
・
・
rbenv install 2.4.0
$rbenv install 2.4.0
Downloading ruby-2.4.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.0.tar.bz2
Installing ruby-2.4.0...
Installed ruby-2.4.0 to /Users/b0npu/.rbenv/versions/2.4.0
gem install bundler
$rbenv global 2.4.0
$gem install bundler
Fetching: bundler-1.13.7.gem (100%)
Successfully installed bundler-1.13.7
1 gem installed

参考記事

qiita.com qiita.com

開発環境

*1:Macのセキュリティ機能SIPのおかげで少し手間取りました

*2:rbenv installコマンドを提供しているrbenvのプラグイン