A.打開終端
$ ruby -v #查看ruby的版本
打印代碼:
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
B. 更換ruby鏡像:
終端輸入如下命令(把Ruby鏡像指向taobao,避免被墻,你懂得)
a.移除現(xiàn)有 Ruby 默認(rèn)源輸入以下指令
$gem sources --remove https://rubygems.org/
C.使用新的源輸入以下指令 :
$gem sources -a https://ruby.taobao.org/
#淘寶源已經(jīng)停更了目前最新的是
$gem source -a https://gems.ruby-china.org
這里附上官網(wǎng)地址 --> RubyGems 鏡像- Ruby China
D.驗(yàn)證新源是否替換成功輸入以下指令:
$gem sources -l #檢查源鏡像的
E.安裝cocoapods
$sudo gem install cocoa pods
這就遇到我的第一個(gè)問題:
如果你的ruby 版本過低 就會(huì)報(bào)錯(cuò):
ERROR: Error installing cocoa:
activesupport requires Ruby version >= 2.2.2.
ERROR: Error installing pods:
activesupport requires Ruby version >= 2.2.2.
前幾天页藻,我就搞到這個(gè)地方澄干,嘗試了好幾種方法更新ruby 但是都沒有成功叛溢,今天偶然看到一個(gè)文章,你們可以看一下 作者:有種淡淡的憂傷 -->安裝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. 執(zhí)行文件
$ source ~/.bashrc
$ source ~/.bash_profile
$ rvm -v
打印代碼:
rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com>[https://rvm.io/]
3. 用RVM升級Ruby查看當(dāng)前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-<name> --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.
如果安裝失敗
如果提示以下報(bào)錯(cuò)或警告:
解決方法:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
注意,不一定是報(bào)這個(gè)錯(cuò),但是提示會(huì)告訴你解決方法轻纪,一般是缺少啥油额,然后提示你用哪個(gè)命令安裝
第二個(gè)問題:
解決方案:
$ sudo xcode-select --switch /Library/Developer/CommandLineTools/
Password: (輸入電腦權(quán)限密碼)
$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
第二個(gè)問題就解決了
然后再重新執(zhí)行:安裝2.2.2版本 步驟 就可以解決
1. 查看當(dāng)前ruby 版本
$ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
現(xiàn)在ruby版本已經(jīng)是2.2.2了
第一個(gè)問題就解決了
2. 繼續(xù)安裝 CocoaPods
$sudo gem install cocoa pods
$sudo gem install -n /usr/local/bin cocoapods
$pod setup
3. 更新 gem
$sudo gem update --system
4. 新建一個(gè)項(xiàng)目,名字PodTest
5. 跳轉(zhuǎn)到項(xiàng)目路徑 $ cd 項(xiàng)目路徑 (中間有空格)
cd /Users/lucky/Desktop/PodTest
6. 建立Podfile(配置文件)
$vim Podfile
鍵盤輸入 i 進(jìn)入編輯模式桐磁,輸入
不知道的可以自行百度鳥哥的私房菜.
簡單使用可以查看 VIM編輯器的使用
platform :ios, '8.0'
use_frameworks! #//通過指定use_frameworks!要求生成的是framework而不是靜態(tài)庫
inhibit_all_warnings! #//在全局指定不顯示所有所引用的庫中的警告信息
#這個(gè)不清楚的自己上GitHub上面看吧
target 'TestDemo' do
pod 'AFNetworking', '~> 3.0.4'
pod 'YYKit'
pod 'FMDB'
pod 'Masonry'
end
補(bǔ)充:
回車后反饋如下:
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
提示的信息表示,已經(jīng)安裝好了,如果你想要?jiǎng)h掉 就鍵入如下代碼巴拉巴拉“`
并且我再次鍵入
$rvm install ruby-2.0.0-p643
依舊報(bào)錯(cuò)
ERROR: '/usr/local/bin' is not writable - it is required for Homebrew, try 'brew doctor' to fix it!
Requirements installation failed with status: 1.
得了,好好仔細(xì)看看報(bào)錯(cuò)內(nèi)容吧 not writable 不可寫入, 是不是安裝不上啊 然后百度到一條老外也出一樣的錯(cuò)誤 他是這么解決的
終端命令:
$ 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
事情并沒有這么就結(jié)束,我回頭再看報(bào)錯(cuò)的提示信息
ERROR: '/usr/local/bin' is not writable - it is required for Homebrew, try 'brew doctor' to fix it!
Requirements installation failed with status: 1.
當(dāng)然 首先把安裝好的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....
這里有個(gè) 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`.
在這一坨警告文檔里 第一個(gè)就看到了我們的錯(cuò)誤詳解
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
上面,
然而問題還是存在
總結(jié):
遇到這個(gè)報(bào)錯(cuò) ,試試先安裝下
Homebrew
試試看,
如果已經(jīng)安裝過了,可以卸載一下重新安裝,如果
rvm install 2.0.0
沒有用,
可以用這段命令代替,好像可以自動(dòng)安裝最新版本的ruby
$ rvm autolibs read-only # read more here:https://rvm.io/rvm/autolibs
$ rvm install ruby
問題暫時(shí)先記錄在這里,留以后再來翻閱
這是收集整理網(wǎng)上資料的文字,如有不妥,可以直接聯(lián)系我撤掉.我的郵箱 281090013@qq.com.