2018 cocoapods安装与更新


注意事项:安装CocoaPots的顺序:

(可跳到第四步做安装测试,不成功再从第一步开始)

Xcode -> homebrew -> RVM -> Ruby -> CocoaPots;

第一步:安装Homebrew

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
ps:https://blog.csdn.net/luohancc/article/details/46897247

第二步:安装gpg


gpg官网:https://gpgtools.org/


安装成功查看版本:$ gpg –version


第二步:安装vrm


1.修改安装目录的权限(有些文件可能会报不允许修改的错误,这个可以忽略。)
$ chmod + R 777 chmod -R 777 /Users/xxxusername/


2.执行官方命令 
$ \curl -sSL https://get.rvm.io | bash -s stable


检测,出现以下图片则表示安装成功
$ rvm --version


第三步:安装ruby

1.查看版本可以看到所有版本选择一个安装
$ rvm list known
2.安装ruby:
$ rvm install 2.4.0
3.查看ruby版本
$ ruby --version

4.安装ruby报错:Error running 'requirements_osx_brew_update_system ruby-2.4.0
解决方案:步骤1:
$ brew install autoconf automake libtool pkg-config apple-gcc42 libyaml readline libxml2 libxslt libksba openssl sqlite
此方案会报错Error: No available formula with the name "apple-gcc42"==> Searching for similarly named formulae...Error: No similarly named formulae found.==> Searching taps...This formula was found in a tap:homebrew/dupes/apple-gcc42To install it, run:brew install homebrew/dupes/apple-gcc42这就是一波未平一波又起,幸运的报错提示明确的给出了此问题的解决方案

步骤2:$brew install homebrew/dupes/apple-gcc42

然后继续安装即可
$ rvm install 2.3.1

第四步:安装cocoapods

1.查看gem源:$ gem sources -l
2.删除gem源:$ gem sources --remove https://ruby.taobao.org/
3.修改gem源:$ gem sources -a https://gems.ruby-china.org
4.安装cocoapods:
       $ sudo gem install cocoapods           
       // Mac OS X 10.11前 输入这一条
       $ sudo gem install -n /usr/local/bin cocoapods
       //Mac OS X 10.11后 输入这一条
5.执行pod文件下载:$ pod setup
6.查看升级后的cocoapods版本:$ pod --version

某些环境原因导致pod更新不了,可能原因有
1)gem版本太低;     
      更新gem:$ sudo gem update --system
2)github无法链接;$ ping github.com       
      无法ping通"打开网络偏好设置->高级->DNS->DNS服务器(8.8.8.8)"
3).cocoapods目录下的配置信息错误。     
      $ pod repo list     
      结果显示0 repos,说明没有安装成功;
4. 删除.cocoapods目录,重新下载pod更新:
      $ cd ~/.cocoapods/
      $ sudo -rm -rf ~/.cocoapods/
      重新执行pod setup,过一段时间后提示setup completed,在终端中输入 pod list,展示出安装列表;

第五步:更新cocoapods

1.sudo gem update --system

2.1.$ sudo gem install cocoapods                   
// Mac OS X 10.11前 输入这一条        
2.2. $ sudo gem install -n /usr/local/bin cocoapods      
 //Mac OS X 10.11后 输入这一条

3.pod setup
4.pod --version

第六步:使用cocoapods

1.新建Podfile文件:$ touch Podfile
2.使用命令修改文件:$ vim Podfile
3.执行pod:pod install  或 pod install --verbose --no-repo-update
4.更新pod:pod update 或 pod update --verbose --no-repo-update

5. cocoaPods隐藏目录 > + 前往—>个人—>.cocoapods > + .cocoapods/repos/master/Specs

OC:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target '[项目名称]' do
pod 'AFNetworking'
end

Swift:

source 'https://github.com/CocoaPods/Specs.git'
 platform :ios, '8.0'
use_frameworks!
target 'HJProject' do
pod 'AFNetworking'
 #  Swift3.x 如果需要使用 use_frameworks! 则需要加上一下配置才行
post_install do |installer|
       installer.pods_project.targets.each do |target|                        target.build_configurations.each do |config|                                      config.build_settings['SWIFT_VERSION'] = ‘3.0’           
                     end     
            end
        end
end

use_frameworks! 介绍
Swift 2.3 / 3.0如何正确配置Podfile并添加第三方库(也就是上面Swift Podfile文件中 post_install do |installer|...... 这一段的介绍以及用意 为什么要这么用)

这个Podfile文件是有固定格式的,也可以在第三方的Github中找到的:


最后添加几个参考地址:
1.rvm
https://blog.csdn.net/taishanduba/article/details/72055317
https://blog.csdn.net/luohancc/article/details/46897247
2.ruby
https://ruby-china.org/wiki/install_ruby_guide
https://blog.csdn.net/qqlinxi/article/details/53648227
3.cocoapods更新升级
https://blog.csdn.net/mx666666/article/details/53332263
https://blog.csdn.net/potato512/article/details/62235282
https://www.jianshu.com/p/90ca71b3b94a
CocoaPods的安装以及遇到的坑
http://www.cocoachina.com/ios/20160922/17622.html

你可能感兴趣的:(2018 cocoapods安装与更新)