cocoapods安装过程遇到的问题

cocoapods是iOS开发的依赖管理开发工具,iOS开发不可避免的会使用到第三方库,cocoapods可以为我们节省设置和更新第三方库的时间

macOS High Sierra 10.13.2   xcode10

按照教程安装cocoapods后,运行pod --version,很悲剧的提示command not found

于是卸载重装,悲剧又一次重演,使用了网上说的各种方法,都是不行,而且使用sudo gem update --system时总是提示没有写的权限。貌似mac自带的ruby更新,即使用了管理员权限

于是决定重装ruby。重装过程如下:

一、重装前先检查是否有安装残留

1、若之前重装过cocoapods,先卸载,卸载命令:$ sudo gem uninstall cocoapods

2、先查看本地安装过的cocoapods相关组件,命令$ sudo gem list | greo cocoapods,显示如下:


cocoapods安装过程遇到的问题_第1张图片

使用命令

sudo gem uninstall cocoapods

sudo gem uninstall cocoapods-core

sudo gem uninstall cocoapods-deintegrate

sudo gem uninstall cocoapods-downloader

sudo gem uninstall cocoapods-plugins

sudo gem uninstall cocoapods-search

sudo gem uninstall cocoapods-stats

sudo gem uninstall cocoapods-trunk

sudo gem uninstall cocoapods-try

将所有组件卸载

3、先把Mac隐藏文件夹显示出来,Mac隐藏和显示的命令如下:

隐藏:defaults write com.apple.finder AppleShowAllFiles -bool true

显示:defaults write com.apple.finder AppleShowAllFiles -bool false

4、退出终端,重启访达

5、重新安装ruby和cocoapods

二、RVM-ruby-cocoapods

1、安装RVM

命令:$ curl -L https://get.rvm.io | bash -s stable

安装过程中会要求输入管理员密码,以及自动通过homebrew安装依赖包,等待一段时间后就可以成功安装好 RVM

然后,载入RVM 环境

命令:$ source ~/.rvm/scripts/rvm

2、检查RVM安装是否正确

$ rvm -v

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

3、用rvm安装ruby环境

列出已知ruby版本

$ 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[.7]

[ruby-]2.4[.4]

[ruby-]2.5[.1]

[ruby-]2.6[.0-preview2]

选择要安装的版本,我选择的是[ruby-]2.6[.0-preview2]

$ rvm install 2.6.0-preview2

按照系统提示一步一步走,等待漫长的下载,编译完成,ruby,ruby gems就安装完成了

4、查询已安装的ruby

$ rvm list

=* ruby-2.6.0-preview2 [ x86_64 ]

# => - current

# =* - current && default

#  * - default

5、设置默认ruby版本

ruby安装以后需要执行下面的命令将指定版本的ruby设置为系统默认的版本

dongcheng$ rvm 2.6.0-preview2 default

Using /Users/dongcheng/.rvm/gems/ruby-2.6.0-preview2

如果用rvm install安装过其他ruby版本,也可以设置其他版本为默认版本

测试一下当前使用的ruby版本是否正确:

$ ruby -v

ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-darwin17]

6、gem为ruby的包管理系统

$ gem -v

3.0.0.beta1

三、安装cocoapods

1、查看ruby镜像服务器

$ gem sources -l

如果是https://rubygems.org/,将之替换为https://gems.ruby-china.com/

命令$ sudo gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

查看替换后的镜像:

$ gem sources

*** CURRENT SOURCES ***

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

这样就ruby环境成功安装到了macOS X上

2、安装cocoapods

命令:$ sudo gem install -n /usr/loacl/bin cocoapods

设置cocoapods

$ pod setup

到这里cocoapods就成功安装并可以使用了

尝试命令:

$ pod search 'GT'


-> GT (2.3.3)

   A short description of GT.

   pod 'GT', '~> 2.3.3'

   - Homepage: http://gt.tencent.com/

   - Source:  https://github.com/njafei/GTFramework.git

   - Versions: 2.3.3 [master repo]

   - Subspecs:

     - GT/GT (2.3.3)

3、安装 pod

pod install 或者pod install --verbose --no-repo-update(如果前者不行,就用后者,推荐前者)

解决安装第三方库慢,更新第三方库慢得问题

pod install --verbose --no-repo-update

pod update --verbose --no-repo-update

四、安装过程中遇到的其他问题

1、Unable to find a pod with name, author, summary, or descriptionmatching `AFNetworking`

推荐使用  rm ~/Library/Caches/CocoaPods/search_index.json

~/Library/Caches/CocoaPods中重新生成了一份新的search_index.json。并且能找到AFNetworking对应的资源了

此后需要搜索其他第三方库时,无需再删除search_index.json文件,直接搜索即可

完事。


参考:https://www.jianshu.com/p/712644abf655

你可能感兴趣的:(cocoapods安装过程遇到的问题)