Ruby ビルド時の parse.tmp.y:12.10-14: require bison 3.0, but have 2.3 を解決する

macOS に入っている bison のバージョンが 2.3 のため Ruby 3.2 がビルドできなくなっていた。

❯ asdf install ruby 3.2.0-dev
Downloading ruby-build...
Cloning into '/Users/mi/.asdf/plugins/ruby/ruby-build-source'...
remote: Enumerating objects: 13397, done.
remote: Counting objects: 100% (2096/2096), done.
remote: Compressing objects: 100% (374/374), done.
remote: Total 13397 (delta 1876), reused 1828 (delta 1704), pack-reused 11301
Receiving objects: 100% (13397/13397), 2.70 MiB | 2.33 MiB/s, done.
Resolving deltas: 100% (9114/9114), done.
Already on 'master'
To follow progress, use 'tail -f /var/folders/7g/c0g_krhn7zg7q4jzpntm6ylw0000gn/T/ruby-build.20221214004540.19944.log' or pass --verbose
Downloading openssl-3.0.7.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/83049d042a260e696f62406ac5c08bf706fd84383f945cf21bd61e9ed95c396e
Installing openssl-3.0.7...
Installed openssl-3.0.7 to /Users/mi/.asdf/installs/ruby/3.2.0-dev

Cloning https://github.com/ruby/ruby.git...
Installing ruby-master...
ruby-build: using readline from homebrew
ruby-build: using gmp from homebrew

BUILD FAILED (macOS 12.4 using ruby-build 20221206)

Inspect or clean up the working tree at /var/folders/7g/c0g_krhn7zg7q4jzpntm6ylw0000gn/T/ruby-build.20221214004540.19944.xS24dl
Results logged to /var/folders/7g/c0g_krhn7zg7q4jzpntm6ylw0000gn/T/ruby-build.20221214004540.19944.log

Last 10 log lines:
generating parse.c
copying lex.c
compiling proc.c
compiling process.c
making ractor.rbinc
compiling random.c
compiling range.c
parse.tmp.y:12.10-14: require bison 3.0, but have 2.3
make: *** [parse.c] Error 63
make: *** Waiting for unfinished jobs....


❯ bison -V
bison (GNU Bison) 2.3
Written by Robert Corbett and Richard Stallman.

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Ruby 3.2 からは bison 3.0 以上が必要になるため、インストールしてPATHを通す。

homebrew を使っている場合は、

brew install bison

で bison をインストールする。

インストール時に以下のように通すべきPATHが書いてあるためここにPATHを通す。

以下の例は Intel mac で、M1 mac だとおそらくパスが異なる。

If you need to have bison first in your PATH, run:
  echo 'export PATH="/usr/local/opt/bison/bin:$PATH"' >> ~/.zshrc

.zshrc に PATH を書いて、シェルを再起動するか source ~/.zshrc する。

# bison
export PATH="/usr/local/opt/bison/bin:$PATH"

bison -V でバージョンが変わっていたらOK

❯ bison -V
bison (GNU Bison) 3.8.2
Written by Robert Corbett and Richard Stallman.

Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


❯ asdf install ruby 3.2.0-dev
Downloading ruby-build...
Cloning into '/Users/mi/.asdf/plugins/ruby/ruby-build-source'...
remote: Enumerating objects: 13397, done.
remote: Counting objects: 100% (2084/2084), done.
remote: Compressing objects: 100% (392/392), done.
remote: Total 13397 (delta 1864), reused 1798 (delta 1674), pack-reused 11313
Receiving objects: 100% (13397/13397), 2.70 MiB | 4.38 MiB/s, done.
Resolving deltas: 100% (9114/9114), done.
Already on 'master'
To follow progress, use 'tail -f /var/folders/7g/c0g_krhn7zg7q4jzpntm6ylw0000gn/T/ruby-build.20221214010049.68309.log' or pass --verbose
Downloading openssl-3.0.7.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/83049d042a260e696f62406ac5c08bf706fd84383f945cf21bd61e9ed95c396e
Installing openssl-3.0.7...
Installed openssl-3.0.7 to /Users/mi/.asdf/installs/ruby/3.2.0-dev

Cloning https://github.com/ruby/ruby.git...
Installing ruby-master...
ruby-build: using readline from homebrew
ruby-build: using gmp from homebrew
Installed ruby-master to /Users/mi/.asdf/installs/ruby/3.2.0-dev