IOS之 安装cocoapods问题

1,安装cocoapods

sudo gem install cocoapods

问题:ERROR:  Could not find a valid gem 'cocoapods' (>= 0) in any repository

2,升级gem

移除旧源,gem sources --remove https://gems.ruby-china.org/

 添加新源,gem sources -a https://gems.ruby-china.com

检查新源,gem sources -l

问题:报错ssl证书错误

Error fetching https://gems.ruby-china.com:
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://gems.ruby-china.com/specs.4.8.gz)

3,检查自己的OpenSSL正式是否过期

rvm osx-ssl-certs

问题:Certificates for ~/Documents/ssldir/~/Documents/ssldir/cert.pem: Old.

4,更新OpenSSL证书

rvm osx-ssl-certs update all

问题:证书不能找到
Selected SSL certs for: curl
cURL certificate bundle /usr/share/curl/curl-ca-bundle.crt not found

5,切换root环境

sudo -i

6,再次安装cocoapods

sudo gem install cocoapod

问题:Ruby必须大于2.7.0.

error installing cocoapods: activesupport requires Ruby version >= 2.7.0.

7,查看rvm列表

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]

8,查看当前rvm版本

rvm -v

结果:获取成功

rvm 1.29.12 (manual) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

9,更新rvm版本

curl -L get.rvm.io | bash -s stable

结果:更新成功,但还是低版本的

Thanks for installing RVM

10,安装Homebrew

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

问题:以root身份运行Homebrew非常危险,不再受支持。由于Homebrew不会在安装时放弃特权,因此您将付出所有构建对系统的完全访问权限的脚本。

Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

11,安装rvm指定版本2.7

rvm install 2.7

问题:以root身份运行Homebrew非常危险,不再受支持。由于Homebrew不会在安装时放弃特权,因此您将付出所有构建对系统的完全访问权限的脚本

Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.14/x86_64/ruby-2.7.2.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

12,切换普通身份,rvm指定版本2.7

rvm install 2.7

结果:自动更新环境系统

Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.14/x86_64/ruby-2.7.2.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Installing requirements for osx.
Updating system........Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, libksba, readline, zlib, [email protected]...................................
Certificates bundle '/usr/local/etc/[email protected]/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/dong/.rvm/rubies/ruby-2.7.2, this may take a while depending on your cpu(s)...
ruby-2.7.2 - #downloading ruby-2.7.2, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 14.0M  100 14.0M    0     0  92539      0  0:02:38  0:02:38 --:--:-- 95229
ruby-2.7.2 - #extracting ruby-2.7.2 to /Users/dong/.rvm/src/ruby-2.7.2.....
ruby-2.7.2 - #configuring.........................................................................
ruby-2.7.2 - #post-configuration.
ruby-2.7.2 - #compiling........................................................................
ruby-2.7.2 - #installing............
ruby-2.7.2 - #making binaries executable...
Installed rubygems 3.1.4 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation.
ruby-2.7.2 - #gemset created /Users/dong/.rvm/gems/ruby-2.7.2@global
ruby-2.7.2 - #importing gemset /Users/dong/.rvm/gemsets/global.gems.................................there was an error installing gem rubygems-bundler
...............................
ruby-2.7.2 - #generating global wrappers........
ruby-2.7.2 - #gemset created /Users/dong/.rvm/gems/ruby-2.7.2
ruby-2.7.2 - #importing gemsetfile /Users/dong/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.7.2 - #generating default wrappers........
ruby-2.7.2 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.7.2 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri


13,查看rvm版本

rvm install 2.7

结果:

rvm 1.29.12 (manual) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

14,再次安装rvm 2.7

rvm install 2.7

结果:已经安装,要重新安装,请使用:rvm重新安装ruby-2.7.2

Already installed ruby-2.7.2.
To reinstall use:rvm reinstall ruby-2.7.2

15,查看已经安装的rvm版本

rvm list

