ios_2017年安装CocoaPods Mac OS 10.12.2 系统

28 篇文章 0 订阅
15 篇文章 0 订阅

给大家推荐一个用homebrew安装的,可参考
http://blog.csdn.net/zhang5690800/article/details/51891879

CocoaPods使用步骤(已有Ruby环境):
(没有Ruby环境也没关系,后面会安装升级的,或者翻我之前安装Ruby环境文章也行)
(注: 1., gem sources –remove https://rubygems.org/

等有反应之后再敲入以下命令
$ gem sources -a https://ruby.taobao.org/

为了验证你的Ruby镜像是并且仅是taobao,可以用以下命令查看:
$ gem sources -l

只有在终端中出现下面文字才表明你上面的命令是成功的:

* CURRENT SOURCES *

https://ruby.taobao.org/

1.5升级gem命令:$ sudo gem update –system

2.安装CocoaPods,在终端输入
$ sudo gem install cocoapods
这里出现问题了.安装不了,

下面是解决方法:
这个地方很坑,之前安装cocoapods一直是没有这个问题的,这里提示Ruby版本要大于或等于2.2.2
于是查看ruby版本
$ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
果然这里就要升级Ruby版本啦
查看目前的所有ruby版本:
$rvm list known

如果提示command not found 请先安装rvm

在Mac上安装好ruby的RVM后,
在终端输入时,出现rvm: command not found,经过OverStackFlow上的查找,
发现了解决办法:rvm: command not found MAC OX
可能是因为ram的shell配置没有加载,在终端输入:
$ source ~/.rvm/scripts/rvm

接着输入:
$ type rvm | head -n 1

如果输出是rvm is a function,
则需要将source ~/.rvm/scripts/rvm添加到~/.bash_profile文件中。
$Sudo vi ~/.bash_profile

则需要将source ~/.rvm/scripts/rvm添加到~/.bash_profile文件中。 然后保存退出 $esc:wq

}
如果有ruby版本则不需要这行($curl -L get.rvm.io | bash -s stable )
如果已安装会列出所有的ruby版本:

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[.8]
[ruby-]2.2[.4]
[ruby-]2.3[.0]
[ruby-]2.2-head
ruby-head

for forks use: rvm install ruby-head- –url https://github.com/github/ruby.git –branch 2.2

JRuby

jruby-1.6[.8]
jruby-1.7[.23]
jruby[-9.0.5.0]
jruby-head

Rubinius

rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx[-2.5.8]
rbx-head

Opal

opal

Minimalistic ruby implementation - ISO 30170:2012

mruby[-head]

Ruby Enterprise Edition

ree-1.8.6
ree[-1.8.7][-2012.02]

GoRuby

goruby

Topaz

topaz

MagLev

maglev[-head]
maglev-1.0.0

Mac OS X Snow Leopard Or Newer

macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

IronRuby

ironruby[-1.1.3] ironruby-head 这里我们安装2.2.2: $rvm install 2.2.2 终端运行结果:(如果直接成功请绕过homebrew的卸载安装) Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/10.11/x86_64/ruby-2.2.2.tar.bz2 Checking requirements for osx. About to install Homebrew, press Enter for default installation in /usr/local, type new path if you wish custom Homebrew installation (the path needs to be writable for user)
回车:
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)”
The current contents of /usr/local are .git
Requirements installation failed with status: 1.
这里执行:

(下面是卸载Home_brew的

)

$ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

卸载home-brew
Warning: This script will remove:
/Library/Caches/Homebrew/
/usr/local/.git/
Are you sure you want to uninstall Homebrew? [y/N] y
==> Removing Homebrew installation…
==> Removing empty directories…
==> Homebrew uninstalled!
You may want to restore /usr/local’s original permissions
sudo chmod 0755 /usr/local
sudo chgrp wheel /usr/local
再执行:
$ rvm install 2.2.2

