cocopods安装与配置 卸载

前期准备

CocoaPods的安装需要Ruby环境,Mac系统都自带Ruby,通过下面终端命令查看Ruby版本:
ruby -v

192:~ ***$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

CocoaPods支持的Ruby最低版本是2.2.2,如果自己的版本低于2.2.2就需要更新升级Ruby:

sudo gem update --system

更换Ruby镜像

Ruby默认的源地址是国外网络地址,通过下面终端命令查看当前镜像地址:
gem sources -l

~$gem sources -l
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Applications/Cocos/tools/ant/bin in PATH, mode 040777
*** CURRENT SOURCES ***

https://rubygems.org/

首先移除当前镜像
gem sources --remove https://rubygems.org/

~$gem sources --remove https://rubygems.org/
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Applications/Cocos/tools/ant/bin in PATH, mode 040777
https://rubygems.org/ removed from sources

然后添加国内最新Ruby镜像地址
gem sources -a https://gems.ruby-china.com/

~$gem sources -a https://gems.ruby-china.com/
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Applications/Cocos/tools/ant/bin in PATH, mode 040777
https://gems.ruby-china.com/ added to sources

这时候再查看镜像地址就是这样的了

192:~ ***$ gem sources -l
*** CURRENT SOURCES ***

https://gems.ruby-china.com/
192:~ ***$ 

安装CocoaPods

Ruby环境安装好以后,接下来就是安装CocoaPods,终端输入:
sudo gem install cocoapods

Mac OS X 10.11前

sudo gem install cocoapods

Mac OS X 10.11后

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

如果终端出现下面的提示,表示安装成功。

~$sudo gem install cocoapods
Password:
......

Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, activesupport, nap, fuzzy_match, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, molinillo, atomos, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 33 seconds
28 gems installed

注意如果出现错误

# [ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod](https://www.cnblogs.com/yujinzhong/p/6198015.html)

就执行以下命令

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

到这里还剩最后一步,还需执行命令:
pod setup
这一步可能需要耐心等待,需要下载上百M的文件。

~$pod setup
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Applications/Cocos/tools/ant/bin in PATH, mode 040777
Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Enumerating objects: 179, done.        
  remote: Counting objects: 100% (179/179), done.        
  remote: Compressing objects: 100% (135/135), done.        
  remote: Total 2819986 (delta 66), reused 64 (delta 42), pack-reused 2819807        
  Receiving objects: 100% (2819986/2819986), 614.27 MiB | 834.00 KiB/s, done.
  Resolving deltas: 100% (1676501/1676501), done.
  Checking out files: 100% (304760/304760), done.
Setup completed

至此,CocoaPods安装完成!

查看pod版本 pod --version

$ pod --version
1.9.0

注意:我遇到的问题:
1.setup时 不执行,不卡顿的问题
2.setup执行,未出现Setting up CocoaPods master repo 立马出现Setup completed(Mac osx新系统是这种情况,这时需要手动安装本地库,直接看下面解决方法)
执行pod search AFNetworking会报如下错误

***@192 ~ % pod search AFNetworking
Setup completed
[!] Unable to find a pod with name, author, summary, or description matching `AFNetworking`

解决方法
(推荐)方法一:
直接去Git上拉,终端输入

$git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master

也可以执行下面命令

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

或者使用下面的,国内镜像,速度快些

git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git  ~/.cocoapods/repos/trunk

使用后面两个命令的目录结构如下图


image.png

方法二:
1.要是以上命令比较慢或者执行不成功,就到 https://github.com/CocoaPods/Specs.git 把文件clone下来,默认文件夹名字为Specs-master
2.前往文件夹 ~/.cocoapods/repos
3.Specs-master文件夹名字修改为master,并替换~/.cocoapods/repos 下的master文件夹,要是没有master文件夹,直接放进去就好

但是这种方法会出现部分库可以下载,部分不行。还是建议使用方法一

验证cocopods是否安装成功
在使用之前,我们先验证下CocoaPods是否安装成功,搜索一个第三方库。终端输入:pod search AFNetworking

~$pod search AFNetworking

正常情况下,这是会提示Creating search index for spec repo 'master'...等待一会就会出现搜索结果了(也可能需要等待很长时间,大约二十几分钟,不要着急,耐心等待就行)。


image

出现上图这个就说明成功了。直接按“Q”键就可以退出。

更新pods 本地库

pod install --repo-update

执行结果

ios001@bogon appdemo % pod install --repo-update
Updating local specs repositories
/Users/ios001/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/cocoapods-core-1.9.3/lib/cocoapods-core/cdn_source.rb:342: warning: URI.escape is obsolete
  $ /usr/bin/git -C /Users/ios001/.cocoapods/repos/cocoapods fetch origin
  --progress
  remote: Enumerating objects: 52103, done.        
  remote: Counting objects: 100% (52103/52103), done.        
  remote: Compressing objects: 100% (432/432), done.        
  remote: Total 215474 (delta 51792), reused 51882 (delta 51652), pack-reused 163371        
  Receiving objects: 100% (215474/215474), 25.43 MiB | 11.00 KiB/s, done.
  Resolving deltas: 100% (150687/150687), completed with 8903 local objects.
  From https://github.com/CocoaPods/Specs
     77f9552132dd..bf078067b87c  master            -> origin/master
   * [new branch]                igor/fix-workflow -> origin/igor/fix-workflow
  $ /usr/bin/git -C /Users/ios001/.cocoapods/repos/cocoapods rev-parse
  --abbrev-ref HEAD
  master
  $ /usr/bin/git -C /Users/ios001/.cocoapods/repos/cocoapods reset --hard
  origin/master
  Updating files: 100% (453663/453663), done.
  HEAD is now at bf078067b87c [Add] SudoUser 7.13.0
Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project
/Users/ios001/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/cocoapods-core-1.9.3/lib/cocoapods-core/cdn_source.rb:342: warning: URI.escape is obsolete
Pod installation complete! There are 42 dependencies from the Podfile and 43 total pods installed.