注: RubyGems(简称 gems)是一个用于对 Ruby组件进行打包的 Ruby 打包系统。 它提供一个分发 Ruby 程序和库的标准格式,还提供一个管理程序包安装的工具。

结果:

=* ruby-2.7.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

16,再次执行升级gem

移除旧源,gem sources --remove https://gems.ruby-china.org/

 添加新源,gem sources -a https://gems.ruby-china.com

检查新源,gem sources -l

结果:成功,不再第2步的证书过期错误

https://gems.ruby-china.com/ added to sources

*** CURRENT SOURCES ***

https://gems.ruby-china.com/

到这里就已经把Ruby环境成功的安装到了Mac OS X上,接下来就可以进行相应的开发使用了

17,安装home-brew

也可选择跳过这步, 直接安装cocoapods, 引入库文件时, 会提示你自动安装home-brew
Homebrew: 是一个包管理器,用于在Mac上安装一些OS X没有的UNIX工具。
官方网址: https://brew.sh/index_zh-cn
Homebrew是完全基于 Git 和 ruby.

安装
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

检测是否存在冲突
$ brew doctor
 
检查是否安装成功, 出现版本号就成功了.
$ brew --version

结果:安装成功

Homebrew 4.0.4
Homebrew/homebrew-core (git revision ea3642558b6; last commit 2023-03-04)
Homebrew/homebrew-cask (git revision f1134401b4; last commit 2023-03-04)

18,再次安装Cocoapods

sudo gem install cocoapods

结果:终于安装成功

