Macのrbenvでインストールエラー

久しぶりにrbenvでRuby2.3.0をインストールしようとしたところ、エラーでインストールできなかった。 OpenSSLとcurlのバージョンを上げることでインストールできるようになった。

環境

rbenv installで出たエラー

$ rbenv install 2.3.0
ruby-build: use openssl from homebrew
Downloading ruby-2.3.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.bz2
error: failed to download ruby-2.3.0.tar.bz2

BUILD FAILED (OS X 10.12.6 using ruby-build 20180424-3-g16ac342)

対応

  • OpenSSLとcurlのバージョンを上げる。

Googleで検索すると、Linuxでの同様のエラーがすでに報告されているようだが、Macでも同様の対応方法で解決できた。 バージョンアップの前後のOpenSSLとcurlのバージョンは以下の通り。

VerUp前    VerUp後
OpenSSL OpenSSL 0.9.8zh 14 Jan 2016 OpenSSL 1.0.2o 27 Mar 2018
curl curl 7.54.0 (x86_64-apple-darwin16.0) libcurl/7.54.0 SecureTransport zlib/1.2.8 curl 7.60.0 (x86_64-apple-darwin16.7.0) libcurl/7.60.0 SecureTransport zlib/1.2.8

OpenSSLのインストール

以前Homebrewでインストールしていたようなので、再インストールした。

$ brew reinstall openssl
==> Reinstalling openssl 
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2o_1.sierra.bottle.tar.gz
Already downloaded: /Users/razgriz1/Library/Caches/Homebrew/openssl-1.0.2o_1.sierra.bottle.tar.gz
==> Pouring openssl-1.0.2o_1.sierra.bottle.tar.gz
==> 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,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2o_1: 1,791 files, 12.3MB

HomebrewでインストールしたOpenSSLは、PATHに設定されていないようなので、インストールコマンドを打った後にした後に表示されるコメントのコマンドを実行し、HomebrewでインストールしたOpenSSLをPATHに通す。

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
$ echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ openssl version
OpenSSL 1.0.2o  27 Mar 2018

OpenSSLのバージョンが1.0.2oになった。

curlの新しいバージョンをインストール

OpenSSL同様にHomebrewでインストールする。

$ brew install curl
==> Downloading https://homebrew.bintray.com/bottles/curl-7.60.0.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring curl-7.60.0.sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/curl/lib
    CPPFLAGS: -I/usr/local/opt/curl/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/curl/lib/pkgconfig

==> Summary
🍺  /usr/local/Cellar/curl/7.60.0: 423 files, 3MB

こちらもインストール直後はPATHが通っていないようなので、OpenSSL同様に、インストール後の標準出力を参考に、インストールしたcurlをPATHに通してやる。

$ echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ curl -V
curl 7.60.0 (x86_64-apple-darwin16.7.0) libcurl/7.60.0 SecureTransport zlib/1.2.8
Release-Date: 2018-05-16

rbenvでRubyをインストール

OpenSSL、curlをバージョンアップした後、めでたくrbenvでRuby2.3.0をインストールできた。

$ rbenv install 2.3.0
ruby-build: use openssl from homebrew
Downloading ruby-2.3.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.bz2
Installing ruby-2.3.0...
ruby-build: use readline from homebrew
Installed ruby-2.3.0 to /Users/razgriz1/.rbenv/versions/2.3.0