rbenvでruby 2.1.2をインストールしようとしたらエラーが発生して、思った以上に時間がかかってしまいました。最終的にインストールできた対処策をお伝えします。
エラー発生
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$ rbenv install 2.1.2 ruby-build: use openssl from homebrew Downloading ruby-2.1.2.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.bz2 Installing ruby-2.1.2... WARNING: ruby-2.1.2 is past its end of life and is now unsupported. It no longer receives bug fixes or critical security updates. ruby-build: use readline from homebrew BUILD FAILED (OS X 10.13.2 using ruby-build 20190423) Inspect or clean up the working tree at /var/folders/vc/3xzdspjn5_j53wlgmf23prsh0000gn/T/ruby-build.20200320165134.55679 Results logged to /var/folders/vc/3xzdspjn5_j53wlgmf23prsh0000gn/T/ruby-build.20200320165134.55679.log Last 10 log lines: The Ruby openssl extension was not compiled. ERROR: Ruby install aborted due to missing extensions Configure options used: --prefix=/Users/XXXX/.rbenv/versions/2.1.2 --with-openssl-dir=/usr/local/opt/openssl@1.1 --with-readline-dir=/usr/local/opt/readline CC=clang CFLAGS= -O3 -Wno-error=shorten-64-to-32 LDFLAGS=-L/Users/XXXX/.rbenv/versions/2.1.2/lib CPPFLAGS=-I/Users/XXXX/.rbenv/versions/2.1.2/include |
OS X : 10.13.2(17C88)
発生日:2020/3/20
対処策
色々試したのですが、結論から言うと brew upgrade ruby-build をしたらインストールできました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
$ brew upgrade ruby-build Updating Homebrew... ==> Upgrading 1 outdated package: ruby-build 20190615 -> 20200224 ==> Upgrading ruby-build 20190615 -> 20200224 ==> Downloading https://github.com/rbenv/ruby-build/archive/v20200224.tar.gz ==> Downloading from https://codeload.github.com/rbenv/ruby-build/tar.gz/v20200224 ######################################################################## 100.0% ==> ./install.sh ==> Caveats ruby-build installs a non-Homebrew OpenSSL for each Ruby version installed and these are never upgraded. To link Rubies to Homebrew's OpenSSL 1.1 (which is upgraded) add the following to your ~/.bash_profile: export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" Note: this may interfere with building old versions of Ruby (e.g <2.4) that use OpenSSL <1.1. ==> Summary 🍺 /usr/local/Cellar/ruby-build/20200224: 473 files, 236.6KB, built in 5 seconds Removing: /usr/local/Cellar/ruby-build/20190615... (448 files, 224.6KB) ==> Checking for dependents of upgraded formulae... ==> Upgrading 1 dependent: rbenv 0.4.0 -> 1.1.2 ==> Upgrading rbenv 0.4.0 -> 1.1.2 ==> Downloading https://homebrew.bintray.com/bottles/rbenv-1.1.2.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring rbenv-1.1.2.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/rbenv/1.1.2: 36 files, 65KB Removing: /usr/local/Cellar/rbenv/0.4.0... (32 files, 49.6KB) ==> Checking for dependents of upgraded formulae... Error: No such file or directory - /usr/local/Cellar/rbenv/0.4.0 |
この後に、 rbenv install 2.1.2 をすると
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ rbenv install 2.1.2 Downloading openssl-1.0.2u.tar.gz... -> https://dqw8nmjcqpjn7.cloudfront.net/ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16 Installing openssl-1.0.2u... Installed openssl-1.0.2u to /Users/XXXX/.rbenv/versions/2.1.2 Downloading ruby-2.1.2.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.bz2 Installing ruby-2.1.2... WARNING: ruby-2.1.2 is past its end of life and is now unsupported. It no longer receives bug fixes or critical security updates. ruby-build: using readline from homebrew Installed ruby-2.1.2 to /Users/XXXX/.rbenv/versions/2.1.2 $ rbenv global 2.1.2 $ ruby -v ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin17.0] |
きちんとインストールできました。
この記事にruby-buildを最新版にしようということが書いていたのですが、ruby-buildの更新の仕方について、rbenv pluginというのを使うと書いていたのですが、ruby-buildのgithubページを見ると、homebrewでinstallしていたので、最初は brew install ruby-build しました。すると、
1 2 |
Error: ruby-build 20190615 is already installed To upgrade to 20200224, run `brew upgrade ruby-build`. |
と表示されたので、brew upgrade ruby-build
をしました。
rbenv pluginでやった方がよかったのかはわかりません。とりあえず動いたのでよしとしました。
経緯
推測ですが、python3をhomebrewで入れた際に、homebrew update かupgradeが走ったか、自分で実行してしまい、opensslのバージョンが上がってしまったのが根本的な原因だと考えています。
その後、pryをすると以下のようなエラーが出たので、
1 2 3 4 |
$ pry Sorry, you can't use byebug without Readline. To solve this, you need to rebuild Ruby with Readline support. If using Ubuntu, try `sudo apt-get install libreadline-dev` and then reinstall your Ruby. |
上の記事を見て、もともとインストールされていたruby 2.1.2をuninstallし、再installしようとしたら、冒頭のエラーが出てしまったということです。
ちなみに、pryのエラーの他に、次の記事に書いたように、middlemanというrubyのツールを起動する時もエラーが発生していました。
今考えると、rubyの再インストールしなくても、次の章で紹介するリンクの張り替えやPATHを通すだけでもpryは動いたのかもしれません。
対処策に至るまでに他に試した事
対処策にたどり着く前に、次のことを試しました。もしかしたら、これとの合わせ技で、動いたのかもしれません。
上述した対処策で動かなかった場合は、以下もためして見てください。
opensslのpathを指定してrbenv install
1 |
$ RUBY_CONFIGURE_OPTS="--with-readline-dir=`brew --prefix readline` --with-openssl-dir=`brew --prefix openssl`" rbenv install 2.1.2 |
1 |
$ RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/local/Cellar/openssl/1.0.2s rbenv install 2.1.2 |
1 |
$ RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/local/Cellar/openssl rbenv install 2.1.2 |
opensslの再install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
$ brew reinstall openssl@1.1 ==> Reinstalling openssl@1.1 ==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1d.high_sierra.bottle.tar.gz Already downloaded: /Users/XXXX/Library/Caches/Homebrew/downloads/3e87a1132e64eed274a253d12489b47f7f8dd5350d00a036efeab0d443ea0728--openssl@1.1-1.1.1d.high_sierra.bottle.tar.gz ==> Pouring openssl@1.1-1.1.1d.high_sierra.bottle.tar.gz ==> Caveats A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because openssl/libressl is provided by macOS so don't link an incompatible version. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" For pkg-config to find openssl@1.1 you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" ==> Summary 🍺 /usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB Removing: /usr/local/Cellar/openssl@1.1/1.1.1c... (7,963 files, 17.9MB) |
uninstallしてからのinstallもしてみました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
$ brew uninstall openssl@1.1 Error: Refusing to uninstall /usr/local/Cellar/openssl@1.1/1.1.1d because it is required by ansible, apr-util, berkeley-db, fuse-emulator, glib, gnutls, httpd, jack, lftp, libevent, libspectrum, libxml2, libxslt, macvim, mercurial, mysql, nghttp2, php-build, postgresql, pyenv, python, ruby, ruby-build, subversion, tmux, vim and wget, which are currently installed. You can override this and force removal with: brew uninstall --ignore-dependencies openssl@1.1 $ $ brew uninstall --ignore-dependencies openssl@1.1 Uninstalling /usr/local/Cellar/openssl@1.1/1.1.1d... (7,983 files, 17.9MB) $ openssl version LibreSSL 2.2.7 $ brew install openssl ==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1d.high_sierra.bottle.tar.gz Already downloaded: /Users/XXXX/Library/Caches/Homebrew/downloads/3e87a1132e64eed274a253d12489b47f7f8dd5350d00a036efeab0d443ea0728--openssl@1.1-1.1.1d.high_sierra.bottle.tar.gz ==> Pouring openssl@1.1-1.1.1d.high_sierra.bottle.tar.gz ==> Caveats A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because openssl/libressl is provided by macOS so don't link an incompatible version. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" For pkg-config to find openssl@1.1 you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" ==> Summary 🍺 /usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB |
brew link --force openssl
1 2 3 4 5 6 7 8 9 10 11 |
$ brew link --force openssl Warning: Refusing to link macOS-provided software: openssl@1.1 If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" For pkg-config to find openssl@1.1 you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" |
openssl@1.1にPATHを通す
1 |
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile |
brew switch openssl 1.0.2s
1 2 3 |
$ brew switch openssl 1.0.2s Cleaning /usr/local/Cellar/openssl/1.0.2s Opt link created for /usr/local/Cellar/openssl/1.0.2s |
どうもopensslの1.0系が必要な感じがしたのでこれをやってみました。
ちなみに、インストールしたはずのより新しい1.1.1dを指定するとエラーが発生します。不思議ですね。
1 2 3 |
$ brew switch openssl 1.1.1d Error: openssl does not have a version "1.1.1d" in the Cellar. openssl's installed versions: 1.0.2s |
これは、もちろん、 brew reinstall openssl@1.1 した後にやっています。
奇妙なopensslのバージョン認識
ちなみに、ここまで紹介opensslをアップデートしたり、リンクを変えたりするなどの対策を紹介しましたが、何をやっても、 brew list openssl をやると一貫して以下のように1.0.2sが表示されるんですよね。
1 2 3 4 5 6 7 8 9 10 11 |
$ brew list openssl /usr/local/Cellar/openssl/1.0.2s/.bottle/etc/ (8 files) /usr/local/Cellar/openssl/1.0.2s/bin/c_rehash /usr/local/Cellar/openssl/1.0.2s/bin/openssl /usr/local/Cellar/openssl/1.0.2s/include/openssl/ (75 files) /usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.1.0.0.dylib /usr/local/Cellar/openssl/1.0.2s/lib/libssl.1.0.0.dylib /usr/local/Cellar/openssl/1.0.2s/lib/engines/ (12 files) /usr/local/Cellar/openssl/1.0.2s/lib/pkgconfig/ (3 files) /usr/local/Cellar/openssl/1.0.2s/lib/ (4 other files) /usr/local/Cellar/openssl/1.0.2s/share/man/ (1683 files) |
でも、 brew info openssl をすると、新しいバージョンの1.1.1dと表示されます。不思議です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
$ brew info openssl openssl@1.1: stable 1.1.1d (bottled) [keg-only] Cryptography and SSL/TLS Toolkit https://openssl.org/ /usr/local/Cellar/openssl@1.1/1.1.1d (7,983 files, 17.9MB) Poured from bottle on 2020-03-20 at 17:43:23 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openssl@1.1.rb ==> Caveats A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because openssl/libressl is provided by macOS so don't link an incompatible version. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" For pkg-config to find openssl@1.1 you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" ==> Analytics install: 421,008 (30 days), 1,236,782 (90 days), 3,710,458 (365 days) install-on-request: 53,002 (30 days), 170,219 (90 days), 532,814 (365 days) build-error: 0 (30 days) |