至于為什么要安裝ruby不知道你們有沒有弄清楚楞抡,這位好友寫得很清晰:
參考網址:http://www.reibang.com/p/709896b204e1
因為cocaopods 需要用gem 來安裝召廷,gem 是ruby 語言開發(fā)出來的竞慢,所以需要先安裝ruby,rvm 或者rben都是用來管理ruby版本的遮精,所以按照這樣的倒序來安裝就好了(MAC 一般有自帶的ruby版本)
系統(tǒng)的ruby版本是2.6.0 之前安裝過pods本冲, 使用pods 命令 發(fā)現(xiàn)報錯了檬洞,看樣子是ruby的錯誤,所以我想重新安裝一個, 總覺得用一個常用的管理庫來管理會好一點添怔,rbenv 用來管理多個版本的 ruby 在用戶目錄的安裝和使用 湾戳, 所以我安裝了rbenv ,再安裝了ruby
安裝 rbenv 參考網址:https://ruby-china.org/wiki/rbenv-guide
在 osx 上可以直接用 homebrew 安裝, 下面是手動安裝過程. (不用 zsh 的童鞋注意替換成自己的 shell 配置文件)
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
# 用來編譯安裝 ruby
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# 用來管理 gemset, 可選, 因為有 bundler 也沒什么必要
git clone git://github.com/jamis/rbenv-gemset.git ~/.rbenv/plugins/rbenv-gemset
# 通過 rbenv update 命令來更新 rbenv 以及所有插件, 推薦
git clone git://github.com/rkh/rbenv-update.git ~/.rbenv/plugins/rbenv-update
# 使用 Ruby China 的鏡像安裝 Ruby, 國內用戶推薦
git clone git://github.com/AndorChen/rbenv-china-mirror.git ~/.rbenv/plugins/rbenv-china-mirror
安裝 ruby
rbenv install --list # 列出所有 ruby 版本
rbenv install 1.9.3-p392 # 安裝 1.9.3-p392
rbenv install jruby-1.7.3 # 安裝 jruby-1.7.3
我安裝的是3.0.0,不記得具體命令了,安裝后好澎灸,終端顯示需要配置環(huán)境變量
這個就是在說需要弄環(huán)境變量院塞,因為不太懂咋操作沒及時弄
如果不設置環(huán)境變量,接下來的輸入的ruby 版本還是舊版本2.6.0 性昭,查看了$ gem list 拦止,里面的ruby 已經是3.0.0了,但是終端 使用的ruby 還是2.6.0 糜颠,企圖刪掉系統(tǒng)ruby 2.6.0版本,但是大家都說不能刪掉系統(tǒng)的其兴,怕出現(xiàn)其他錯誤顶瞒,所以還是放回原位了
后面設置了變量也可能移動了系統(tǒng)ruby 文件,所以終端輸入 ruby 這時候的版本是3.0.0了元旬,此時輸入pod 還是會報ruby 2.6.0 的錯誤 , 總是會報錯
sh-3.2# pod -v
Traceback (most recent call last):
20: from /usr/local/bin/pod:23:in `<main>'
19: from /Library/Ruby/Site/2.6.0/rubygems.rb:297:in `activate_bin_path'
18: from /Library/Ruby/Site/2.6.0/rubygems.rb:297:in `synchronize'
17: from /Library/Ruby/Site/2.6.0/rubygems.rb:298:in `block in activate_bin_path'
16: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1371:in `activate'
15: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `activate_dependencies'
14: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `each'
13: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1403:in `block in activate_dependencies'
12: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1371:in `activate'
11: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `activate_dependencies'
10: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `each'
9: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1403:in `block in activate_dependencies'
8: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1371:in `activate'
7: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `activate_dependencies'
6: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `each'
5: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1403:in `block in activate_dependencies'
4: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1371:in `activate'
3: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `activate_dependencies'
2: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `each'
1: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1400:in `block in activate_dependencies'
/Library/Ruby/Site/2.6.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'ffi' (>= 1.3.0) among 155 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/var/root/.gem/ruby/2.6.0:/Library/Ruby/Gems/2.6.0:/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0', execute `gem env` for more information
所以干脆舍棄這個pod榴徐,用新的ruby 3.0.0安裝cocoapods,所以需要卸載掉當前的pod
================= 載掉當前的pod ==================
先尋找到當前的pod ,終端輸入命令
$ which pod
然后一般出現(xiàn)這個目錄 /usr/local/bin/pod
搜索或者go to folder 找到這個目錄, 可以把名字改掉 (個人覺得這個應該是很low的方式匀归,但有效
期間想過使用這個坑资,但是告訴我沒安裝,應該還是路徑問題吧
sh-3.2# sudo gem uninstall cocoapods
Gem 'cocoapods' is not installed
================== 載掉當前的pod =================
這個時候終端輸入 pod 會說找不到該命令了穆端,所以需要開始使用ruby 3.0.0安裝cocoapods
sh-3.2# sudo gem install cocoapods
如果出現(xiàn) sudo 命令不允許訪問袱贮,密碼可能沒有正確,再者 之前如果沒有設置過sudo su 体啰,可以嘗試著直接按enter鍵攒巍,表示沒有密碼 ,然后自己可以設置一個新密碼荒勇,我這邊自己設置了新密碼柒莉,最好是和登錄密碼一樣,統(tǒng)一方便記憶
$ sudo su
Password:
sh-3.2# passwd
Changing password for root.
New password:
Retype new password:
################################### WARNING ###################################
# This tool does not update the login keychain password. #
# To update it, run `security set-keychain-password` as the user in question, #
# or as root providing a path to such user's login keychain. #
###############################################################################
sh-3.2# exit;
exit
zzzzMac:~zzzz$ exit
logout
There are stopped jobs.
如果安裝pods后還是會出現(xiàn)pod 的工程文件沒有出現(xiàn)沽翔,有可能pod就沒有安裝好常柄,需要重新安裝
比如我的這個:
$ pod repo update --verbose
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local
because checking is only perfomed in repo update
Updating spec repo `edu-git-cocoapods-specs`
$ /usr/bin/git -C /Users/zhengyi/.cocoapods/repos/edu-git-cocoapods-specs
fetch origin --progress
$ /usr/bin/git -C /Users/zhengyi/.cocoapods/repos/edu-git-cocoapods-specs
rev-parse --abbrev-ref HEAD
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
HEAD
[!] CocoaPods was not able to update the `edu-git-cocoapods-specs` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:178:in `rescue in update_git_repo'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:169:in `update_git_repo'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-core-1.10.1/lib/cocoapods-core/source.rb:347:in `update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:135:in `block (3 levels) in update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/user_interface.rb:64:in `section'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:134:in `block (2 levels) in update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:133:in `each'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:133:in `block in update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:131:in `open'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:131:in `update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/command/repo/update.rb:23:in `run'
/usr/local/lib/ruby/gems/3.0.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/command.rb:52:in `run'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'
這里面提到了這個 :edu-git-cocoapods-specs
這是因為我的pod的源實在太多了,而且安裝也沒有正確搀擂,edu-git-cocoapods-specs這個是清華大學開源鏡像站的庫 西潘,需要先清理,再重新下載哨颂,因為主工程是和其他人共有的使用的喷市,所以需要統(tǒng)一一下,
清華大學開源軟件鏡像站: https://mirror.tuna.tsinghua.edu.cn/help/CocoaPods/ (不需要翻墻)
國外代碼源:https://github.com/CocoaPods/Specs.git (需要翻墻訪問)
這個是看自己的需求
查看自己的源
$ cd ~/.cocoapods/repos
$ pod repo
edu-git-cocoapods-specs
- Type: git (unknown)
- URL: https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
- Path: /Users/zhengyi/.cocoapods/repos/edu-git-cocoapods-specs
master
- Type: git (remotes/origin/master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/zhengyi/.cocoapods/repos/master
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/zhengyi/.cocoapods/repos/trunk
3 repos
有3個威恼,先刪掉了 edu-git-cocoapods-specs 這個
$ pod repo remove edu-git-cocoapods-specs
Removing spec repo `edu-git-cocoapods-specs`
$ pod repo
master
- Type: git (remotes/origin/master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/zhengyi/.cocoapods/repos/master
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/zhengyi/.cocoapods/repos/trunk
2 repos
還剩2個
因為希望安裝的是 edu-git-cocoapods-specs品姓,主要是master的路徑不是清華大學的開源鏡像所以刪掉 master
$ pod repo remove master
Removing spec repo `master`
安裝 從清華大學開源鏡像下載下來的pod 設置為master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
Cloning into 'master'...
remote: Counting objects: 4911133, done.
remote: Compressing objects: 100% (1415138/1415138), done.
remote: Total 4911133 (delta 3250248), reused 4898061 (delta 3239554)
Receiving objects: 100% (4911133/4911133), 725.59 MiB | 4.25 MiB/s, done.
Resolving deltas: 100% (3250248/3250248), done.
Updating files: 100% (497010/497010), done.
warning: the following paths have collided (e.g. case-sensitive paths
on a case-insensitive filesystem) and only one from the same
colliding group is in the working tree:
'Specs/5/1/1/Governor/1.0.11-APPS-1582-beta11/Governor.podspec.json'
'Specs/5/1/1/Governor/1.0.11-apps-1582-beta11/Governor.podspec.json'
可以看到master 的URL 和之前的master的URL 不一樣,后面pod 正常使用
$ pod repo list
master
- Type: git (remotes/origin/master)
- URL: https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
- Path: /Users/zhengyi/.cocoapods/repos/master
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/zhengyi/.cocoapods/repos/trunk