總共就下面幾個命令行
sudo gem update -n /usr/local/bin --system
gem source -l
gem sources --remove 上面返回的路徑
gem source -a https://gems.ruby-china.org/
sudo gem install -n /usr/local/bin cocoapods
pod setup
pod --version
pod search AFNetWorking
以下是有可能出現的問題
1.升級Ruby環境
gem update --system
1.1若報錯
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
命令行換成
sudo gem update --system
1.2若報錯
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/update_rubygems
命令行換成
sudo gem update -n /usr/local/bin --system
1.3 若報錯
YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0).
ruby 版本過低,更新ruby , 第一次通過RVM失敗,換成了Homebrew安裝成功了
方式一: RVM方式安裝
// 1.先安裝ruby版本管理器RVM
curl -L get.rvm.io | bash -s stable
// 2.驗證RVM
source ~/.profile
source ~/.bashrc
source ~/.bash_profile
// 3.測試是否安裝正常
rvm -v
// 4.查看ruby最新版本
rvm list known
// 5.安裝ruby 2.4.1
rvm install 2.4.1
方式二: Homebrew安裝ruby
// 1.安裝 Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
若報錯
error: could not lock config file /usr/local/Homebrew/.git/config: Permission denied
執行
sudo chgrp -R admin /usr/local
sudo chmod -R g+w /usr/local
或
sudo chown -R $(whoami) /usr/local
[參考鏈接] (https://apple.stackexchange.com/questions/42127/homebrew-permissions-multiple-users-needing-to-brew-update)
若報錯
Error: /usr/local/Cellar is not writable. You should change the
ownership and permissions of /usr/local/Cellar back to your
執行
sudo chown -R $(whoami) /usr/local/Cellar
// 2.驗證brew是否安裝成功
brew
安裝成功后,會返回
Example usage:
brew search [TEXT|/REGEX/]
brew (info|home|options) [FORMULA…]
brew install FORMULA…
brew update
brew upgrade [FORMULA…]
brew uninstall FORMULA…
brew list [FORMULA…]
// 3.更新最新版本brew
brew update
// 4.安裝 ruby, 通過下面的命令會安裝最新的ruby版本
brew install ruby
// 5.安裝后查看ruby版本還是老版本
source ~/.profile
source ~/.bash_profile
1.4若報錯
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store
請升級ruby
2.更換Ruby鏡像
// 檢查現有 Ruby鏡像
gem sources -l
如果結果是
*** CURRENT SOURCES ***
https://gems.ruby-china.org/
就不需要替換了,否則就要替換,執行下面命令
// 移除現有鏡像
gem sources --remove https://rubygems.org
// 添加國內鏡像
gem source -a https://gems.ruby-china.org/
// 檢查是否替換成功
gem sources -l
3.安裝 Cocoapods
sudo gem install cocoapods
若出現
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
則換成下面的命令行
sudo gem install -n /usr/local/bin cocoapods
4.建立索引庫
pod setup
5.查看版本
pod --version
6.pod search AFNetworking
若報錯
[!] Unable to find a pod with name, author, summary, or description matching `AFNetworking`
執行命令行
rm ~/Library/Caches/CocoaPods/search_index.json
然后再執行 pod search AFNetworking ,會重新建立索引,需要花費一會時間
