2016最新的CocoPods安装

A.打开终端

 $ ruby -v  #查看ruby的版本

打印代码:

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

B. 更换ruby镜像:

终端输入如下命令(把Ruby镜像指向taobao,避免被墙,你懂得)

a.移除现有 Ruby 默认源输入以下指令

$gem sources --remove https://rubygems.org/ 

C.使用新的源输入以下指令 :

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

#淘宝源已经停更了目前最新的是
$gem source -a https://gems.ruby-china.org

这里附上官网地址 --> RubyGems 镜像- Ruby China

D.验证新源是否替换成功输入以下指令:

$gem sources -l  #检查源镜像的

E.安装cocoapods

$sudo gem install cocoa pods

这就遇到我的第一个问题:

如果你的ruby 版本过低 就会报错:

ERROR:  Error installing cocoa:
    activesupport requires Ruby version >= 2.2.2.
ERROR:  Error installing pods:
    activesupport requires Ruby version >= 2.2.2.  

前几天,我就搞到这个地方,尝试了好几种方法更新ruby 但是都没有成功,今天偶然看到一个文章,你们可以看一下 作者:有种淡淡的忧伤 -->安装CocoaPods过程和遇到各种坑

解决方案:

1. 安装 RVM baby 版本管理器

$curl -L get.rvm.io | bash -s stable

打印代码:

In case of problems: https://rvm.io/help and https://twitter.com/rvm_io

如上显示说明安装成功

2. 执行文件

$ source ~/.bashrc  
$ source ~/.bash_profile  
$ rvm -v  

打印代码:

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

3. 用RVM升级Ruby查看当前ruby版本

$ ruby -v 
$ 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[.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

4. 安装ruby 2.2.2 版本

$rvm install 2.2.2

如果打印:

    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/abc/.rvm/gems/ruby-2.2.2@global
    ruby-2.2.2 - #importing gemset/Users/abc/.rvm/gemsets/global.gems..............................
    ruby-2.2.2 - #generating global wrappers........
    ruby-2.2.2 - #gemset created /Users/abc/.rvm/gems/ruby-2.2.2
    ruby-2.2.2 - #importing gemsetfile /Users/abc/.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
    LiuWenqiang password required for 'mkdir -p /etc/openssl': 
    and sudo mkdir worked    

则说明安装成功了

打印代码:

Done with Command Line Tools (OS X 10.11) for Xcode
Done.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> Installing the Command Line Tools (expect a GUI popup):
==> /usr/bin/sudo /usr/bin/xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Failed during: /usr/bin/sudo /usr/bin/xcode-select --install
Requirements installation failed with status: 1.

如果安装失败

如果提示以下报错或警告:

解决方法:

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

注意,不一定是报这个错,但是提示会告诉你解决方法,一般是缺少啥,然后提示你用哪个命令安装

第二个问题:

解决方案:


$ sudo xcode-select --switch /Library/Developer/CommandLineTools/

Password: (输入电脑权限密码)

$ git

usage: git [--version] [--help] [-C ] [-c name=value]

[--exec-path[=]] [--html-path] [--man-path] [--info-path]

[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]

[--git-dir=] [--work-tree=] [--namespace=]

 []

第二个问题就解决了

然后再重新执行:安装2.2.2版本 步骤 就可以解决

1. 查看当前ruby 版本

$ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]

现在ruby版本已经是2.2.2了

第一个问题就解决了

2. 继续安装 CocoaPods

$sudo gem install cocoa pods
$sudo gem install -n /usr/local/bin cocoapods
$pod setup

3. 更新 gem

$sudo gem update --system

4. 新建一个项目,名字PodTest

5. 跳转到项目路径 $ cd 项目路径 (中间有空格)

cd /Users/lucky/Desktop/PodTest   

6. 建立Podfile(配置文件)

$vim Podfile

键盘输入 i 进入编辑模式,输入 不知道的可以自行百度鸟哥的私房菜.
简单使用可以查看 VIM编辑器的使用

platform :ios, '8.0'

use_frameworks! #//通过指定use_frameworks!要求生成的是framework而不是静态库
inhibit_all_warnings! #//在全局指定不显示所有所引用的库中的警告信息

#这个不清楚的自己上GitHub上面看吧
target 'TestDemo' do

pod 'AFNetworking', '~> 3.0.4'
pod 'YYKit'
pod 'FMDB'
pod 'Masonry'

end

补充:

回车后反馈如下:

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 bin Cellar CODEOFCONDUCT.md CONTRIBUTING.md etc include lib Library LICENSE.txt opt README.md share SUPPORTERS.md .git .gitignore

