M2 Mac fails to install rbenv install 3.1.3 due to errors

Asked 2 years ago, Updated 2 years ago, 592 views

I want to install Ruby 3.1.3

M2 MacBook Air macOS Monterey version 12.5.1
Homebrew 3.6.12
rbenv1.2.0
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]

Originally, I wanted to install Cocoapods, but I got the following error:

 ERROR: While executing gem... (Gem::FilePermissionError)
You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Version/2.6/usr/lib/ruby/gems/2.6.0 directory.

So, I was trying to create a ruby environment in the general user area by referring to this article.

rbenv install 3.1.3

The following error occurred while trying to:

->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)

Inspector clean up the working tree at /var/folder/w5/592h_r3d57547m_h6k0tywk80000gn/T/ruby-build.20221126180230.2526.AiU8cm
Results logged to/var/folder/w5/592h_r3d57547m_h6k0tywk80000gn/T/ruby-build.20221126180230.2526.log

Last 10 log lines:
compiling ossl_x509 ext.c
compiling ossl_x509name.c
linking shared-object psich.bundle
compiling ossl_x509req.c
3 warnings generated.
compiling ossl_x509 revoked.c
compiling ossl_x509store.c
linking shared-object openssl.bundle
linking shared-object ripper.bundle
make:*** [build-ext] Error 2

/var/folder/w5/592h_r3d57547m_h6k0tywk80000gn/T/ruby-build.20221126180230.2526.log.Partial due to character limitation

compiling psich.c
compiling riper.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
external 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/opensl/include/opensl/macros.h:62:52:note:expanded from macro'OSSL_DEPRECATED'
#     defineOSSL_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_x509 ext.c
compiling ossl_x509name.c
linking shared-object psich.bundle
compiling ossl_x509req.c
3 warnings generated.
compiling ossl_x509 revoked.c
compiling ossl_x509store.c
linking shared-object openssl.bundle
linking shared-object ripper.bundle
make:*** [build-ext] Error 2

Xcode Reinstall

 sudo xcode-select -- switch/Applications/Xcode.app/Contents/Developer
sudoxcodebuild-runFirstLaunch

Use this article to execute the code below

arch-arm64 rbenv install 3.1.3

Refer to this article to reinstall CommandLineTools.zsh, add environment variables, specify [email protected] and so on.

ruby macos cocoapods rbenv

2022-11-27 15:28

1 Answers

Self-resolved

Reinstalling homebrew
Verify OpenSSL is not installed

brew list | grep openssl

Ruby 3.1.x Appears to Request OpenSSL3

brew install openssl@3readline libyaml gmp
export RUBY_CONFIGURE_OPTS="--with-opensl-dir=$(brew --prefix openssl@3)"

After installing it normally, it passed

rbenv install 3.1.3
rbenv global 3.1.3
rbenv versions

Edit .zshrc

open to /.zshrc
 pass through #rbenv
[[-d~/.rbenv]&\
  export PATH=${HOME}/.rbenv/bin:${PATH}&\
  event "$(rbenv init-)"

Run the source command

source to /.zshrc

ruby-build
Missing OpenSSL
Error occurs and CocoaPods cannot be installed


2022-11-27 17:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.