Fetching tzinfo-2.0.6.gem
Fetching activesupport-7.0.4.2.gem
Fetching nap-1.1.0.gem
Fetching httpclient-2.8.3.gem
Fetching concurrent-ruby-1.2.2.gem
Fetching i18n-1.12.0.gem
Fetching algoliasearch-1.27.5.gem
Fetching ffi-1.15.5.gem
Fetching fuzzy_match-2.0.4.gem
Fetching typhoeus-1.4.0.gem
Fetching cocoapods-downloader-1.6.3.gem
Fetching addressable-2.8.1.gem
Fetching cocoapods-core-1.12.0.gem
Fetching ethon-0.16.0.gem
Fetching claide-1.1.0.gem
Fetching molinillo-0.8.0.gem
Fetching atomos-0.1.3.gem
Fetching cocoapods-search-1.0.1.gem
Fetching cocoapods-deintegrate-1.0.5.gem
Fetching netrc-0.11.0.gem
Fetching public_suffix-4.0.7.gem
Fetching cocoapods-try-1.2.0.gem
Fetching cocoapods-plugins-1.0.0.gem
Fetching xcodeproj-1.22.0.gem
Fetching rexml-3.2.5.gem
Fetching cocoapods-trunk-1.6.0.gem
Fetching CFPropertyList-3.0.6.gem
Fetching colored2-3.1.2.gem
Fetching nanaimo-0.3.0.gem
Fetching escape-0.0.4.gem
Fetching fourflusher-2.3.1.gem
Fetching gh_inspector-1.1.3.gem
Fetching ruby-macho-2.5.1.gem
Fetching cocoapods-1.12.0.gem
Successfully installed concurrent-ruby-1.2.2
Successfully installed i18n-1.12.0
Successfully installed tzinfo-2.0.6
Successfully installed activesupport-7.0.4.2
Successfully installed nap-1.1.0
Successfully installed fuzzy_match-2.0.4
Successfully installed httpclient-2.8.3
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.15.5
Successfully installed ethon-0.16.0
Successfully installed typhoeus-1.4.0
Successfully installed netrc-0.11.0
Successfully installed public_suffix-4.0.7
Successfully installed addressable-2.8.1
Successfully installed cocoapods-core-1.12.0
Successfully installed claide-1.1.0
Successfully installed cocoapods-deintegrate-1.0.5
Successfully installed cocoapods-downloader-1.6.3
Successfully installed cocoapods-plugins-1.0.0
Successfully installed cocoapods-search-1.0.1
Successfully installed cocoapods-trunk-1.6.0
Successfully installed cocoapods-try-1.2.0
Successfully installed molinillo-0.8.0
Successfully installed atomos-0.1.3
Successfully installed rexml-3.2.5
Successfully installed CFPropertyList-3.0.6
Successfully installed colored2-3.1.2
Successfully installed nanaimo-0.3.0
Successfully installed xcodeproj-1.22.0
Successfully installed escape-0.0.4
Successfully installed fourflusher-2.3.1
Successfully installed gh_inspector-1.1.3
Successfully installed ruby-macho-2.5.1
Successfully installed cocoapods-1.12.0
Parsing documentation for concurrent-ruby-1.2.2
Installing ri documentation for concurrent-ruby-1.2.2
Parsing documentation for i18n-1.12.0
Installing ri documentation for i18n-1.12.0
Parsing documentation for tzinfo-2.0.6
Installing ri documentation for tzinfo-2.0.6
Parsing documentation for activesupport-7.0.4.2
Installing ri documentation for activesupport-7.0.4.2
Parsing documentation for nap-1.1.0
Installing ri documentation for nap-1.1.0
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for httpclient-2.8.3
Installing ri documentation for httpclient-2.8.3
Parsing documentation for algoliasearch-1.27.5
Installing ri documentation for algoliasearch-1.27.5
Parsing documentation for ffi-1.15.5
Installing ri documentation for ffi-1.15.5
Parsing documentation for ethon-0.16.0
Installing ri documentation for ethon-0.16.0
Parsing documentation for typhoeus-1.4.0
Installing ri documentation for typhoeus-1.4.0
Parsing documentation for netrc-0.11.0
Installing ri documentation for netrc-0.11.0
Parsing documentation for public_suffix-4.0.7
Installing ri documentation for public_suffix-4.0.7
Parsing documentation for addressable-2.8.1
Installing ri documentation for addressable-2.8.1
Parsing documentation for cocoapods-core-1.12.0
Installing ri documentation for cocoapods-core-1.12.0
Parsing documentation for claide-1.1.0
Installing ri documentation for claide-1.1.0
Parsing documentation for cocoapods-deintegrate-1.0.5
Installing ri documentation for cocoapods-deintegrate-1.0.5
Parsing documentation for cocoapods-downloader-1.6.3
Installing ri documentation for cocoapods-downloader-1.6.3
Parsing documentation for cocoapods-plugins-1.0.0
Installing ri documentation for cocoapods-plugins-1.0.0
Parsing documentation for cocoapods-search-1.0.1
Installing ri documentation for cocoapods-search-1.0.1
Parsing documentation for cocoapods-trunk-1.6.0
Installing ri documentation for cocoapods-trunk-1.6.0
Parsing documentation for cocoapods-try-1.2.0
Installing ri documentation for cocoapods-try-1.2.0
Parsing documentation for molinillo-0.8.0
Installing ri documentation for molinillo-0.8.0
Parsing documentation for atomos-0.1.3
Installing ri documentation for atomos-0.1.3
Parsing documentation for rexml-3.2.5
Installing ri documentation for rexml-3.2.5
Parsing documentation for CFPropertyList-3.0.6
Installing ri documentation for CFPropertyList-3.0.6
Parsing documentation for colored2-3.1.2
Installing ri documentation for colored2-3.1.2
Parsing documentation for nanaimo-0.3.0
Installing ri documentation for nanaimo-0.3.0
Parsing documentation for xcodeproj-1.22.0
Installing ri documentation for xcodeproj-1.22.0
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for fourflusher-2.3.1
Installing ri documentation for fourflusher-2.3.1
Parsing documentation for gh_inspector-1.1.3
Installing ri documentation for gh_inspector-1.1.3
Parsing documentation for ruby-macho-2.5.1
Installing ri documentation for ruby-macho-2.5.1
Parsing documentation for cocoapods-1.12.0
Installing ri documentation for cocoapods-1.12.0
Done installing documentation for concurrent-ruby, i18n, 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, rexml, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 22 seconds
34 gems installed
 

