cocoapods安装

1.安装Xcode Command Line Tools。
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

2.安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

1必备设置

替换 brew.git:

git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git

2替换 homebrew-core.git:

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

3.安装rvm
上github下载rvm,https://github.com/rvm/rvm.git。
双击打开/bin/rvm-installer

.../Users/****计算机名***/.rvm/ is complete.

提示这个说明安装完成。
然后配置到.bash_profile
export PATH="/Users/****计算机名***/.rvm/bin:$PATH"
终端输入:rvm -v 查看版本

4.安装 Ruby

brew install ruby

安装完成后查看其 Ruby 源:
gem sources -l

如果显示的ruby源不是ruby-china,则需要进行源替换:
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

5.ruby源正常, 安装CocoaPods:
sudo gem install -n /usr/local/bin cocoapods

安装成功后进行pod设置:
pod setup

执行完毕后, 查看pod版本看安装是否成功: pod --version

关于M1芯片的Mac电脑上使用pod命令时报ffi相关的错误

错误如下:
LoadError - dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle, 0x0009):
tried: '/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle'
(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')),
'/usr/lib/ffi_c.bundle' (no such file) - /Library/Ruby/Gems/2.6.0/gems/
ffi-1.15.5/lib/ffi_c.bundle

解决办法:
sudo arch -x86_64 gem install ffi
arch -x86_64 pod install
注:之后使用pod命令前,要加上"arch -x86_64",表示以X86 模式运行该命令
如果嫌麻烦,可以执行下述命令:
arch -x86_64 $SHELL
就可以启动一个 X86 模式终端,使得之后运行的命令都在 X86 模式下运行。

CocoaPods 卸载重装

卸载命令行
sudo gem uninstall cocoapods

不能完全卸载干净,通过如下命令查看相关组件
gem list --local | grep cocoapods

会显示如下类似
cocoapods-core (1.11.2)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (1.5.1)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
cocoapods-try (1.2.0)

然后依次删除
sudo gem uninstall cocoapods-core

最后重新安装
sudo gem install -n /usr/local/bin cocoapods

你可能感兴趣的:(cocoapods安装)