Ruby-install を使用して Ruby をインストールすると、Mac M1 でビルド エラーが発生する
概要
Mac M1 に Ruby-install を使用して Ruby 2.6.6 または 2.7.2 をインストールすると、次のエラーが発生します。 Ruby 3.0.0 は正常に動作しますが、それより古いものは readline でエラーが発生し、ruby をインストールできません。
readline.c:1905: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));
解決策
次の手順で、最終的に、2.6.6 を含む古いバージョンの Ruby を m1 チップの MacBook Pro にインストールできました。
まず、rbenv、ruby-build、readline を次のように再インストールする必要がありました。
brew reinstall rbenv ruby-build readline
次に、CONFIGURE_OPTS を使用すると、OpenSSL ビルドが壊れていました。代わりに RUBY_CONFIGURE_OPTS を使用してください。私は hombrew を使用しており、次のフラグを使用する必要がありました。
RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`"
3 番目に、make コマンドの警告によってビルドが停止されないように次のように設定します。
RUBY_CFLAGS="-Wno-error=implicit-function-declaration"
4 番目に、rbenv 経由でインストールするときに必ず Arch フラグを設定します。
arch -x86_84
5 番目に、自作パスが正しく設定されていることを確認します。
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/opt:$PATH"
Ruby 2.6.6 を正常にインストールした最後のコマンドは次のとおりです。
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/opt:$PATH"
RUBY_CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`" sudo arch -x86_64 rbenv install --verbose 2.6.6
sudo を使用して、スクリプトに mkdir 権限を付与しました。