生活随笔
收集整理的這篇文章主要介紹了
Ruby 版本升级
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、升級原因
在開發shopify app的時候,提示我當前的Ruby版本不支持(如下圖),所以需要升級Ruby。
由于Ruby 中的一些 Gem 依賴于 OpenSSL 庫,所以更改 Ruby 版本,還需要安裝正確版本的 OpenSSL。
下面的升級過程會先安裝 OpenSSL 1.1,再安裝 Ruby 3.2。
二、升級過程
1、降級 OpenSSL 版本
我當前的 OpenSSL 版本為 3.2,存在不兼容的問題,所以需要降到 1.1
brew list | grep openssl
openssl version
- 使用 Homebrew 安裝 OpenSSL 1.1
brew install openssl@3.0
brew link --force openssl@3.0
在
~/.bashrc、
~/.zshrc 或其他 shell 配置文件中添加如下行:
export PATH="/usr/local/opt/openssl@3.0/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl@3.0/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@3.0/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@3.0/lib/pkgconfig"
- 使用
source命令立即應用配置文件的更改 或 重啟終端
source ~/.bashrc
source ~/.zshrc
此時,再次查看 OpenSSL 版本,應為 1.1
2、升級 Ruby 版本
ruby -v
brew install ruby@3.2
在
~/.bashrc、
~/.zshrc 或其他 shell 配置文件中添加如下行:
export PATH="/usr/local/opt/ruby/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
- 使用
source命令立即應用配置文件的更改 或 重啟終端
source ~/.bashrc
source ~/.zshrc
三、其他
1、查看當前 Ruby 依賴的 OpenSSL 版本
ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
2、OpenSSL 版本不對相關報錯
- ERROR: While executing gem ... (Gem::Exception)OpenSSL is not available. Install OpenSSL and rebuild Ruby or use non-HTTPS sources (Gem::Exception)
- Could not load OpenSSL. You must recompile Ruby with OpenSSL support.
- cannot load such file -- openssl (LoadError)
3、參考鏈接
https://*.com/questions/14845481/cannot-load-such-file-openssl-loaderror
https://www.jianshu.com/p/36a7a354d10f
總結
以上是生活随笔為你收集整理的Ruby 版本升级的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。