提示的信息表示,已经安装好了,如果你想要删掉 就键入如下代码巴拉巴拉“`

并且我再次键入

$rvm install ruby-2.0.0-p643 

依旧报错

ERROR: '/usr/local/bin' is not writable - it is required for Homebrew, try 'brew doctor' to fix it!
Requirements installation failed with status: 1.

得了,好好仔细看看报错内容吧 not writable 不可写入, 是不是安装不上啊 然后百度到一条老外也出一样的错误 他是这么解决的
终端命令:

 $ rvm autolibs read-only # read more here:https://rvm.io/rvm/autolibs
 $ rvm install ruby

尼玛,然后终端就疯狂的开始下载了

Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.10/x86_64/ruby-2.2.1.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Skipping update of certificates in '/usr/local/etc/openssl/cert.pem', to force update run:
    rvm osx-ssl-certs update /usr/local/etc/openssl/cert.pem

Requirements installation successful.
Installing Ruby from source to: /Users/Aotu/.rvm/rubies/ruby-2.2.1, this may take a while depending on your cpu(s)...
ruby-2.2.1 - #downloading ruby-2.2.1, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12.7M  100 12.7M    0     0   242k      0  0:00:53  0:00:53 --:--:--  230k
ruby-2.2.1 - #extracting ruby-2.2.1 to /Users/Aotu/.rvm/src/ruby-2.2.1....
ruby-2.2.1 - #applying patch /Users/Aotu/.rvm/patches/ruby/2.2.1/fix_installing_bundled_gems.patch.
ruby-2.2.1 - #configuring..........................................................
ruby-2.2.1 - #post-configuration.
ruby-2.2.1 - #compiling............................................................................................|
ruby-2.2.1 - #installing..........
ruby-2.2.1 - #making binaries executable..
ruby-2.2.1 - #downloading rubygems-2.4.8
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   154  100   154    0     0     46      0  0:00:03  0:00:03 --:--:--   129
100  437k  100  437k    0     0  74299      0  0:00:06  0:00:06 --:--:--  198k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.2.1 - #extracting rubygems-2.4.8....
ruby-2.2.1 - #removing old rubygems.........
ruby-2.2.1 - #installing rubygems-2.4.8......................
ruby-2.2.1 - #gemset created /Users/Aotu/.rvm/gems/ruby-2.2.1@global
ruby-2.2.1 - #importing gemset /Users/Aotu/.rvm/gemsets/global.gems................................................
ruby-2.2.1 - #generating global wrappers........
ruby-2.2.1 - #gemset created /Users/Aotu/.rvm/gems/ruby-2.2.1
ruby-2.2.1 - #importing gemsetfile /Users/Aotu/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.2.1 - #generating default wrappers........
ruby-2.2.1 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.2.1 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

到此,ruby就安装好了 而且我们注意看到 ruby 的安装版本并不是2.0.0 ,而是2.2.1

事情并没有这么就结束,我回头再看报错的提示信息

ERROR: '/usr/local/bin' is not writable - it is required for Homebrew, try 'brew doctor' to fix it!
Requirements installation failed with status: 1.

当然 首先把安装好的2.2.1删掉 防止有哪些影响

rvm remove 2.2.1

ruby-2.2.1 - #removing src/ruby-2.2.1..
ruby-2.2.1 - #removing rubies/ruby-2.2.1..
ruby-2.2.1 - #removing gems....
ruby-2.2.1 - #removing aliases
ruby-2.2.1 - #removing wrappers....
ruby-2.2.1 - #removing environments....

这里有个 brew doctor
嗯,键入终端看看冒出啥鬼玩意

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: /usr/local/bin isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/bin

Warning: /usr/local/Cellar isn't writable.
You should `chown` /usr/local/Cellar

Warning: /usr/local/etc isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/etc

Warning: /usr/local/include isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/include

Warning: /usr/local/lib isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/lib

Warning: /usr/local/lib/pkgconfig isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/lib/pkgconfig

Warning: /usr/local/opt isn't writable.
You should `chown` /usr/local/opt

Warning: /usr/local/share isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/share

Warning: Some directories in /usr/local/share/man aren't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a brew tries to add locale information to one of these
directories, then the install will fail during the link step.
You should probably `chown` them:

    /usr/local/share/man
    /usr/local/share/man/man1

Warning: Your Homebrew is outdated.
You haven't updated for at least 24 hours. This is a long time in brewland!
To update Homebrew, run `brew update`.

在这一坨警告文档里 第一个就看到了我们的错误详解

Warning: /usr/local/bin isn’t writable.

This can happen if you “sudo make install” software that isn’t managed by 
by Homebrew. If a formula tries to write a file to this directory, the 
install will fail during the link step.

总之就是告诉你 问题还是出在 Homebrew 上面,
然而问题还是存在

总结:

  1. 遇到这个报错 ,试试先安装下 Homebrew 试试看,
    如果已经安装过了,可以卸载一下重新安装,

  2. 如果 rvm install 2.0.0 没有用,
    可以用这段命令代替,好像可以自动安装最新版本的ruby

 $ rvm autolibs read-only # read more here:https://rvm.io/rvm/autolibs
 $ rvm install ruby

问题暂时先记录在这里,留以后再来翻阅
这是收集整理网上资料的文字,如有不妥,可以直接联系我撤掉.我的邮箱 [email protected].

你可能感兴趣的:(2016最新的CocoPods安装)