やりたいこと
Ruby3.1.3をインストールしたい
環境
M2 MacBook Air macOS Monterey バージョン 12.5.1
Homebrew 3.6.12
rbenv 1.2.0
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
経緯
もともとはCocoapodsをインストールしたかったのですが、以下のようなエラーが出ました。
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory.
そこで、こちらの記事を参考に、一般ユーザの領域にrubyの環境を作ろうとしていました。
rbenv install 3.1.3
を実行したところ、以下のようなエラーが発生しました。
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.3.tar.gz
Installing ruby-3.1.3...
ruby-build: using readline from homebrew
ruby-build: using gmp from homebrew
BUILD FAILED (macOS 12.5.1 using ruby-build 20221124)
Inspect or clean up the working tree at /var/folders/w5/592h_r3d57547m_h6k0tywk80000gn/T/ruby-build.20221126180230.2526.AiU8cm
Results logged to /var/folders/w5/592h_r3d57547m_h6k0tywk80000gn/T/ruby-build.20221126180230.2526.log
Last 10 log lines:
compiling ossl_x509ext.c
compiling ossl_x509name.c
linking shared-object psych.bundle
compiling ossl_x509req.c
3 warnings generated.
compiling ossl_x509revoked.c
compiling ossl_x509store.c
linking shared-object openssl.bundle
linking shared-object ripper.bundle
make: *** [build-ext] Error 2
/var/folders/w5/592h_r3d57547m_h6k0tywk80000gn/T/ruby-build.20221126180230.2526.logの内容です。文字数制限のため一部です
compiling psych.c
compiling ripper.c
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
^
/usr/local/opt/readline/include/readline/readline.h:494:14: note: 'rl_username_completion_function' declared here
extern char *rl_username_completion_function (const char *, int);
^
1 error generated.
make[2]: *** [readline.o] Error 1
make[1]: *** [ext/readline/all] Error 2
make[1]: *** Waiting for unfinished jobs....
checking ../.././parse.y and ../.././ext/ripper/eventids2.c
installing default libraries
compiling ossl_pkey_dh.c
compiling ossl_pkey_dsa.c
ossl_pkey_dh.c:87:14: warning: 'DH_new' is deprecated [-Wdeprecated-declarations]
dh = DH_new();
^
/Users/komatsu/.rbenv/versions/3.1.3/openssl/include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED'
# define OSSL_DEPRECATED(since) __attribute__((deprecated))
^
44 warnings generated.
compiling ossl_x509.c
compiling ossl_x509attr.c
40 warnings generated.
compiling ossl_x509cert.c
linking shared-object date_core.bundle
compiling ossl_x509crl.c
compiling ossl_x509ext.c
compiling ossl_x509name.c
linking shared-object psych.bundle
compiling ossl_x509req.c
3 warnings generated.
compiling ossl_x509revoked.c
compiling ossl_x509store.c
linking shared-object openssl.bundle
linking shared-object ripper.bundle
make: *** [build-ext] Error 2
やったこと
Xcode再インストール
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
こちらの記事を参考に下記コードを実行
arch -arm64 rbenv install 3.1.3
こちらの記事を参考にCommandLineToolsの再インストール.zshに環境変数の追加、[email protected]の指定なども行いました。