LoginSignup
1
0

More than 1 year has passed since last update.

Ruby3.2.0-devのインストール時にrequire bison 3.0と出てインストールできない時の対処法

Last updated at Posted at 2023-02-04

rbenvを利用してruby3.2.0-devのインストールを試みたところ、bisonのversionが低いというコンパイラ関連のエラーで躓いてしまいました。
同じ問題でインストールできない方のお役に少しでも立てたらと思い、解決までのプロセスを共有します。

3.2.0-devのインストールの準備

ruby-buildの公式ページにて3.2.0-devのインストールに必要な手順を確認し、下記のとおり実行。

  1. openssl@3及び関連ライブラリのインストール
    brew install openssl@3 readline libyaml gmp
  2. opensslコンパイルのための環境変数を.zshrcに設定(source ~/.zshrcをお忘れなく)
    export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@3)"
  3. YJITを有効にするためにRustコンパイラのインストール
    brew install rust
  4. Ruby 3.2.0-dev以上(-dev版のみ)にはBison(Cコンパイラ)が必要とのことでインストール。
    brew install bison

エラー内容

ruby3.2.0-devをインストールしようとすると下記のエラーが発生。

$ rbenv install 3.2.0-dev
Cloning https://github.com/ruby/ruby.git...
Installing ruby-master...
ruby-build: using readline from homebrew

BUILD FAILED (macOS 13.1 using ruby-build 20220426-1-gc0d87ea)

Inspect or clean up the working tree at /var/folders/xc/700s01nj3cxf7z98cmnkl3lr0000gn/T/ruby-build.20230130111131.10195.LQXMSS
Results logged to /var/folders/xc/700s01nj3cxf7z98cmnkl3lr0000gn/T/ruby-build.20230130111131.10195.log

Last 10 log lines:
compiling process.c
making ractor.rbinc
compiling random.c
compiling range.c
compiling rational.c
compiling re.c
compiling regcomp.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....

出力されたログを確認するとrequire bison 3.0, but have 2.3と言われている。
bisonのversion3以上である必要がある模様。

bisonのversionを調べてみる。

$ bison --version
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.

最新版をインストールしたはずであるがversion2.3となっている。

解決までのプロセス

bisonのversionを上げるという内容でググってみると、PATHを通す必要があることが判明。
とういか、実はbisonのインストール時に下記説明がなされていたが気づいてなかった。

$ brew install bison
==> Fetching bison
==> Downloading https://ghcr.io/v2/homebrew/core/bison/manifests/3.8.2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/bison/blobs/sha256:fc0224d45c74ee561128eb9df366ccb08698b1d659cfb92ea746e57d
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:fc0224d45c74ee561128eb9df366ccb08698b1d
######################################################################## 100.0%
==> Pouring bison--3.8.2.ventura.bottle.tar.gz
==> Caveats
bison is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

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

For compilers to find bison you may need to set:
  export LDFLAGS="-L/usr/local/opt/bison/lib"

==> Summary
🍺  /usr/local/Cellar/bison/3.8.2: 99 files, 3.7MB
==> Running `brew cleanup bison`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

bison is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

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

bisonはkeg-onlyなので/usr/localにシンボリックリンクされておらず、読み込むためにPATHを通す必要がある模様。

説明に従い.zshrcにPATHを設定(設定後、source ~/.zshrcをお忘れなく)。1

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

bison --verionを実行。

$ bison --version
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.

bisonのversionが上がった!:v:

ruby3.2.0-devを再度インストールすると無事に成功しました!:sparkles:

$ rbenv install 3.2.0-dev
Cloning https://github.com/ruby/ruby.git...
Installing ruby-master...
ruby-build: using readline from homebrew
Installed ruby-master to ~/.rbenv/versions/3.2.0-dev

実行環境

  • MacBook Pro(2019, Intel Core i9)
  • MacOS Ventura(version13.1)

参考記事

あわせて読みたい

ruby3.1.2のインストール時にもエラーで躓いたので解決までのプロセスを共有します。

  1. M1チップのMacでは違うPATHが出力されるようです。

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