使用RVM 安装Ruby rvm 官网 https://rvm.io.
curl -sSL https://get.rvm.io | bash -s stable
有变动请参考 rvm 官网 https://rvm.io.
显示当前正在使用的ruby版本
ruby -v
查看可以安装的版本
rvm list known
安装一个ruby版本
rvm install 2.2.2
卸载一个已安装版本
rvm remove 2.2.2
切换到一个ruby版本
rvm use 2.2.2
设置默认版本
rvm use 2.2.2 --default
查询已经安装的ruby
rvm list
#查看当前正在使用的源
gem sources -l
#移除默认的源
gem sources --remove https://rubygems.org/
#更换淘宝的源
gem sources -a https://gems.ruby-china.com
# 安装最新版本
gem install cocoapods
# 安装指定版本
gem install cocoapods -v 1.9.3
或者
sudo gem install cocoapods --version 1.9.3
# 初始化
pod setup
#安装第三方打包lib
gem install cocoapods-packager
Q 1: 安装失败
Update all pods
Preparing
Updating local specs repositories
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only perfomed in repo update
Updating spec repo `cocoapods`
[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-core-1.10.1/lib/cocoapods-core/github.rb:105:in `rescue in modified_since_commit'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-core-1.10.1/lib/cocoapods-core/github.rb:100:in `modified_since_commit'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-core-1.10.1/lib/cocoapods-core/source.rb:464:in `unchanged_github_repo?'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-core-1.10.1/lib/cocoapods-core/source.rb:345:in `update'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:135:in `block (3 levels) in update'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/user_interface.rb:64:in `section'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:134:in `block (2 levels) in update'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:133:in `each'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:133:in `block in update'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:131:in `open'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:131:in `update'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:145:in `block in update_repositories'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:143:in `each'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/installer/analyzer.rb:143:in `update_repositories'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:235:in `block in resolve_dependencies'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/user_interface.rb:64:in `section'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:234:in `resolve_dependencies'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/installer.rb:160:in `install!'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/command/update.rb:63:in `run'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/lib/cocoapods/command.rb:52:in `run'
/Users/xiao/.rvm/gems/ruby-2.7.2/gems/cocoapods-1.10.1/bin/pod:55:in `<top (required)>'
/Users/xiao/.rvm/gems/ruby-2.7.2/bin/pod:23:in `load'
/Users/xiao/.rvm/gems/ruby-2.7.2/bin/pod:23:in `<main>'
/Users/xiao/.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `eval'
/Users/xiao/.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `<main>'
A 1: 替换host
1、下载host
https://cdn.jsdelivr.net/gh/521xueweihan/GitHub520@main/hosts
github 网址
https://github.com/521xueweihan/GitHub520
2、把 host 追加到 /etc/hosts
然后运行命令
sudo killall -HUP mDNSResponder
3、多次尝试可以成功