文章目录

今天在学习LeanCloud时,需要获取SDK,官方推荐的方式是通过包依赖管理工具来下载最新版本。然后第一步是【包依赖管理工具安装】,于是就点进了CocoaPods安装和使用教程,在【如何下载和安装CocoaPods?】来安装和更新CocoaPods。但是发现执行

1
$ gem sources -a http://ruby.taobao.org/

这句时,终端一直没有出现huangsengolndeMacBook-Pro:Desktop huangaengoln$
说明这个源也像cocoapods.org不能访问了。于是就百度,发现有个博客网站里面说:

按照下面的顺序在终端中敲入依次敲入命令:

1
2
> $ gem sources --remove https://rubygems.org/
>

//等有反应之后再敲入以下命令:

1
2
3
4
> $ gem sources -a http://ruby.taobao.org/
> //或者
> $ gem sources -a https://ruby.taobao.org/
>

于是就尝试键入

1
$ gem sources -a https://ruby.taobao.org/

效果如下:

1
2
3
huangsengolndeMacBook-Pro:Desktop huangaengoln$ gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
huangsengolndeMacBook-Pro:Desktop huangaengoln$

说明这个源才是正确的。

接下来更新gem:

1
2
3
4
5
6
7
8
9
10
11
12
huangsengolndeMacBook-Pro:Desktop huangaengoln$ gem update --system
Updating rubygems-update
Fetching: rubygems-update-2.6.7.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
huangsengolndeMacBook-Pro:Desktop huangaengoln$ sudo gem update --system
Password:
Updating rubygems-update
Fetching: rubygems-update-2.6.7.gem (100%)
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/update_rubygems
huangsengolndeMacBook-Pro:Desktop huangaengoln$

- /usr/bin/update_rubygems操作不允许。百度下,在SegmentFault的一篇问答中看到这么一个回答:

这个问题在stackoverflow上面有过讨论:

Can not perform pod install under el capitan (15A279b)

被采纳的答案为:sudo gem install -n /usr/local/bin cocoapods

于是将信将疑地继续在终端键入:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
huangsengolndeMacBook-Pro:Desktop huangaengoln$ sudo gem install -n /usr/local/bin
ERROR: While executing gem ... (Gem::CommandLineError)
Please specify at least one gem name (e.g. gem build GEMNAME)
huangsengolndeMacBook-Pro:Desktop huangaengoln$ sudo gem install -n /usr/local/bin cocoapods
Successfully installed xcodeproj-1.4.4
Fetching: ruby-macho-1.1.0.gem (100%)
Successfully installed ruby-macho-1.1.0
Fetching: molinillo-0.5.7.gem (100%)
Successfully installed molinillo-0.5.7
Fetching: gh_inspector-1.0.3.gem (100%)
Successfully installed gh_inspector-1.0.3
Fetching: fourflusher-2.0.1.gem (100%)
Successfully installed fourflusher-2.0.1
Fetching: cocoapods-try-1.1.0.gem (100%)
Successfully installed cocoapods-try-1.1.0
Fetching: cocoapods-trunk-1.2.0.gem (100%)
Successfully installed cocoapods-trunk-1.2.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.1.3.gem (100%)
Successfully installed cocoapods-downloader-1.1.3
Fetching: cocoapods-deintegrate-1.0.1.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.1
Fetching: cocoapods-core-1.2.1.gem (100%)
Successfully installed cocoapods-core-1.2.1
Fetching: cocoapods-1.2.1.gem (100%)
Successfully installed cocoapods-1.2.1
Parsing documentation for xcodeproj-1.4.4
Installing ri documentation for xcodeproj-1.4.4
Parsing documentation for ruby-macho-1.1.0
Installing ri documentation for ruby-macho-1.1.0
Parsing documentation for molinillo-0.5.7
Installing ri documentation for molinillo-0.5.7
Parsing documentation for gh_inspector-1.0.3
Installing ri documentation for gh_inspector-1.0.3
Parsing documentation for fourflusher-2.0.1
Installing ri documentation for fourflusher-2.0.1
Parsing documentation for cocoapods-try-1.1.0
Installing ri documentation for cocoapods-try-1.1.0
Parsing documentation for cocoapods-trunk-1.2.0
Installing ri documentation for cocoapods-trunk-1.2.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.1.3
Installing ri documentation for cocoapods-downloader-1.1.3
Parsing documentation for cocoapods-deintegrate-1.0.1
Installing ri documentation for cocoapods-deintegrate-1.0.1
Parsing documentation for cocoapods-core-1.2.1
Installing ri documentation for cocoapods-core-1.2.1
Parsing documentation for cocoapods-1.2.1
Installing ri documentation for cocoapods-1.2.1
14 gems installed
huangsengolndeMacBook-Pro:Desktop huangaengoln$

终于到达了xx gems installed的提示了。

接着安装cocoapods:

1
2
3
4
5
huangsengolndeMacBook-Pro:Desktop huangaengoln$ sudo gem install cocoapods
Password:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
huangsengolndeMacBook-Pro:Desktop huangaengoln$

操作不允许- /usr/bin/pod。继续复制Operation not permitted - /usr/bin/pod百度。在这篇博客找到了解决方法:

1
2
3
4
5
huangsengolndeMacBook-Pro:Desktop huangaengoln$ sudo gem install -n /usr/local/bin cocoapods
Successfully installed cocoapods-1.2.1
Parsing documentation for cocoapods-1.2.1
1 gem installed
huangsengolndeMacBook-Pro:Desktop huangaengoln$

