如何在本地安装多个版本的 CocoaPods

1. CocoaPods 其实并不是覆盖安装,除非你显式的删除
gem uninstall cocoapods
2.安装你需要的cocoapods版本
sudo gem install cocoapods -v 1.5.3
sudo gem install cocoapods -v 1.7.5
3.查看本地安装的 CocoaPods 版本列表
 ~ gem list cocoapods
*** LOCAL GEMS ***

cocoapods (1.7.5, 1.5.3)
cocoapods-core (1.7.5, 1.5.3)
cocoapods-deintegrate (1.0.4, 1.0.2)
cocoapods-downloader (1.2.2)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.3.1)
cocoapods-try (1.1.0)
4.查看pod脚本文件位置
~ which pod
/usr/local/bin/pod
5.修改pod脚本
~ vim /usr/local/bin/pod
修改前:
require 'rubygems'

version = ">= 0.a"

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

load Gem.bin_path('cocoapods', 'pod', version)
修改后:
require 'rubygems'

version = ">= 0.a"

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

# 这里新增一行代码
gem 'cocoapods', version
load Gem.bin_path('cocoapods', 'pod', version)
6.使用指定cocoapods版本执行命令
pod _version_ command

~ pod _1.5.3_  --version
1.5.3

~ pod _1.7.5_  --version
1.7.5

你可能感兴趣的:(如何在本地安装多个版本的 CocoaPods)