Cocoapods安装

2023-03-06  本文已影响0人  hyq1101

一、安装步骤
安装Homebrew --> 安装rvm --> 安装ruby -> 安装cocoapods

二、检查Homebrew或安装
1、查看安装的版本信息

brew --version
// 出现以下结果说明安装过
Homebrew 4.0.4-202-gb1ef41c
Homebrew/homebrew-core (git revision fd2e83a24e8; last commit 2023-03-06)
Homebrew/homebrew-cask (git revision c896fe8640; last commit 2023-03-06)

2、安装Homebrew
方式1:官方提供的安装方法

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

方式2:使用国内的源进行安装

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

安装完成后执行

source /Users/apple/.rvm/scripts/rvm

三、检查rvm
1、检查rvm是否安装

rvm -v
// 出现以下结果说明安装过
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

2、更新rvm

rvm get stable

若执行失败,可以在命令前加入sudo权限

sudo  rvm get stable

如果还是执行失败,报错如下:

$ rvm get stable
Downloading https://get.rvm.io
Could not download rvm-installer, please report to https://github.com/rvm/rvm/issues

解决方案是替换host文件:
(1)查询一下 raw.githubusercontent.com对应的IP地址
(2)进入 /etc 目录下替换系统的 hosts 文件(直接修改是没有权限的,复制出来修改后拷贝进去替换)
在hosts文件中最后加入一行:


image.png

此时在终端中 ping 一下 raw.githubusercontent.com
如果可以ping通则继续后续操作
重新执行 rvm get stable


image.png

3、安装rvm

// 安装rvm
curl -L https://get.rvm.io | bash -s stable
// 载入rvm
source ~/.rvm/scripts/rvm

四、检查ruby或安装
1、检查ruby是否安装

ruby -v
// 出现以下结果说明安装过
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin21]

2、查看ruby在系统中可安装的版本

rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0]
ruby-head
......

3、安装最新版本ruby

rvm install 3.0.0
// 出现以下结果说明最新版安装成功
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin22]

gem版本太老ruby安装失败的话先升级gem:sudo gem update --system
4、安装ruby遇到的错
(1)执行 brew install ruby 时报错


image.png

解决方法:
输入brew -v后会提示你执行两个配置命令,直接复制执行就ok了!

git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask

具体如下图所示:


image.png

(2)执行 rvm install 3.0.0 时报错


image.png

解决方法:

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

(3)执行 rvm install 3.0.0 时报错


image.png

解决方法:

// 先删除文件
rm -rf /Users/huangyueqi/Library/Caches/Homebrew/portable-ruby-2.6.10_1.el_capitan.bottle.tar.gz
// 再重新执行
rvm install 3.0.0

5、将ruby该版本设置默认使用

rvm use 3.0.0 --default

6、查询Ruby的源地址

gem source -l

替换国内Ruby镜像源

// 移除旧源
gem sources --remove https://rubygems.org/
// 添加china源
gem sources --add https://gems.ruby-china.com/

没有权限的话在前面加上sudo


image.png

五、安装cocoapods

sudo gem install -n /usr/local/bin cocoapods

问题:执行上面命令后还是找不到pod


image.png

解决方法:
执行 sudo gem install Cocoapods 重新安装

六、pod install报错
1、执行“sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/”切换到当前Xcode路径下


image.png

2、

Cloning spec repo `cocoapods` from `https://github.com/CocoaPods/Specs.git`
 
# 过了很久很久没反应
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `cocoapods`.
You can try adding it manually in `/Users/xxx/.cocoapods/repos` or via `pod repo add`.

解决方法:

cd ~/.cocoapods/repos/

检查一下 master 文件夹是否存在,如果存在 master 文件夹,执行 pod repo remove master。不存在则跳过这一条命令。

pod repo remove master

接下来继续执行以下命令

pod setup
git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master

3、pod search SDWebImage出现以下错误

[!] Unable to find a pod with name, author, summary, or description matching `SDWebImage`

解决办法:

git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master

4、pod install出现Couldn't determine repo type for URL...

myUser$ pod install
Analyzing dependencies
[!] Couldn't determine repo type for URL: `https://github.com/CocoaPods/Specs.git`: Permission bits for '/Users/myUser/.netrc' should be 0600, but are 644

错误消息说存在权限问题

'/Users/myUser/.netrc'的权限位应为0600,但为644

解决办法:

chmod 600 ~/.netrc
上一篇下一篇

猜你喜欢

热点阅读