Mac下搭建ruby遇到openssl问题
mac下升级ruby环境版本
前言
因为根据提示升级了Flutter的dart库,导致运行不了,报错
Warning: CocoaPods minimum required version 1.6.0 or greater not installed. Skipping pod install.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade:
brew upgrade cocoapods
pod setup
升级cocoaPods
sudo gem install cocoapods
报错
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Users/xx/Documents in PATH, mode 040707
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
解决办法,用如下命令:
sudo gem install cocoapods -n /usr/local/bin
参考: Cocopods 遇到You don't have write permissions for the /usr/bin directory.
一、正常流程
1、安装rvm
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm -v
2、使用rvm安装ruby
rvm list known // 支持版本
sudo rvm install --force 2.4 // 安装所需版本
rvm list // 本地安装的
rvm remove 2.3
3、设置ruby
rvm 2.4 --default
二、可能的报错信息
1、执行安装rvm install 2.4
报错
Error running '__rvm_make install',
showing last 15 lines of /Users/RenChao/.rvm/log/1495852001_ruby-2.4.0/install.log
网说一:本地多版本Xcode,需要安装xcode命令行工具
xcode-select --install // 无效
网说二:更新rvm
rvm get stable // 无效
使用rvm安装ruby失败,最终的解决方法:下载所需的ruby版本,手动分解执行rvm install 2.4
Ruby个版本镜像地址
./configure // 配置
make // 编译
sudo make install // 安装
rvm remove ruby 2.0.0p648 // 删除rvm管理的ruby版本
ruby -v // 验证是否安装成功
2、执行gem install cocoapods
报错
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
解决方案:根据提示,命令前加sudo。
3、执行gem install cocoapods
报错
ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
解决方案一:根据提示use non-HTTPS sources
,使用http源
gem source -l
gem source -r https://gems.ruby-china.com/
to remove
gem source -a http://gems.ruby-china.com/
to read
解决方案二:根据require openssl, install OpenSSL
,升级Mac的openssl
brew install openssl
rvm reinstall 2.3.0 --with-openssl-dir=brew --prefix openssl
4、sudo gem install cocoapods
安装成功,执行pod -v
报错
/Library/Ruby/Site/2.0.0/rubygems.rb:270:in
find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException) from /Library/Ruby/Site/2.0.0/rubygems.rb:298:in
activate_bin_path'
from /usr/local/bin/pod:22:in `<main>'
解决方案:删除当前ruby,卸载cocoapods,重新安装
which pod
sudo rm -rf /usr/local/bin/ruby
sudo rvm install 2.4
sudo gem install cocoapods
网友评论