问题
在版本开发过程中,可能需要多个版本的 cocoaPods
Cocoapods 的安装
//移除指定版本
sudo gem uninstall cocoapods -v 1.3.1
//安装指定版本
OS X 10.11之前系统的安装 CocoaPods 指令: $ sudo gem install cocoapods -v 1.5.3
OS X 10.11以后系统的安装 CocoaPods 指令: $ sudo gem install -n /usr/local/bin cocoapods -v 1.5.3
CocoaPods 其实并不是覆盖安装,除非你显式的删除
安装成功:
➜ ~ pod --version
1.5.3
➜ ~ pod _1.3.1_ --version
1.3.1
➜ Example git:(master) ✗ gem list cocoapods
*** LOCAL GEMS ***
cocoapods (1.5.3, 1.3.1)
cocoapods-core (1.5.3, 1.3.1)
cocoapods-deintegrate (1.0.2)
cocoapods-downloader (1.2.2, 1.2.1)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.3.1, 1.3.0)
cocoapods-try (1.1.0)
安装后可以通过以下命令指定 CocoaPods 的版本:
//执行默认版本 pod --verison 的版本
pod install
//切换至指定版本
pod _1.3.1_ install
修改 CocoaPods 默认版本
如上,CocoaPods 的默认版本是最新的 1.5.3,如果需要将默认的 CocoaPods 改为 1.3.1。执行:
➜ ~ which pod
/Users/xuyang/.rvm/rubies/ruby-2.4.0/bin/pod
➜ ~ subl /Users/xuyang/.rvm/rubies/ruby-2.4.0/bin/pod
备注:这里subl 找不到的话,需要执行:
//For Sublime Text 3
sudo rm /usr/local/bin/subl
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
//For Sublime Text 2
sudo rm /usr/local/bin/subl
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
参考stackoverflow
修改前:
require 'rubygems'
version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
end
if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('cocoapods', 'pod', version)
else
gem "cocoapods", version
load Gem.bin_path("cocoapods", "pod", version)
end
修改后
require 'rubygems'
version = "1.3.1"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
end
if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('cocoapods', 'pod', version)
else
gem "cocoapods", version
load Gem.bin_path("cocoapods", "pod", version)
end
只需修改 version即可
参考链接:
【iOS工具】rvm、Ruby环境和CocoaPods安装使用及相关报错问题解决
如何在本地安装多个版本的 CocoaPods
CocoaPod指定版本安装删除
网友评论