inohilog

/var/log/inohiro.log

Apple Silicon Mac で ruby のインストールにハマった

昨日 の続き。まあハマりそうだなと思っていたけど、ハマった。環境的には旧 Intel MacBook Pro から Migrate Assistant でコピったものなので、まっさらな状態より悪い。

最終的にやったことは

$ sudo rm -rf /Library/Developer/CommandLineTools
$ sudo xcode-select --install

してから、readline を Homebrew でインストールし直し、rbenv install 3.1.2 (最終的に、特別なビルドオプションは必要無かった)


今いるチームでは ruby 3.1.2 を使っていて、rbenv + ruby-build でインストールしようとしたが、以下のようなエラーで止まった(それっぽいところを一部抜粋)。完全なログはこちら

compiling readline.c
compiling ripper.c
linking shared-object date_core.bundle
compiling ossl_engine.c
linking shared-object rbconfig/sizeof.bundle
installing default libraries
readline.c:1903:37: error: use of undeclared identifier 'username_completion_function'; did you mean 'rl_username_completion_function'?
                                    rl_username_completion_function);
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    rl_username_completion_function
readline.c:79:42: note: expanded from macro 'rl_username_completion_function'
# define rl_username_completion_function username_completion_function
                                         ^
/opt/homebrew/opt/readline/include/readline/readline.h:485:14: note: 'rl_username_completion_function' declared here
extern char *rl_username_completion_function PARAMS((const char *, int));
             ^
1 error generated.
compiling init.c
make[2]: *** [readline.o] Error 1
make[1]: *** [ext/readline/all] Error 2

blog.furu07yu.com

上の記事にあるように、readline の場所を明示的に指定しても同じエラーで失敗した。

$ brew --prefix readline  
/opt/homebrew/opt/readline
$ RUBY_CONFIGURE_OPTS=--with-readline-dir="$(brew --prefix readline)" rbenv install 3.1.2

他にも Web で色々情報を漁って、いくつかのビルドオプションを試したが、混乱のもとになりそうなのでリンクはしない。 readline がおかしそうなのは間違いなさそうなので、brew で再インストールしてみようとしたら、Command Line Tools が古すぎるとメッセージが出た。

$ brew reinstall readline -s     
==> Downloading https://ftp.gnu.org/gnu/readline/readline-8.1-patches/readline81-001
######################################################################## 100.0%
==> Downloading https://ftp.gnu.org/gnu/readline/readline-8.1-patches/readline81-002
######################################################################## 100.0%
==> Downloading https://ftp.gnu.org/gnu/readline/readline-8.1.tar.gz
######################################################################## 100.0%
==> Reinstalling readline
Error: Your Command Line Tools are too outdated.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you any updates, run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/all/.
You should download the Command Line Tools for Xcode 13.4.

softwareupdate --all --install --force では何も出なかったので、その下で示されている方法でインストールし直した。そのあと readline をインストールし直し、rbev install 3.1.2 したところ無事インストールできた。