Post

每年痛一次的cocoapods

因为电脑坏了,或新电脑安装环境,总会卡在cocoapods安装很长一段时间 时间:2022年01月05日 设备: MacBook Pro 系统:12.1 macOS Montery

2022.12.01 M1的Mac mini安装,一切顺利,没遇到任何问题

1
brew install cocoapods

安装好后,使用最新xcode版本创建项目后,pod init报错

1
2
3
4
5
6
7
8
9
RuntimeError - [Xcodeproj] Unknown object version (56).
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/gems/xcodeproj-1.21.0/lib/xcodeproj/project.rb:228:in `initialize_from_file'
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/gems/xcodeproj-1.21.0/lib/xcodeproj/project.rb:113:in `open'
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command/init.rb:41:in `validate!'
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/gems/claide-1.1.0/lib/claide/command.rb:333:in `run'
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in `run'
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/bin/pod:55:in `<top (required)>'
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/bin/pod:25:in `load'
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/bin/pod:25:in `<main>'

这是因为xcode的最新默认Project Format设置成Xcode 14.0-compatible 改成Xcode 9.3-compatible即可 image.png

image.png


出现的问题:

You don’t have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.

/Library/Ruby/Site/2.6.0/rubygems/dependency.rb:311:in to_specs': Could not find 'json' (>= 1.5.1) among 50 total gem(s) (Gem::MissingSpecError) Checked in 'GEM_PATH=/Users/aaa/.rvm/gems/ruby-2.6.6:/Users/aaa/.rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0:/usr/local/Cellar/cocoapods/1.11.2_1/libexec' , execute gem env` for more information

解决方案: M1芯片

1
2
3
4
5
6
7
8
9
10
Right clic Terminal from the Application/Utilities folder, Get Info, tick the "Open using Rosetta" box.
Uninstall Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
rm -rf /opt/homebrew/*
sudo rm -rf /opt/homebrew
Reinstall Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Restart terminal
Check Homebrew is working fine: brew doctor
Reinstall openssl: brew install openssl

Intel芯片

1
2
3
4
5
6
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm list known
rvm install 2.6.6
ruby -v
sudo gem install -n /usr/local/bin cocoapods

参考: https://clay-atlas.com/blog/2021/02/22/ruby-cn-extconf-failed-solution/ https://blog.csdn.net/mp624183768/article/details/106049466


今日又有同事遇到一个新问题 运行pod时提示ruby3.1.2与2.4.7冲突,导致pod不能使用,查找了很多资料花了很多时间才解决 思路: 删除除系统自带版本的其他ruby,重置相关路径,然后重新下载一个较新的3.0.0的版本

卸载除系统自带的旧版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 1、查看ruby的安装目录
which -a ruby
# npm 安装的
# /Users/xxx/.rvm/rubies/ruby-2.6.6/bin/ruby 
# homebrew安装的
# /usr/local/opt/ruby/bin/ruby 
# 系统自带的
# /usr/bin/ruby

# 查看使用的默认版本
rvm -v

# 本地已安装版本
rvm list
# 可以下载安装的版本
rvm list known

#rvm安装
rvm install 2.6.6
rvm automount
#rvm删除
rvm remove 2.6.6

# brew 安装
brew install ruby
# brew删除
brew uninstall --force ruby
brew autoremove

安装好ruby后提示不是不是优先的版本

Warning! PATH is not properly set up, ‘/Users/***/.rvm/gems/ruby-2.4.0/bin’ is not at first place

重置下解决 rvm reset

设置默认版本的全局变量

1
2
3
4
5
6
which -a ruby
# 将ruby版本设置成path
#echo 'export PATH="xxxx/ruby/bin:$PATH"' >> ~/.zshrc
# 比如
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

参考:
Cocoapods 杂谈
Ruby 的安装与卸载
二、 RVM 的安装和使用
Warning! PATH is not properly set up, ‘/Users/***/.rvm/gems/ruby-2.4.0/bin’ is not at first place.

This post is licensed under CC BY 4.0 by the author.