Mac更新Ruby環(huán)境及可能遇到的問(wèn)題

一、正常流程

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、設(shè)置ruby

rvm 2.4 --default

二、可能的報(bào)錯(cuò)信息

1、執(zhí)行安裝rvm install 2.4報(bào)錯(cuò)

Error running '__rvm_make install',
showing last 15 lines of /Users/RenChao/.rvm/log/1495852001_ruby-2.4.0/install.log

網(wǎng)說(shuō)一:本地多版本Xcode,需要安裝xcode命令行工具

xcode-select --install // 無(wú)效

網(wǎng)說(shuō)二:更新rvm

rvm get stable // 無(wú)效

使用rvm安裝ruby失敗,最終的解決方法:下載所需的ruby版本,手動(dòng)分解執(zhí)行rvm install 2.4
Ruby個(gè)版本鏡像地址

./configure // 配置
make // 編譯
sudo make install // 安裝
rvm remove ruby 2.0.0p648 // 刪除rvm管理的ruby版本
ruby -v // 驗(yàn)證是否安裝成功

2、執(zhí)行gem install cocoapods報(bào)錯(cuò)

ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

解決方案:根據(jù)提示,命令前加sudo。

3、執(zhí)行gem install cocoapods報(bào)錯(cuò)

ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

解決方案一:根據(jù)提示use non-HTTPS sources,使用http源

gem source -l
gem source -r https://rubygems.org/ to remove
gem source -a http://rubygems.org/ to read

解決方案二:根據(jù)require openssl, install OpenSSL,升級(jí)Mac的openssl

brew install openssl
rvm reinstall 2.3.0 --with-openssl-dir=brew --prefix openssl

4、sudo gem install cocoapods安裝成功,執(zhí)行pod -v報(bào)錯(cuò)

/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>'

解決方案:刪除當(dāng)前ruby,卸載cocoapods,重新安裝

which pod
sudo rm -rf /usr/local/bin/ruby
sudo rvm install 2.4
sudo gem install cocoapods

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容