提示: Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/10.11/x86_64/ruby-2.2.2.tar.bz2 Checking requirements for osx. About to install Homebrew, press Enter for default installation in /usr/local, type new path if you wish custom Homebrew installation (the path needs to be writable for user)
按回车:
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/…
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
Password:
这里需要输入电脑密码:
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown haha /Library/Caches/Homebrew
==> Downloading and installing Homebrew…
remote: Counting objects: 501, done.
remote: Compressing objects: 100% (445/445), done.
remote: Total 501 (delta 29), reused 360 (delta 27), pack-reused 0
Receiving objects: 100% (501/501), 787.83 KiB | 169.00 KiB/s, done.
Resolving deltas: 100% (29/29), done.
From https://github.com/Homebrew/brew
* [new branch] master -> origin/master
HEAD is now at 32f7e73 download_strategy: ensure fixed commit hash length
==> Tapping homebrew/core
Cloning into ‘/usr/local/Library/Taps/homebrew/homebrew-core’…
remote: Counting objects: 3714, done.
remote: Compressing objects: 100% (3598/3598), done.
remote: Total 3714 (delta 14), reused 2112 (delta 6), pack-reused 0
Receiving objects: 100% (3714/3714), 2.88 MiB | 240.00 KiB/s, done.
Resolving deltas: 100% (14/14), done.
Checking connectivity… done.
Checking out files: 100% (3717/3717), done.
Tapped 3591 formulae (3,740 files, 9.0M)
==> Installation successful!
==> Next steps
Run brew help to get started
Further documentation: https://git.io/brew-docs
==> Homebrew has enabled anonymous aggregate user behaviour analytics
Read the analytics documentation (and how to opt-out) here:
https://git.io/brew-analytics
Installing requirements for osx.
Updating system…..
Installing required packages: autoconf, automake, libtool, pkg-config, libyaml, readline, libksba, openssl……..
Certificates in ‘/usr/local/etc/openssl/cert.pem’ are already up to date.
Requirements installation successful.
ruby-2.2.2 - #configure
ruby-2.2.2 - #download
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6854k 100 6854k 0 0 61342 0 0:01:54 0:01:54 –:–:– 132k
ruby-2.2.2 - #validate archive
ruby-2.2.2 - #extract
ruby-2.2.2 - #validate binary
ruby-2.2.2 - #setup
ruby-2.2.2 - #gemset created /Users/haha/.rvm/gems/ruby-2.2.2@global
ruby-2.2.2 - #importing gemset /Users/haha/.rvm/gemsets/global.gems…………………………
ruby-2.2.2 - #generating global wrappers……..
ruby-2.2.2 - #gemset created /Users/haha/.rvm/gems/ruby-2.2.2
ruby-2.2.2 - #importing gemsetfile /Users/haha/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.2.2 - #generating default wrappers……..
Updating certificates in ‘/etc/openssl/cert.pem’.
mkdir: /etc/openssl: Permission denied
mkdir -p “/etc/openssl” failed, retrying with sudo
haha password required for ‘mkdir -p /etc/openssl’:
and sudo mkdir worked
这样ruby2.2.2就安装好了
现在就可以安装cocoapods啦:
$sudo gem install cocoapods
看看这样cocoapods就安装成功了
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: fourflusher-0.3.2.gem (100%)
Successfully installed fourflusher-0.3.2
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: colored-1.2.gem (100%)
Successfully installed colored-1.2
Fetching: concurrent-ruby-1.0.2.gem (100%)
Successfully installed concurrent-ruby-1.0.2
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: activesupport-5.0.0.gem (100%)
Successfully installed activesupport-5.0.0
Fetching: claide-1.0.0.gem (100%)
Successfully installed claide-1.0.0
Fetching: xcodeproj-1.1.0.gem (100%)
Successfully installed xcodeproj-1.1.0
Fetching: molinillo-0.4.5.gem (100%)
Successfully installed molinillo-0.4.5
Fetching: cocoapods-try-1.0.0.gem (100%)
Successfully installed cocoapods-try-1.0.0
Fetching: netrc-0.7.8.gem (100%)
Successfully installed netrc-0.7.8
Fetching: cocoapods-trunk-1.0.0.gem (100%)
Successfully installed cocoapods-trunk-1.0.0
Fetching: cocoapods-stats-1.0.0.gem (100%)
Successfully installed cocoapods-stats-1.0.0
Fetching: cocoapods-search-1.0.0.gem (100%)
Successfully installed cocoapods-search-1.0.0
Fetching: cocoapods-plugins-1.0.0.gem (100%)
Successfully installed cocoapods-plugins-1.0.0
Fetching: cocoapods-downloader-1.0.1.gem (100%)
Successfully installed cocoapods-downloader-1.0.1
Fetching: cocoapods-deintegrate-1.0.0.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.0
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-1.0.1.gem (100%)
Successfully installed cocoapods-core-1.0.1
Fetching: cocoapods-1.0.1.gem (100%)
Successfully installed cocoapods-1.0.1
Parsing documentation for nap-1.1.0
Installing ri documentation for nap-1.1.0
Parsing documentation for fourflusher-0.3.2
Installing ri documentation for fourflusher-0.3.2
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for colored-1.2
Installing ri documentation for colored-1.2
Parsing documentation for concurrent-ruby-1.0.2
Installing ri documentation for concurrent-ruby-1.0.2
Parsing documentation for thread_safe-0.3.5
Installing ri documentation for thread_safe-0.3.5
Parsing documentation for tzinfo-1.2.2
Installing ri documentation for tzinfo-1.2.2
Parsing documentation for i18n-0.7.0
Installing ri documentation for i18n-0.7.0
Parsing documentation for activesupport-5.0.0
Installing ri documentation for activesupport-5.0.0
Parsing documentation for claide-1.0.0
Installing ri documentation for claide-1.0.0
Parsing documentation for xcodeproj-1.1.0
Installing ri documentation for xcodeproj-1.1.0
Parsing documentation for molinillo-0.4.5
Installing ri documentation for molinillo-0.4.5
Parsing documentation for cocoapods-try-1.0.0
Installing ri documentation for cocoapods-try-1.0.0
Parsing documentation for netrc-0.7.8
Installing ri documentation for netrc-0.7.8
Parsing documentation for cocoapods-trunk-1.0.0
Installing ri documentation for cocoapods-trunk-1.0.0
Parsing documentation for cocoapods-stats-1.0.0
Installing ri documentation for cocoapods-stats-1.0.0
Parsing documentation for cocoapods-search-1.0.0
Installing ri documentation for cocoapods-search-1.0.0
Parsing documentation for cocoapods-plugins-1.0.0
Installing ri documentation for cocoapods-plugins-1.0.0
Parsing documentation for cocoapods-downloader-1.0.1
Installing ri documentation for cocoapods-downloader-1.0.1
Parsing documentation for cocoapods-deintegrate-1.0.0
Installing ri documentation for cocoapods-deintegrate-1.0.0
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for cocoapods-core-1.0.1
Installing ri documentation for cocoapods-core-1.0.1
Parsing documentation for cocoapods-1.0.1
Installing ri documentation for cocoapods-1.0.1
Done installing documentation for nap, fourflusher, escape, colored, concurrent-ruby, thread_safe, tzinfo, i18n, activesupport, claide, xcodeproj, molinillo, cocoapods-try, netrc, cocoapods-trunk, cocoapods-stats, cocoapods-search, cocoapods-plugins, cocoapods-downloader, cocoapods-deintegrate, fuzzy_match, cocoapods-core, cocoapods after 146 seconds
23 gems installed

