1、安装Xcode
App Store下载即可
2、安装Homebrew
方式 1:手动安装 https://blog.csdn.net/icfhtg/article/details/107254950
方式 2:官网源安装(有可能 443):
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
方式 3:国内源安装(⚠️第一步直接选择阿里源有问题,clone不下来)
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
2.1 Homebrew安装上了,但是有些软件无法安装,可以考虑
使用阿里镜像
替换 / 还原 brew.git 仓库地址
# 替换成阿里巴巴的 brew.git 仓库地址:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 还原为官方提供的 brew.git 仓库地址
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
替换 / 还原 homebrew-core.git 仓库地址
# 替换成阿里巴巴的 homebrew-core.git 仓库地址:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 还原为官方提供的 homebrew-core.git 仓库地址
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
3、安装RVM
方式 1:官网源
curl -sSL https://get.rvm.io | bash -s stable
方式 2:若出现443 试试下面这个
curl -L [https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer](https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer) | bash -s stable
方式 3:若还是出现443 就只能试试下面这个了
a. 打开网站: https://www.ipaddress.com/
b. 查询一下 raw.githubusercontent.com对应的IP 地址
c. 将查询到的IP添加到/ect/hosts
屁股后面,举个栗子:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
185.199.108.133 raw.githubusercontent.com
4、安装ruby
4.1 列出已知的ruby版本
rvm list known
如果出现
command not found: rvm
可能是因为ram的shell配置没有加载,在终端输入:
source ~/.rvm/scripts/rvm
再输入
type rvm | head -n 1
4.2 可以选择现有的rvm版本来进行安装(以下就是是3.0.0安装步骤)
4.2.1 安装
rvm install 3.0.0
4.2.2 检测是否安装成功
ruby -v
4.2.3 环境配置
echo 'export PATH="/opt/homebrew/opt/ruby@3.0/bin:$PATH"' >> ~/.zshrc
4.2.4 立即生效
source ~/.zshrc
4.3 更换Ruby镜像
4.3.1 移除
gem sources --remove https://rubygems.org/
4.3.2 添加(https://ruby.taobao.org/ 源已停止维护)
gem sources -a https://gems.ruby-china.com/
4.3.2 是否更换成功
gem sources -l
5、安装cocopods
5.1 安装cocopods
// 普通方式1 (推荐)
sudo gem install cocoapods
// 普通方式2 (容易出现 Could not find 'CFPropertyList' (>= 2.3.3, < 4.0) among 83 total gem(s)类似错误)
brew install cocoapods
// M1芯片
brew install cocoapods
5.2 配置pod(会比较慢,请耐心等待)
pod setup
//使用这句代替执行效果更佳
git clone https://gitee.com/mirrors/CocoaPods-Specs.git ~/.cocoapods/repos/master
// 或者使用清华大学的(听着就🐂皮哄哄的)
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/master
- 更新 gem
5.1 更新gem
sudo gem update --system
5.1 查看gem版本
pod --version
5.3 测试
pod search AFNetworking
5.4 错误
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'CFPropertyList' (>= 2.3.3, < 4.0) among 83 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/Users/fengming/.rvm/gems/ruby-3.0.0:/Users/fengming/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0:/usr/local/Cellar/cocoapods/1.11.2_1/libexec', execute `gem env` for more information
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/specification.rb:1449:in `block in activate_dependencies'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `activate_dependencies'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/specification.rb:1420:in `activate'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/specification.rb:1452:in `block in activate_dependencies'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `activate_dependencies'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/specification.rb:1420:in `activate'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:304:in `block in activate_bin_path'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:303:in `synchronize'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:303:in `activate_bin_path'
from /usr/local/Cellar/cocoapods/1.11.2_1/libexec/bin/pod:23:in `<main>'
用下面这句重新安装下就好了
sudo gem install cocoapods
[!] Unable to find a pod with name, author, summary, or description matching AFNetworking
将缓存删掉重新搜索即可
rm ~/Library/Caches/CocoaPods/search_index.json