卸载CocoaPods

查看是否安装:pod list

如果已安装:

*** LOCAL GEMS ***

activesupport (4.2.9)
bigdecimal (default: 1.2.0)
CFPropertyList (2.3.5, 2.2.8)
claide (1.0.2)
cocoa (0.1.6)
cocoapods (1.3.1)
cocoapods-core (1.4.0.beta.1, 1.3.1)
cocoapods-deintegrate (1.0.1)
cocoapods-downloader (1.1.3)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.2.0)
cocoapods-try (1.1.0)
colored2 (3.1.2)
escape (0.0.4)
ffi (1.9.18)
nanaimo (0.2.3)
...

如果未安装:

zsh: command not found: pod

删除

1.移除pod组件
这条指令会告诉你Cocoapods组件装在哪里 :

$ which pod

你可以手动移除这个组件 :

$ sudo rm -rf 

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

查看gems中本地程序包:

$ gem list

输出

*** LOCAL GEMS ***

activesupport (4.2.11.1)
algoliasearch (1.27.1)
atomos (0.1.3)
bigdecimal (default: 1.4.1)
bundler (default: 1.17.2)
CFPropertyList (2.3.6)
claide (1.0.3)
cmath (default: 1.0.0)
cocoa (0.1.6)
cocoapods (1.9.0)
cocoapods-core (1.9.0)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.3.0)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.1.0)
cocoapods-trunk (1.4.1)
cocoapods-try (1.1.0)
colored2 (3.1.2)
concurrent-ruby (1.1.6)
csv (default: 3.0.9)
date (default: 2.0.0)
dbm (default: 1.0.0)
did_you_mean (1.3.0)
e2mmap (default: 0.1.0)
escape (0.0.4)
etc (default: 1.0.1)
ethon (0.12.0)
fcntl (default: 1.0.0)
ffi (1.12.2)
fiddle (default: 1.0.0)
fileutils (default: 1.1.0)
forwardable (default: 1.2.0)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (0.9.5)
io-console (default: 0.4.7)
ipaddr (default: 1.2.2)
irb (default: 1.0.0)
json (default: 2.1.0)
libxml-ruby (3.1.0)
logger (default: 1.3.0)
matrix (default: 0.1.0)
mini_portile2 (2.4.0)
minitest (5.11.3)
molinillo (0.6.6)
mutex_m (default: 0.1.0)
nanaimo (0.2.6)
nap (1.1.0)
net-telnet (0.2.0)
netrc (0.11.0)
nokogiri (1.10.1)
openssl (default: 2.1.2)
ostruct (default: 0.1.0)
pods (0.0.1)
power_assert (1.1.3)
prime (default: 0.1.0)
psych (default: 3.1.0)
rake (12.3.2)
rdoc (default: 6.1.0)
rexml (default: 3.1.9)
rss (default: 0.2.7)
ruby-macho (1.4.0)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
shell (default: 0.7)
sqlite3 (1.3.13)
stringio (default: 0.0.2)
strscan (default: 1.0.0)
sync (default: 0.5.0)
test-unit (3.2.9)
thread_safe (0.3.6)
thwait (default: 0.1.0)
tracer (default: 0.1.0)
typhoeus (1.3.1)
tzinfo (1.2.6)
webrick (default: 1.4.2)
xcodeproj (1.15.0)
xmlrpc (0.3.0)
zlib (default: 1.0.0)

发现有cocopods相关包

cocoapods (1.9.0)
cocoapods-core (1.9.0)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.3.0)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.1.0)
cocoapods-trunk (1.4.1)
cocoapods-try (1.1.0)

移除cocopods程序包

$ sudo gem uninstall cocoapods

输出

Remove executables:
    pod, sandbox-pod

in addition to the gem? [Yn]  y
Removing pod
Removing sandbox-pod
Successfully uninstalled cocoapods-1.9.0

依次移除pods包

$ sudo gem uninstall cocoapods-core
Successfully uninstalled cocoapods-core-1.9.0
$ sudo gem uninstall cocoapods-deintegrate
Successfully uninstalled cocoapods-deintegrate-1.0.4
$ sudo gem uninstall cocoapods-downloader 
Successfully uninstalled cocoapods-downloader-1.3.0
$ sudo gem uninstall cocoapods-plugins   
Successfully uninstalled cocoapods-plugins-1.0.0
$ sudo gem uninstall cocoapods-search 
Successfully uninstalled cocoapods-search-1.0.0
$ sudo gem uninstall cocoapods-stats 
Successfully uninstalled cocoapods-stats-1.1.0
$ sudo gem uninstall cocoapods-trunk
Successfully uninstalled cocoapods-trunk-1.4.1
$ sudo gem uninstall cocoapods-try  
Successfully uninstalled cocoapods-try-1.1.0

全部移除完,再次执行gem list 输出结果未发现cocopods相关包

~/资源库/Caches/CocoaPods

卸载后有一些缓存并不会清理,可以进入~/资源库/Caches/CocoaPods目录手动清理。

你可能感兴趣的:(cocopods安装与配置 卸载)