5.现在建一个工程,叫CocoaPodsDemo

6.CocoaPods的工作原理是利用Podfile文件来下载我们指定的类库,每个工程只需要一个Podfile文件,但Podfile文件需要我们利用终端自行创建

7.在终端中使用cd命令进入工程所在目录,例如:
$ cd /Users/lanouhn/Desktop/Shared/CocoaPods

8.当前目录下,利用vim创建Podfile,在终端中输入:
$ vim Podfile

9.按【i】或【a】进入插入模式,输入以下内容:
原因是podfile升级到最新版本,pod里的内容必须明确指出所用第三方库的target;可以修改Podfile文件的配置文件,让它兼容不指定固定版本;且又不报错;

platform :ios, ‘7.0’
target ‘CocoaPodsDemo’ do
pod ‘AFNetworking’, ‘~> 2.4.1’
end

其中CocoaPodsDemo要换成当前target名,最后不要忘记增加一个end结尾,

(这两行内容是在AFNetworking的github页面找到的。
这两句文字的意思是,当前AFNetworking支持的iOS最高版本是iOS 7.0, 要下载的AFNetworking版本是2.0)

输入完毕后,按【ESC】返回命令行模式
按【:】(冒号)进入末行模式,输入【wq】保存命令并退出vim

10.这时你会发现工程目录中,出现一个名为Podfile的文件,而且文件内容就是刚刚输入的内容。
(注意,Podfile文件应该和工程文件.xcodeproj在同一个目录下)

