CocoaPods安装最新版

3 篇文章 0 订阅

安装步骤和命令如下:

1. 查看当前系统ruby版本ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]

mac OS自带ruby环境,我是重新安装的新系统macOS Big Sur,所以这里是最新版本。
如果不是新版本可以进行如下操作:

  • 升级ruby环境,通过rvm安装ruby环境
curl -L get.rvm.io | bash -s stable 

source ~/.bashrc

source ~/.bash_profile
  • 查看rvm版本 rvm -v
  • 列出ruby可安装的版本信息 rvm list known
  • 安装一个ruby版本 rvm install 2.5.1
  • 安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • 设置ruby默认版本 rvm use 2.5.1 --default
2. 查看ruby镜像源 gem source -l
*** CURRENT SOURCES ***

https://rubygems.org/
3. https://rubygems.org/ 这个源在国内是访问不到的,所以你需要先移除这个镜像,然后添加国内可访问的镜像 https://gems.ruby-china.com/(只保留这一个镜像)
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/

查看镜像是否已经是 https://gems.ruby-china.com/,如果不是请仔细阅读此步骤。
4. 开始安装CocoaPods
sudo gem install -n /usr/local/bin cocoapods
输入命令后,输入电脑密码后回车,没有密码直接回车。

riber@cpe-172-100-5-18 ~ % sudo gem install -n /usr/local/bin cocoapods
Password:
Fetching concurrent-ruby-1.1.8.gem
...
Successfully installed concurrent-ruby-1.1.8
...
A new major version is available for Algolia! Please now use the https://rubygems.org/gems/algolia gem to get the latest features.
Successfully installed algoliasearch-1.27.5
Building native extensions. This could take a while...
Successfully installed ffi-1.14.2
...
Parsing documentation for concurrent-ruby-1.1.8
Installing ri documentation for concurrent-ruby-1.1.8
Parsing documentation for i18n-1.8.9
...
Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, activesupport, nap, fuzzy_match, httpclient, algoliasearch, ffi, ethon, typhoeus, netrc, public_suffix, addressable, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-trunk, cocoapods-try, molinillo, atomos, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 50 seconds
33 gems installed

到此已经安装成功。

5. 如果有多个Xcode要选择Xcode版本

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

6. 执行pod命令

######(1)查看当前pods版本 pod --version

1.10.1

######(2)添加master源
查看pods源 pod repo list


0 repos

开始添加master源。由于cocoapods 新版1.9 新版的 CocoaPods 不允许用pod repo add直接添加master源了,可用清华镜像 repo更新
解决办法:

  • 对于旧版的 CocoaPods 可以使用如下方法使用 tuna 的镜像:
pod repo remove master
pod repo add master https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
pod repo update
  • 新版的 CocoaPods 不允许用pod repo add直接添加master库了,但是依然可以:
cd ~/.cocoapods/repos
pod repo remove master
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

第一次安装是没有~/.cocoapods/repos路径的。
如果你的Mac不是M1芯片的,可直接添加master库或执行pod install命令,默认为cdn源。
如果你的Mac是M1芯片的,可参考文章末尾的第一个问题。

######(3)最后进入自己的工程,在自己工程的podFile第一行加上:

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

如果Podfile中不加上面的这句话,直接pod install

Analyzing dependencies
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

查看pod源
pod repo list


trunk
- Type: CDN
- URL:  https://cdn.cocoapods.org/
- Path: /Users/riber/.cocoapods/repos/trunk

1 repo

在CocoaPods 1.8中,CocoaPods将CDN切换为默认的spec repo源,并附带一些增强功能!如果使用CDN源出现问题,可以切换为master源,可参考文章末尾的第三个问题。

注意:为了保证依赖库版本保持一致,操作时尽量不要执行pod update命令,而是使用通过修改Podfile文件里的版本号并执行pod install命令来更新pods第三方库的版本。

查看所有第三方库更新版本
pod outdated

其他问题:
  1. M1芯片安装CocoaPods问题
  2. 无法添加master源问题
  3. CDN问题
  4. pod search 搜索不到,执行后rm ~/Library/Caches/CocoaPods/search_index.json
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值