总算安装完成了。

最后测试下第三方库的管理。

查询Parse是否可以用cocoaPods管理:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
huangsengolndeMacBook-Pro:Desktop huangaengoln$ pod search Parse
-> Parse (1.14.2)
A library that gives you access to the powerful Parse cloud platform from your
iOS/OS X/watchOS/tvOS app.
pod 'Parse', '~> 1.14.2'
- Homepage: https://www.parse.com/
- Source: https://github.com/ParsePlatform/Parse-SDK-iOS-OSX.git
- Versions: 1.14.2, 1.14.1, 1.14.0, 1.13.0, 1.12.0, 1.11.0, 1.10.0, 1.9.1, 1.9.0,
1.8.5, 1.8.4, 1.8.3, 1.8.2, 1.8.1, 1.8.0, 1.7.5.3, 1.7.5.2, 1.7.5.1, 1.7.5, 1.7.4,
1.7.3, 1.7.2.2, 1.7.2.1, 1.7.2, 1.7.1, 1.7.0, 1.6.5, 1.6.4, 1.6.3, 1.6.2, 1.6.1,
1.6.0, 1.5.0, 1.4.2, 1.4.1, 1.4.0, 1.3.0.1, 1.3.0, 1.2.21, 1.2.20, 1.2.19, 1.2.18,
1.2.17, 1.2.16, 1.2.15, 1.2.13, 1.2.12, 1.2.11, 1.2.10, 1.2.9, 1.2.8, 1.2.7, 1.2.6,
1.2.5, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.33, 1.1.32, 1.1.31, 1.1.30, 1.1.29,
1.1.27, 1.1.25, 1.1.24, 1.1.23, 1.1.10, 1.0.39, 1.0.36 [master repo]
-> Parse+NSCoding (0.1.4)
iOS library for serializing Parse objects
pod 'Parse+NSCoding', '~> 0.1.4'
- Homepage: https://github.com/martinrybak/Parse-NSCoding
- Source: https://github.com/martinrybak/Parse-NSCoding.git
- Versions: 0.1.4, 0.1.3, 0.1.2, 0.1.1, 0.1.0, 0.0.2, 0.0.1 [master repo]
-> Parse+PromiseKit (0.9.2)
A PromiseKit category for the Parse SDK.
pod 'Parse+PromiseKit', '~> 0.9.2'
//... ...
:

新建podfile,并加入Parse

1
$ vim podfile
1
2
//podfile
pod 'Parse'

下载Parse库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
huangsengolndeMacBook-Pro:MyParse huangaengoln$ pod install
Analyzing dependencies
[!] The dependency `Parse (~> 1.14.2)` is not used in any concrete target.
[!] Smart quotes were detected and ignored in your Podfile. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.
huangsengolndeMacBook-Pro:MyParse huangaengoln$ sudo pod install
Password:
/Library/Ruby/Gems/2.0.0/gems/claide-1.0.1/lib/claide/command.rb:439:in `help!': [!] You cannot run CocoaPods as root. (CLAide::Help)
Usage:
$ pod COMMAND
CocoaPods, the Cocoa library package manager.
Commands:
+ cache Manipulate the CocoaPods cache
+ env Display pod environment
+ init Generate a Podfile for the current directory
+ install Install project dependencies according to versions from a
Podfile.lock
+ ipc Inter-process communication
+ lib Develop pods
+ list List pods
+ outdated Show outdated project dependencies
+ repo Manage spec-repositories
+ setup Setup the CocoaPods environment
+ spec Manage pod specs
+ update Update outdated project dependencies and create new Podfile.lock
Options:
--silent Show nothing
--version Show the version of the tool
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified command
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.1/lib/cocoapods/command.rb:47:in `run'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.1/bin/pod:55:in `<top (required)>'
from /usr/local/bin/pod:23:in `load'
from /usr/local/bin/pod:23:in `<main>'

发现红色的文字提示[!] The dependencyParse (~> 1.14.2)is not used in any concrete target.。复制该句百度,找到一篇博客的解决方法:

我的Podfile的内容如下:

1
2
3
4
> platform:ios,'7.0'
> pod 'Masonry', '~> 1.0.1'
> pod 'MJRefresh', '~> 3.1.12'
>

结果执行:pod install 后出现错误The dependency `` is not used in any concrete target

3)修复这个错误只需要修改成如下即可:

1
2
3
4
5
6
>platform:ios,'7.0'
>target "KYVedioPlayer" do
>pod 'Masonry', '~> 1.0.1'
>pod 'MJRefresh', '~> 3.1.12'
>end
>

要明确指出所用第三方库的target

这样再运行 pod install --verbose --no-repo-update,就会成功了。

然后修改podfile文件:

1
2
3
4
//podfile
target "MyParse" do
pod 'Parse’
end

再运行:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
huangsengolndeMacBook-Pro:MyParse huangaengoln$ pod install
Analyzing dependencies
Downloading dependencies
Installing Bolts (1.8.4)
Installing Parse (1.14.2)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `MyParse.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 2 total pods installed.
[!] Smart quotes were detected and ignored in your Podfile. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.
[!] Automatically assigning platform ios with version 10.2 on target MyParse because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
huangsengolndeMacBook-Pro:MyParse huangaengoln$

再看看目录,果真下载好了第三方库。


来自:Mac安装gem、cocoapods(转)

文章目录