LoginSignup
20
9

More than 1 year has passed since last update.

最新版のruby-buildを入れているとRubyをインストール出来ない問題の対処法(暫定版)

Last updated at Posted at 2022-07-12

こんにちはRUNTEQで開発TA(エンジニア & 講師の補佐)をしているふぁらおです
今回は昨日(2022/07/12)から受講生がはまっているエラーがなかなか初学者にはしんどそうなので解決法を書いていきます
新しいruby-buildを入れると起こるようです(私のはruby-build: stable 20220710 (bottled))
最新版のruby-build(私のやつはruby-build 20220910.1)では解決済みかと思われます

環境(intel版でも発生を確認しています)

OS: macOS Monterey(12.4)
チップ: Apple M1

エラー内容

rbenvでrubyをインストールしようとするとInstalling openssl-1.1.1q...と出た後にエラーが出てインストールが出来ない

実際のターミナル

❯❯❯ RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.5.1
Downloading openssl-1.1.1q.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/d7939ce614029cdff0b6c20f0e2e5703158a489a72b2507b8bd51bf8c8fd10ca
Installing openssl-1.1.1q...

BUILD FAILED (macOS 12.4 using ruby-build 20220710-2-gd6481c8)

Inspect or clean up the working tree at /var/folders/kx/g8d12w2x353c1lqh93cvl2380000gn/T/ruby-build.20220712164345.15421.4AbMnQ
Results logged to /var/folders/kx/g8d12w2x353c1lqh93cvl2380000gn/T/ruby-build.20220712164345.15421.log

Last 10 log lines:
clang  -Iinclude -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DZLIB_SHARED -DNDEBUG -I/Users/kenchaso/.anyenv/envs/rbenv/versions/2.5.1/include  -MMD -MF test/v3nametest.d.tmp -MT test/v3nametest.o -c -o test/v3nametest.o test/v3nametest.c
clang  -Iinclude -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DZLIB_SHARED -DNDEBUG -I/Users/kenchaso/.anyenv/envs/rbenv/versions/2.5.1/include  -MMD -MF test/verify_extra_test.d.tmp -MT test/verify_extra_test.o -c -o test/verify_extra_test.o test/verify_extra_test.c
test/v3ext.c:201:24: error: implicitly declaring library function 'memcmp' with type 'int (const void *, const void *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
        if (!TEST_true(memcmp(ip1->data, ip2->data, ip1->length) <= 0))
                       ^
test/v3ext.c:201:24: note: include the header <string.h> or explicitly provide a declaration for 'memcmp'
1 error generated.
make[1]: *** [test/v3ext.o] Error 1
make[1]: *** Waiting for unfinished jobs....

2022/8/1追記

Rubyの3.1.x系以降を使用する場合は20220721版からオプションを追記せずにインストールすることが出来るようになったようです(3.1.2をインストール出来ることを確認済み)
それ以前のものに関しては私の環境ではまだ下記に従ってオプションをつけないとインストール出来ないようです
withelmoさんコメントありがとうございます

2022/7/20追記

C言語のコンパイラのClangでエラーが出るようになっている設定を警告に変更するオプションを付けるとインストール出来るようになる

対処法

rbenv installの際にOPENSSL_CFLAGS=-Wno-error=implicit-function-declarationを書いてオプションを設定する

OPENSSL_CFLAGS=-Wno-error=implicit-function-declaration rbenv install Rubyのバージョン

M1で古いRubyをインストールするときは下記のようなイメージ

❯ OPENSSL_CFLAGS=-Wno-error=implicit-function-declaration RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.5.1
Downloading openssl-1.1.1q.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/d7939ce614029cdff0b6c20f0e2e5703158a489a72b2507b8bd51bf8c8fd10ca
Installing openssl-1.1.1q...
Installed openssl-1.1.1q to /Users/kenchaso/.anyenv/envs/rbenv/versions/2.5.1

Downloading ruby-2.5.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.bz2
Installing ruby-2.5.1...

WARNING: ruby-2.5.1 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.5.1 to /Users/kenchaso/.anyenv/envs/rbenv/versions/2.5.1

rubyのインストール時に使うopensslをHomebrewで入れたものを使うように環境変数を指定する方法

対処法(これではインストール出来ない事例あり)

echo "$(brew --prefix openssl@1.1)"でなんかパスっぽいものが出るか確認する(人によって違います私の場合は/opt/homebrew/opt/openssl@1.1)
上記でなんかパスっぽいものが出たら
export RUBY_CONFIGURE_OPTS="--with-openssl-dir='$(brew --prefix openssl@1.1)'"
を打っていつも通りrbenv install バージョンを打つと解決するはず

対処方法(これではインストール出来ない事例あり)

Homebrewでopenssl@1.1のインストール(既にインストールしている方は飛ばしてください)

  • brew install openssl@1.1
If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> /Users/kenchaso/.zshrc

みたいなのが出ていたら自分のターミナルに出ているものを実行して設定ファイルを再読み込みしてください(今回の場合はsource ~/.zshrc)

openssl@1.1の場所の確認

  • echo "$(brew --prefix openssl@1.1)"
❯❯❯ echo "$(brew --prefix openssl@1.1)"
/opt/homebrew/opt/openssl@1.1

Rubyをインストールするときのopensslを指定する

  • export RUBY_CONFIGURE_OPTS="--with-openssl-dir=echo '$(brew --prefix openssl@1.1)'"

rbenvでRubyをインストールする

rbenv install バージョン

参考

opensslのバグらしい...?
https://github.com/rbenv/ruby-build/issues/1998#issuecomment-1180691799
https://github.com/openssl/openssl/issues/18720
https://clang.llvm.org/docs/UsersManual.html#cmdoption-wno-error
https://clang.llvm.org/docs/DiagnosticsReference.html#wimplicit-function-declaration
https://github.com/rbenv/ruby-build/pull/2000

最後に

  • 別の解決方法や、私の理解が間違っているところがあったら教えていただけると大変助かります
  • 初学者には環境構築のエラーはなかなかきついのではと思っているのでなにか参考になれば幸いです
20
9
2

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
20
9