LoginSignup
7
4
記事投稿キャンペーン 「2024年!初アウトプットをしよう」

rbenv install 3.3.0でerror: something wrong with LDFLAGS=""が出た時の備忘録

Last updated at Posted at 2024-01-08

rbenv install 3.3.0を実行すると、エラーが生じた。

実行環境: MacOS M2チップ

$ rbenv install 3.3.0

ruby-build: using openssl@3 from homebrew
==> Downloading ruby-3.3.0.tar.gz...
-> curl -q -fL -o ruby-3.3.0.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.0M  100 21.0M    0     0  21.7M      0 --:--:-- --:--:-- --:--:-- 21.7M
==> Installing ruby-3.3.0...
ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
-> ./configure "--prefix=$HOME/.rbenv/versions/3.3.0" --with-openssl-dir=/opt/homebrew/opt/openssl@3 --enable-shared --with-readline-dir=/opt/homebrew/opt/readline --with-libyaml-dir=/opt/homebrew/opt/libyaml --with-ext=openssl,psych,+

BUILD FAILED (macOS 14.2 on arm64 using ruby-build 20231225)

You can inspect the build directory at /var/folders/bn/6ryb3pn1299_xr2sbqcb5k5h0000gn/T/ruby-build.20240108105928.26890.0Aoa2w
See the full build log at /var/folders/bn/6ryb3pn1299_xr2sbqcb5k5h0000gn/T/ruby-build.20240108105928.26890.log

エラーが生じ、ビルドログを見てということなので、見てみると下記の記述がある。(一部抜粋)

checking whether LDFLAGS is valid... no
configure: error: something wrong with LDFLAGS=""
external command failed with status 1

ログはLDFLAGSに問題があると言うことを示唆しているが、結論から言うとLDFLAGS以外に問題がある。ChatGPTの言う通りにLDFLAGSのパスを通してもエラーが解決されることはなかった。
ChatGPTに促されて打ったコマンド(打たなくていい):

$ export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/libyaml/lib"

私が問題だった点

別の機会にMySQLを導入する際にzstdとopenssl@3をインストールしていたが、その時に通したパスに問題があった。

$ export -p

~~(省略)~~
export LIBRARY_PATH=:/opt/homebrew/Cellar/zstd/1.5.2/lib:/opt/homebrew/Cellar/openssl@3/3.0.1m/lib/:/opt/homebrew/opt/zstd/lib
~~(省略)~~

ここで、zstdのバージョンは1.5.2、openssl@3のバージョンは3.0.1mを指定している。おそらくどこかの記事をそのままコピペした時の名残だと思われる。しかし、自分のローカルにインストールしているライブラリのバージョンを確認してみると、状況が違うことがわかる。

$ ls /opt/homebrew/Cellar/zstd/1.5.2/lib
ls: /opt/homebrew/Cellar/zstd/1.5.2/lib: No such file or directory

$ ls /opt/homebrew/Cellar/zstd/ 
1.5.5
$ ls /opt/homebrew/Cellar/openssl@3/3.0.1m/lib 
ls: /opt/homebrew/Cellar/openssl@3/3.0.1m/lib: No such file or directory

$ ls /opt/homebrew/Cellar/openssl@3
3.2.0_1

正しいバージョンに揃える必要がありそうなので、パスを消去してから、設定し直す。

$ unset LIBRARY_PATH
$ export LIBRARY_PATH=:/opt/homebrew/Cellar/zstd/1.5.5/lib:/opt/homebrew/Cellar/openssl@3/3.2.0_1/lib/:/opt/homebrew/opt/zstd/lib

パスを設定し直したところで再びruby 3.3.0をインストールすると、成功した。

$ rbenv install 3.3.0

ruby-build: using openssl@3 from homebrew
==> Downloading ruby-3.3.0.tar.gz...
-> curl -q -fL -o ruby-3.3.0.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.0M  100 21.0M    0     0  42.5M      0 --:--:-- --:--:-- --:--:-- 42.5M
==> Installing ruby-3.3.0...
ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
-> ./configure "--prefix=$HOME/.rbenv/versions/3.3.0" --with-openssl-dir=/opt/homebrew/opt/openssl@3 --enable-shared --with-readline-dir=/opt/homebrew/opt/readline --with-libyaml-dir=/opt/homebrew/opt/libyaml --with-ext=openssl,psych,+
-> make -j 8
-> make install
==> Installed ruby-3.3.0 to /Users/misawayuta/.rbenv/versions/3.3.0

まとめ

今回は私が余計な(?)パスを通してたと言うことが原因だったので、そもそもLIBRARY_PATHのパスを通していないと言う人には無用の解決法かなと思います。実際にunset LIBRARY_PATHでパスを消去した状態でrbenv install 3.3.0は成功したので、プログラミング学習を初めてrbenvを使うという方は気にしなくて大丈夫かと思われます。同じようなエラーが出ているのに今回のこの解決法で解消されないと言う場合は、何かパスに問題があると思われるので別個確認してみてください。

7
4
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
7
4