Mac 12.6.7下用RVM安装Ruby2.7.5遇OpenSSL版本匹配问题求助
无法通过RVM安装Ruby 2.7.5(OSX 12.6.7),OpenSSL版本识别异常
已查阅大量GitHub问题及Stack Overflow类似提问,仍无法让RVM正确识别符合要求的OpenSSL版本,无法为React Native安装Ruby 2.7.5。系统为OSX 12.6.7。
执行rvm reinstall 2.7.5的输出
rvm reinstall 2.7.5 ruby-2.7.5 - #removing src/ruby-2.7.5 - please wait ruby-2.7.5 - #removing rubies/ruby-2.7.5 - please wait Searching for binary rubies, this might take some time. No binary rubies available for: osx/12.6/x86_64/ruby-2.7.5. Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies. Checking requirements for osx_brew. Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date. Requirements installation successful. Installing Ruby from source to: /Users/x/.rvm/rubies/ruby-2.7.5, this may take a while depending on your cpu(s)... ruby-2.7.5 - #downloading ruby-2.7.5, this may take a while depending on your connection... ruby-2.7.5 - #extracting ruby-2.7.5 to /Users/x/.rvm/src/ruby-2.7.5 - please wait ruby-2.7.5 - #configuring - please wait ruby-2.7.5 - #post-configuration - please wait ruby-2.7.5 - #compiling - please wait ruby-2.7.5 - #installing - please wait Error running '__rvm_make install', please read /Users/x/.rvm/log/1688495709_ruby-2.7.5/install.log There has been an error while running make install. Halting the installation.
/usr/local/opt目录内容
lrwxr-xr-x 1 x admin 27 Jul 3 11:58 openssl -> ../Cellar/openssl@3/3.1.1_1 lrwxr-xr-x 1 x admin 28 Jul 3 11:55 openssl@1.1 -> ../Cellar/openssl@1.1/1.1.1u lrwxr-xr-x 1 x admin 27 Jul 3 11:58 openssl@3 -> ../Cellar/openssl@3/3.1.1_1 lrwxr-xr-x 1 x admin 27 Jul 3 11:58 openssl@3.1 -> ../Cellar/openssl@3/3.1.1_1
安装日志错误(.rvm/log/1688493800_ruby-2.7.5/install.log)
/Users//.rvm/src/ruby-2.7.5/lib/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- openssl (LoadError) from /Users//.rvm/src/ruby-2.7.5/lib/rubygems/core_ext/kernel_require.rb:83:in `require' from /Users//.rvm/src/ruby-2.7.5/lib/rubygems/specification.rb:2430:in `to_ruby' from ./tool/rbinstall.rb:846:in `block (2 levels) in install_default_gem' from ./tool/rbinstall.rb:279:in `open_for_install' from ./tool/rbinstall.rb:845:in `block in install_default_gem' from ./tool/rbinstall.rb:835:in `each' from ./tool/rbinstall.rb:835:in `install_default_gem' from ./tool/rbinstall.rb:799:in `block in <main>' from ./tool/rbinstall.rb:950:in `block in <main>' from ./tool/rbinstall.rb:947:in `each' from ./tool/rbinstall.rb:947:in `<main>' make: *** [do-install-nodoc] Error 1
OpenSSL扩展编译日志错误(.rvm/src/ruby-2.7.5/ext/openssl/mkmf.log)
/Users/x/.rvm/src/ruby-2.7.5/ext/openssl/extconf.rb:111: OpenSSL >= 1.0.1, < 3.0.0 or LibreSSL >= 2.5.0 is required /Users/x/.rvm/src/ruby-2.7.5/ext/openssl/extconf.rb:111:in `<top (required)>' ./ext/extmk.rb:214:in `load' ./ext/extmk.rb:214:in `block in extmake' /Users/x/.rvm/src/ruby-2.7.5/lib/mkmf.rb:331:in `open' ./ext/extmk.rb:210:in `extmake' ./ext/extmk.rb:572:in `block in <main>' ./ext/extmk.rb:568:in `each' ./ext/extmk.rb:568:in `<main>'
解决方案
问题根源是Ruby 2.7.5仅支持OpenSSL 1.0.1到2.x版本,但系统默认openssl指向3.x版本,RVM编译时未匹配到符合要求的OpenSSL 1.1版本。执行以下步骤解决:
- 临时指定环境变量,让RVM编译时优先使用OpenSSL 1.1:
export PATH="/usr/local/opt/openssl@1.1/bin:$PATH" export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
- 清理编译残留并重新安装Ruby 2.7.5:
rvm cleanup all rvm reinstall 2.7.5 --with-openssl-dir=/usr/local/opt/openssl@1.1
- 验证安装结果:
安装完成后执行ruby -v确认版本,再执行irb -r openssl -e "puts OpenSSL::OPENSSL_VERSION"检查OpenSSL是否正常加载。
若仍有问题,可尝试卸载RVM后重新安装,确保安装过程中指定正确的OpenSSL路径。
内容的提问来源于stack exchange,提问作者mjmostachetti
相关产品推荐
相关产品推荐

