LoginSignup
1
0

More than 1 year has passed since last update.

ruby-buildが失敗するときのおまじない🪄

Posted at

macOS上でrbenvを通してruby 3.2.2をインストールしようとしても、openssl関係のエラーでなかなかビルドが成功しませんでした。

The Ruby openssl extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Configure options used:
  --prefix=/Users/ricky/.rbenv/versions/3.0.4
  --enable-shared
  --with-readline-dir=/opt/homebrew/opt/readline
  --with-libyaml-dir=/opt/homebrew/opt/libyaml
  --with-openssl-dir=/usr/local/opt/openssl@1.1
  CC=clang
  LDFLAGS=-L/Users/ricky/.rbenv/versions/3.0.4/lib 
  CPPFLAGS=-I/Users/ricky/.rbenv/versions/3.0.4/include 

Githubで聞き回ったところ、コンパイル時のフラグ設定に問題があるようです。Rubyではopensslの最新バージョンでビルドせず、openssl@1.1でビルドしているそうです。[rbenvのメンテナーによるコメント]

ですので、以下のようにOpensslの対応バージョンをインストールします。

brew install openssl@1.1

そして以下のフラグを環境変数として設定します。

export LDFLAGS=-L/opt/homebrew/opt/openssl@1.1/lib
export CPPFLAGS=-I/opt/homebrew/opt/openssl@1.1/include

これでrubyがインストールできるようになりました。

➜  ~ rbenv install 3.2.2
To follow progress, use 'tail -f /var/folders/t0/m8gzjl_n0cl7gmf8pg27fw380000gn/T/ruby-build.20230412150851.53584.log' or pass --verbose
Downloading ruby-3.2.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz
Installing ruby-3.2.2...
ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
Installed ruby-3.2.2 to /Users/ricky/.rbenv/versions/3.2.2

やれやれ、この問題を解決するのに数時間ぐらい掛かったよー
皆さんにはこのように苦労して欲しくないので、このQiitaを書きました。

1
0
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
1
0