2018-09-29 Mac安裝&重裝Ruby、CocoaPods

時隔2年多,CocoaPods最新版本已經(jīng)升級到了1.10.1,但是發(fā)現(xiàn)在自己的電腦上安裝最新版本報錯,發(fā)現(xiàn)是New Mac OS ruby兼容問題(fatal error: 'ruby/config.h' file not found),可以參考:

stackoverflow解決方案

sudo gem install cocoapods?

如果上面命令執(zhí)行報錯: While executing gem … (Gem::FilePermissionError)

You don’t have write permissions for the /usr/bin directory.

可以執(zhí)行:sudo gem install -n /usr/local/bin cocoapods -v 1.10.1,結(jié)果參考

git:(master) sudo gem install -n /usr/local/bin cocoapods -v 1.10.1

Successfully installed cocoapods-1.10.1

Parsing documentation for cocoapods-1.10.1

Installing ri documentation for cocoapods-1.10.1

Done installing documentation for cocoapods after 2 seconds

1 gem installed


1、先安裝好 RVM

RVM 是一個便捷的多版本 ruby 環(huán)境的管理和切換工具

官網(wǎng):https://rvm.io/

1.1 在終端控制臺命令:

$ curl -sSL https://get.rvm.io | bash -s stable 之后按回車鍵

如下所示:

1.2 然后,載入 RVM 環(huán)境:

$ source ~/.rvm/scripts/rvm

1.3 修改 RVM 下載 Ruby 的源,到 Ruby China 的鏡像: ?。?!記住這個鏡像 是 ruby-china.org 不是其他的。

echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db

1.3.1 檢查一下是否安裝正確

$ rvm -v

如果能顯示版本號,則安裝成功。

如果之前安裝過 RVM 想要更新,則?

$ rvm get stable

2、安裝 ruby

列出 ruby 可安裝的版本信息 (這里安裝的是 2.4.0 的)

$ rvm list known

安裝一個ruby版本

$ rvm install 2.4.0

如果想設(shè)置為默認版本,可以用這條命令來完成

$ rvm use 2.4.0 --default

3、重裝Ruby

經(jīng)常碰到項目的Pod install 問題,如下提示,表示ruby版本不匹配,無法找到方法GundamStartUp。需要安裝低版本的ruby,如2.4.0.

[!] Invalid `Podfile` file: .

#? from /Users/xxx/Documents/xxx/xxx/xxx/Podfile:4

#? -------------------------------------------

#? require? "./GUNDAM/Gundam.rb"

>? GundamStartUp(self)

#?

#? -------------------------------------------

3.1 rvm uninstall 你當前的ruby版本

3.2 如果無法卸載,提示如下:

Error running '__rvm_rm_rf /Users/xxx/.rvm/rubies/ruby-2.6.0-preview2',

please read /Users/xxx/.rvm/log/1538210544_ruby-2.6.0-preview2/remove.rubies.log

可以使用remove命令,sudo rvm remove 2.6.0,完全移除。

3.3 安裝需要的版本

rvm ruby 2.4.1

3.4 安裝指定的cocoaPods版本

sudo gem install cocoapods --version <custom-version>

gem的相關(guān)操作

gem sources --remove https://gems.ruby-china.org/

gem sources -a https://gems.ruby-china.com/

gem sources -l

gem list --local | grep cocoapods

sudo gem update --system

sudo gem update --system 2.7.6

gem uninstall cocoapods -v 1.5.3

sudo gem install cocoapods --version 1.3.1

續(xù)1:如果遇到RVM的問題:

https://stackoverflow.com/questions/32965735/cocoapods-points-to-wrong-version?----issue

https://stackoverflow.com/questions/25016382/cocoa-pods-need-to-completely-re-install/25021772#25021772?----solution

Here is what I found out :?In my case it was that RVM was not installed correctly so RubyGems wasn't installed correctly. That in turn made CocoaPods not install correctly.

1、To completely uninstall and remove RVM:?

sudo rvm implode?or you can do?sudo rm -rf ~/.rvm

2、Reinstall RVM by doing this:?

curl -sSL https://get.rvm.io | bash -s stable --ruby

3、Reinstall CocoaPods like this:?

gem install cocoapods

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

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

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