19,查看是否安装成功

pod search afnetworking

结果:安装成功

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

如果没有安装成功,提示Setting up CocoaPods master repo。也可以输入which pod有路径显示就证明安装成功

20,使用cocoapods,首先进行初始化,终端中cd 到项目文件夹,然后执行pod init。在工程目录下生成Podfile文件

打开文件路径栏,复制路径,然后执行cd /Users/dong/Documents/百思不得姐,然后执行,pod init

结果:Podfile已经存在

 Existing Podfile found in directory

21,可通过vim Podfile进行编辑文件,也可直接通过文本查看器打开。
接下来安装库,在Podfile中添加 pod ‘库名’ 并保存

pod "AFNetworking"

结果:完成文件内容如下:

platform :ios, '8.0'

pod "AFNetworking"
target 'test' do
end

22,输入pod install安装库,安装成功则提示Pod installation complete

pod install

结果:

[!] Unable to find a target named `test` in project `百思不得姐.xcodeproj`, did find `百思不得姐`.

23,更换target 'test' do 为工程名 target '百思不得姐' do,再次执行pod install

platform :ios, '8.0'

pod "AFNetworking"
target '百思不得姐' do
end


结果:成功

Analyzing dependencies
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Downloading dependencies
Installing AFNetworking (3.2.1)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `百思不得姐.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

[!] AFNetworking has been deprecated in favor of Alamofire

24,打开xcode项目,如果可以引用到AFNetworking,则说明已经成功

#import "AFNetworking.h"//主要用于网络请求方法

-(void)obtainData{AFHTTPRequestOperationManager *manager   [AFHTTPRequestOperationManager  manager];                                           
}

25,到此经过几天努力,终于安装上了cocoapods,此外可能安装过程可能遇到其它问题也在这写明,可以参考是否遇到类似问题

安装步骤

下载Xcode —>安装rvm —>安装ruby —>安装home-brew —>安装cocoapods

xcode,苹果开发工具,可用于object-c和swift语言开发苹果收集和手表软件应用

RVM,是Ruby的版本管理工具,uby执行需要ruby解释器,rvm就是管理ruby解释器版本的,安装、卸载、更新、切换 等

Ruby,一种简单快捷的面向对象(面向对象程序设计)脚本语言,是用来构建CocoaPods的

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。这里主要用于安装Ruby语言环境

CocoaPods是OS X和iOS下的一个第三类库管理工具,通过CocoaPods工具我们可以为项目添加被称为“Pods”的依赖库(这些类库必须是CocoaPods本身所支持的),并且可以轻松管理其版本

问题1:

ERROR: Could not find a valid gem 'cocoapods' (>= 0) in any repository 错误

也可以安装xcodexcode命令行工具包进行尝试解决sudo xcode-select --install

问题2:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

解决:

更新homebrew

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

问题3:

homebrew-core is a shallow clone.

To `brew update`, first run:

git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

解决:

cd /usr/local/Homebrew/Library/Taps/homebrew

rm -rf homebrew-core

brew upgrade

完成后继续执行:

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

问题4:

xcode-select: error: command line tools are already installed, use "Software Update" to install

解决:

sudo  rm -rf /Library/Developer/CommandLineTools

sudo  xcode-select --install

问题5

每次打开cocoapods编辑器比较麻烦,我们可以安装cocoapods可视化插件,可以先安装Alcatraz插件管理器

解决:

下一章我们将详细讲解Alcatraz插件管理器和cocoapods插件的安装和使用

本教程基于macos10.14.6和xcode11.3.1

猜你喜欢

转载自blog.csdn.net/qq_29848853/article/details/129340315