Mac Big Sur运行Rails命令报错ruby is loading libcrypto in an unsafe way
报错详情
WARNING: /Users/my_mac_username/.rvm/rubies/ruby-2.5.3/bin/ruby is loading libcrypto in an unsafe way [1] 5396 abort bin/rails g model ModelName attribute_1:string attribute_2:integer
根因说明
该问题出现在macOS Big Sur及以上版本系统中,是系统自带的高版本OpenSSL库与Ruby 2.5.3编译时依赖的旧版OpenSSL 1.0不兼容导致的。老版本Ruby调用新的libcrypto库时触发安全校验失败,最终进程中止。
解决方法
方法1:重装Ruby并指定OpenSSL路径(长期稳定可用)
- 先通过Homebrew安装适配的旧版OpenSSL:
brew install rbenv/tap/openssl@1.0 - 卸载当前安装的Ruby 2.5.3:
rvm remove 2.5.3 - 重新编译安装Ruby 2.5.3,指定旧版OpenSSL的安装路径:
rvm install 2.5.3 --with-openssl-dir=$(brew --prefix openssl@1.0) - 重装完成后重新安装bundler及项目依赖即可恢复正常:
gem install bundlerbundle install
方法2:临时创建软链(应急使用,不建议长期保留)
如果仅需要临时执行命令,可直接创建软链指向系统兼容的libcrypto库:sudo ln -s /usr/lib/libcrypto.dylib /Users/my_mac_username/.rvm/rubies/ruby-2.5.3/lib/libcrypto.1.0.0.dylib
注意替换命令中的my_mac_username为你自己的Mac设备用户名
内容的提问来源于stack exchange,提问作者Lucas Cash Hlongwane
相关产品推荐
相关产品推荐

