前言:
cocopods
安装安装之前,一定要安装好Xcode
,否则在安装cocopods
时会报错。
cocopods
:各个版本https://rubygems.org/gems/cocoapods/versions
cocopods
安装步骤
1,安装HomeBrew
,看我其他文章Homebrew介绍和使用
2,安装ruby
,Mac一般自带,更新就行。
brew install ruby // 安装ruby
3,升级ruby
sudo gem update --system
4,查看ruby源
gem sources -l
//之后打印
*** CURRENT SOURCES ***
https://rubygems.org/
替换ruby源
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
注意:如果这步报错:Error fetching https://gems.ruby-china.com: Net::OpenTimeout: execution expired (https://gems.ruby-china.com/specs.4.8.gz)
最近配置新电脑发现使用 https://gems.ruby-china.com 源地址一直报错无法使用
解决:很多时候是网不好,曾经耽误大半天 ,换个网就好了。
安装或更新Cocoapods依赖:
sudo gem install cocoapods
查看是否替换成功
gem sources -l
如果出现的是
*** CURRENT SOURCES ***
https://gems.ruby-china.com
5,安装最新版本:两个命令,建议用第2个。
//1,sudo gem命令安装(ruby安装)。
sudo gem install -n /usr/local/bin cocoapods
//2,Homebrew命令安装。
brew install cocoapods
//安装指定版本
brew install cocoapods -v 1.11.2
Homebrew 踩坑Error: No similarly named formulae found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
Error: No available formula or cask with the name "htop".
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.
解决办法:
重新安装一次homebrew-core
cd /usr/local/Homebrew/Library/Taps/homebrew/
rm -rf homebrew-core
git clone https://github.com/Homebrew/homebrew-core.git
如果运行pod install
报错:
/Library/Ruby/Site/2.6.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'minitest' (>= 5.1) among 39 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/Users/jh/.local/share/gem/ruby/2.6.0:/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0:/usr/local/Cellar/cocoapods/1.11.3/libexec' , execute `gem env` for more information
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1409:in `block in activate_dependencies'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1397:in `each'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1397:in `activate_dependencies'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1379:in `activate'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1415:in `block in activate_dependencies'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1397:in `each'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1397:in `activate_dependencies'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1379:in `activate'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1415:in `block in activate_dependencies'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1397:in `each'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1397:in `activate_dependencies'
from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1379:in `activate'
from /Library/Ruby/Site/2.6.0/rubygems.rb:286:in `block in activate_bin_path'
from /Library/Ruby/Site/2.6.0/rubygems.rb:285:in `synchronize'
from /Library/Ruby/Site/2.6.0/rubygems.rb:285:in `activate_bin_path'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/bin/pod:23:in `'
网上说的升级ruby
,重装home brew
,卸载重新下载cocoapods
,升级cocoapods
。。。都都试了,不行。
最后,这么解决了的:
上面的信息:有这个/usr/local/Cellar/cocoapods
。安装的cocoapods在这个目录/usr/local/Cellar
下,出问题了。需要改成/usr/local/bin/pod
。
①,执行
gem list
打印
*** LOCAL GEMS ***
abbrev (default: 0.1.0)
actioncable (7.0.3)
actionmailbox (7.0.3)
actionmailer (7.0.3)
actionpack (7.0.3)
actiontext (7.0.3)
actionview (7.0.3)
activejob (7.0.3)
activemodel (7.0.3)
activerecord (7.0.3)
activestorage (7.0.3)
activesupport (7.0.3, 6.1.6)
addressable (2.8.0)
algoliasearch (1.27.5)
atomos (0.1.3)
base64 (default: 0.1.1)
benchmark (default: 0.2.0)
bigdecimal (default: 3.1.1)
builder (3.2.4)
bundler (default: 2.3.11)
CFPropertyList (3.0.5)
cgi (default: 0.3.1)
claide (1.1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (1.6.3)
colored2 (3.1.2)
concurrent-ruby (1.1.10)
crass (1.0.6)
csv (default: 3.2.2)
date (default: 3.2.2)
debug (1.4.0)
delegate (default: 0.2.0)
did_you_mean (default: 1.6.1)
digest (default: 3.1.0)
drb (default: 2.1.0)
english (default: 0.7.1)
erb (default: 2.2.3)
error_highlight (default: 0.3.0)
erubi (1.10.0)
escape (0.0.4)
etc (default: 1.3.0)
ethon (0.15.0)
fcntl (default: 1.0.1)
ffi (1.15.5)
fiddle (default: 1.1.0)
fileutils (default: 1.6.0)
find (default: 0.1.1)
forwardable (default: 1.3.2)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
getoptlong (default: 0.1.1)
gh_inspector (1.1.3)
globalid (1.0.0)
httpclient (2.8.3)
i18n (1.10.0)
io-console (default: 0.5.11)
io-nonblock (default: 0.1.0)
io-wait (default: 0.2.1)
ipaddr (default: 1.2.4)
irb (default: 1.4.1)
json (default: 2.6.1)
logger (default: 1.5.0)
loofah (2.18.0)
mail (2.7.1)
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.2)
minitest (5.15.0)
molinillo (0.8.0)
mutex_m (default: 0.1.1)
nanaimo (0.3.0)
nap (1.1.0)
net-ftp (0.1.3)
net-http (default: 0.2.0)
net-imap (0.2.3)
net-pop (0.1.1)
net-protocol (default: 0.1.2)
net-smtp (0.3.1)
netrc (0.11.0)
nio4r (2.5.8)
nkf (default: 0.1.1)
nokogiri (1.13.6 x86_64-darwin)
observer (default: 0.1.1)
open-uri (default: 0.2.0)
open3 (default: 0.1.1)
openssl (default: 3.0.0)
optparse (default: 0.2.0)
ostruct (default: 0.5.2)
pathname (default: 0.2.0)
power_assert (2.0.1)
pp (default: 0.3.0)
prettyprint (default: 0.1.1)
prime (0.1.2)
pstore (default: 0.1.1)
psych (default: 4.0.3)
public_suffix (4.0.7)
racc (default: 1.6.0)
rack (2.2.3.1)
rack-test (1.1.0)
rails (7.0.3)
rails-dom-testing (2.0.3)
rails-html-sanitizer (1.4.2)
railties (7.0.3)
rake (13.0.6)
rbs (2.1.0)
rdoc (default: 6.4.0)
readline (default: 0.0.3)
readline-ext (default: 0.1.4)
reline (default: 0.3.0)
resolv (default: 0.2.1)
resolv-replace (default: 0.1.0)
rexml (3.2.5)
rinda (default: 0.1.1)
rss (0.2.9)
ruby-macho (2.5.1)
ruby2_keywords (default: 0.0.5)
securerandom (default: 0.1.1)
set (default: 1.0.2)
shellwords (default: 0.1.0)
singleton (default: 0.1.1)
stringio (default: 3.0.1)
strscan (default: 3.0.1)
syslog (default: 0.1.0)
tempfile (default: 0.1.2)
test-unit (3.5.3)
thor (1.2.1)
time (default: 0.2.0)
timeout (default: 0.2.0)
tmpdir (default: 0.1.2)
tsort (default: 0.1.0)
typeprof (0.21.2)
typhoeus (1.4.0)
tzinfo (2.0.4)
un (default: 0.2.0)
uri (default: 0.11.0)
weakref (default: 0.1.1)
websocket-driver (0.7.5)
websocket-extensions (0.1.5)
xcodeproj (1.21.0)
yaml (default: 0.2.0)
zeitwerk (2.5.4)
zlib (default: 2.1.1)
②,一个个删除关于cocoapods
的库
gem uninstall cocoapods
gem uninstall cocoapods-core
gem uninstall cocoapods-downloader
gem uninstall cocoapods-plugins
gem uninstall cocoapods-search
gem uninstall cocoapods-stats
gem uninstall cocoapods-trunk
gem uninstall cocoapods-try
...上面的打印cocoapods都一一删除,仔细看看。
③,重新安装pod
在命令中,指定安装到/usr/bin/pods
下,即可正常安装成功:
sudo gem install -n /usr/local/bin cocoapods
这里就成了,可以找个项目试下pod init
就行了。
注释:sudo
和gem
都是shell
命令
①sudo
: 允许系统管理员让普通用户执行一些或者全部的root命令的一个工具。
(比如你不是/root账号
,但是需要安装gcc
软件,可以 sudo apt-get install gcc
)
②gem
: ruby
的包管理器
叫gem
。
报错情况
错误1: M1电脑 pod install 错误
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: https://www.ruby-lang.org/bugreport.html
[IMPORTANT]
Don't forget to include the Crash Report log file under
DiagnosticReports directory in bug reports.
[1] 4669 abort pod install
解决方法: 使用brew install cocoapods
安装cocoapods
, 再使用pod install
即可
错误2: cocoapods报错fatal: unable to access ‘XXX.git/‘: LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection
首先,Ruby镜像
一定要用(https://gems.ruby-china.org/),不要用淘宝的镜像(http://ruby.taobao.org/),淘宝的已经不好用了。
1:查看当前镜像库:
gem sources -l
2: 修改gem的库地址:
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
完成后确认下是否修改成功用gem sources -l
查一下
pod install报错
出现1:
[!] Smart quotes were detected and ignored in your Podfile. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.
解决:
多pod install
几次
出现2:
Automatically assigning platform `ios` with version `10.0` on target `CloudLive` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
解决:
去掉 #
# platform :ios, '10.0'
改为
platform :ios, '10.0'
标准的如下:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'
target '嘻嘻嘻' do
pod 'AFNetworking', '~> 3.1.0'
pod 'SDWebImage', '~>3.7.3'
pod 'Masonry', '~> 1.0.2'
pod 'HGTimerButton', '~> 1.0.3'
pod 'YYModel'
pod 'MJRefresh'
pod 'MBProgressHUD'
pod 'IQKeyboardManager', '~> 6.1.1'
pod 'MJExtension'
#pod 'Realm', '~> 3.1.0’
# 分段控件
#pod 'SGPagingView'
#pod install --verbose --no-repo-update
end