此时就可以利用CocoPods下载AFNetworking类库了,还是在终端中的当前工程目录下,运行以下命令:
$ pod install
(个人猜测,执行该命令后,CocoPods自动会找到该目录下的Podfile文件,下载文件内容对应的第三方类库)
[ps.最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动
原因在于当执行以上两个命令的时候会升级CocoaPods的spec仓库,加一个参数可以省略这一步,然后速度就会提升不少。

加参数的命令如下:
pod install –verbose –no-repo-update
pod update –verbose –no-repo-update
或者 pod update 以及 pod install 也可以

11.执行完毕后,终端会出现以下信息:
EricmatoMacBook-Pro:CocoaPodsDemo ericwang$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (2.0.2)
Generating Pods project
Integrating client project

[!] From now on use CocoaPodsDemo.xcworkspace.

(注意最后一句话,意思是:以后打开工程就用 CocoaPodsDemo.xcworkspace 打开,而不是之前的.xcodeproj文件)

12.此时工程目录会多一个.xcworkspace文件,一个“Podfile.lock”文件和一个文件夹“Pods”

13.点击 .xcworkspace 打开工程,你会发现,AFNetwoking已经成功导入项目了

现在,你就可以开始使用AFNetworking.h了。
可以稍微测试一下,在你的项目任意代码文件中输入(貌似不提示):

import

import “AFNetworking.h”

然后编译,看看是否出错
*/
/*
提示我们从现在起,我们需要使用CocoaPodsTest.xcworkspace文件来开发。

对于工程发生的变化,有几点需要说明:

第三方库会被编译成静态库供我们真正的工程使用

CocoaPods会将所有的第三方库以target的方式组成一个名为Pods的工程,该工程就放在刚才新生成的Pods目录下。整个第三方库工程会生成一个名称为libPods.a的静态库提供给我们自己的CocoaPodsTest工程使用。

我们的工程和第三方库所在的工程会由一个新生成的workspace管理

为了方便我们直观的管理工程和第三方库,CocoaPodsTest工程和Pods工程会被以workspace的形式组织和管理,也就是我们刚才看到的CocoaPodsTest.xcworkspace文件。

原来的工程设置已经被更改了,这时候我们直接打开原来的工程文件去编译就会报错,只能使用新生成的workspace来进行项目管理。\

pod –verson 查找当前版本
这是系统重装之后今天安装的方法,安装不到一个小时就搞好了,上一次安装都被坑了,
坑人的格式,有一些显示的和我写的不一样.太恶心了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值