背景:
升级系统后不能正常执行pod install操作,提示如下:
/Library/Ruby/Site/2.3.0/rubygems/version.rb:209:in `initialize': Malformed version number string (ArgumentError)
from /Library/Ruby/Site/2.3.0/rubygems/version.rb:200:in `new'
from /Library/Ruby/Site/2.3.0/rubygems/version.rb:200:in `new'
from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/command.rb:118:in `git_version'
from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/command.rb:128:in `verify_minimum_git_version!'
from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/command.rb:49:in `run'
from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/bin/pod:55:in `<top (required)>'
from /usr/local/bin/pod:23:in `load'
from /usr/local/bin/pod:23:in `<main>'
网上搜索了一下,解决方法是升级ruby和cocoapods,于是开始了后面的骚操作
首先明确几个基本概念
1 什么是HomeBrew
Homebrew,是Mac OS X上的软件包管理工具,我们能够通过终端方便的使用它来安装管理苹果没有自带的Unix相关工具软件,被誉为OS X不可或缺的套件管理器。
1.1 常用命令
# 查找软件包
brew search git
# 安装软件包
brew install git
# 列举通过Homebrew安装的程序
brew list
# 卸载软件包
brew uninstall git
# 查看软件包信息
brew info git
# 更新HomeBrew
brew update
# 列出过时的软件包(已安装但不是最新版本)
brew outdated
# 更新过时的软件包(全部或指定)
brew upgrade 或 brew upgrade wget
# 下面我们通过brew来安装一个小工具:
brew install tree
#安装成功之后,CD 到一个目录,执行
tree -l
2 什么是gem
Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.org/ )源来查找、安装、升级和卸载软件包,非常的便捷。
2.1 常用命令
$ gem --version (查看gem版本)
$ gem update --system(更新gem)
$ gem sources(查看数据源)
$ gem sources --remove https://rubygems.org/(删除数据源)
$ gem sources -a https://ruby.taobao.org/(添加数据源)
$ gem search 软件包关键字(搜索软件包)
$ gem install 软件包名称(安装软件包)
$ gem install cocoapods --pre(安装上一个版本软件包)
$ gem uninstall 软件包名称(卸载安装包)
$ gem list (查看本地安装的包)
3 什么是rvm
RVM 是一个命令行工具,可以提供一个便捷的多版本 Ruby 环境的管理和切换。
brew和gem不同,brew用于操作系统层面上软件包的安装,而gem只是管理ruby软件。
下面开始实操
确定gem的版本
gem update --system # 这里请翻墙一下
gem -v
使用ruby-china的镜像源来更换 https://gems.ruby-china.com/
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
gem sources -l # 确保只有 gems.ruby-china.com
安装rvm:
curl -sSL [https://get.rvm.io](https://get.rvm.io/) | bash -s stable
执行的时候可能会提示错误:
Downloading https://github.com/rvm/rvm/archive/1.29.8.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.8/1.29.8.tar.gz.asc
gpg: 签名建立于 三 5/ 8 22:14:49 2019 CST
gpg: 使用 RSA 密钥 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: 无法检查签名:No public key
GPG signature verification failed for '/Users/biyao/.rvm/archives/rvm-1.29.8.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.8/1.29.8.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
command curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -
In case of further problems with validation please refer to https://rvm.io/rvm/security
根据提示,执行
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
然后:
gpg: key 105BD0E739499BDB: 6 signatures not checked due to missing keys
gpg: /Users/biyao/.gnupg/trustdb.gpg:建立了信任度数据库
gpg: 密钥 105BD0E739499BDB:公钥“Piotr Kuczynski <piotr.kuczynski@gmail.com>”已导入
gpg: key 3804BB82D39DC0E3: 105 signatures not checked due to missing keys
gpg: 密钥 3804BB82D39DC0E3:公钥“Michal Papis (RVM signing) <mpapis@gmail.com>”已导入
gpg: 没有找到任何绝对信任的密钥
gpg: 合计被处理的数量:2
gpg: 已导入:2
再次执行
\curl -sSL https://get.rvm.io | bash -s stable
得到返回结果
Downloading https://github.com/rvm/rvm/archive/1.29.8.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.8/1.29.8.tar.gz.asc
gpg: 签名建立于 三 5/ 8 22:14:49 2019 CST
gpg: 使用 RSA 密钥 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: 完好的签名,来自于“Piotr Kuczynski <piotr.kuczynski@gmail.com>” [未知]
gpg: 警告:这把密钥未经受信任的签名认证!
gpg: 没有证据表明这个签名属于它所声称的持有者。
主钥指纹: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB
GPG verified '/Users/biyao/.rvm/archives/rvm-1.29.8.tgz'
Installing RVM to /Users/biyao/.rvm/
Adding rvm PATH line to /Users/biyao/.profile /Users/biyao/.mkshrc /Users/biyao/.bashrc /Users/biyao/.zshrc.
Adding rvm loading line to /Users/biyao/.profile /Users/biyao/.bash_profile /Users/biyao/.zlogin.
Installation of RVM in /Users/biyao/.rvm/ is almost complete:
* To start using RVM you need to run `source /Users/biyao/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.
👉 Donate: https://opencollective.com/rvm/donate
成功之后,根据提示,启动rvm
source /Users/biyao/.rvm/scripts/rvm
查看rvm是否成功启动:
rvm -v
rvm 1.29.8 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
下一步是安装ruby:
# 查看已安装ruby
rvm list
# 列出ruby可安装版本信息
vm list known
# 卸载一个已安装的ruby版本
rvm remove 2.2.2
# 安装ruby
rvm install 2.6.3 # 最近版本为2.6.3
期间又提示需要升级homebrew
执行
brew update
成功升级brew后再次执行 rvm install,又掉坑里了:
Error running './configure --prefix=/Users/biyao/.rvm/rubies/ruby-2.6.3 --with-opt-dir=/usr/local/opt/libyaml:/usr/local/opt/libksba:/usr/local/opt/readline:/usr/local/opt/zlib:/usr/local/opt/openssl@1.1 --disable-install-doc --enable-shared',
please read /Users/biyao/.rvm/log/1560483388_ruby-2.6.3/configure.log
There has been an error while running configure. Halting the installation.
这里面有一句
please read /Users/biyao/.rvm/log/1560483388_ruby-2.6.3/configure.log
提示去查看log,去看了一下,里面有这么一句:
configure: error: clang version 3.0 or later is required
又去网上查了一下,发现是新的xcode没有指定命令行工具,借用网上兄弟的一个图:
重新设置,然后再次执行安装
ruby-2.6.3 - #removing src/ruby-2.6.3..
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.14/x86_64/ruby-2.6.3.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/biyao/.rvm/rubies/ruby-2.6.3, this may take a while depending on your cpu(s)...
ruby-2.6.3 - #downloading ruby-2.6.3, this may take a while depending on your connection...
ruby-2.6.3 - #extracting ruby-2.6.3 to /Users/biyao/.rvm/src/ruby-2.6.3.....
ruby-2.6.3 - #configuring.......................................................................
ruby-2.6.3 - #post-configuration.
ruby-2.6.3 - #compiling.....................................................................
ruby-2.6.3 - #installing...........
ruby-2.6.3 - #making binaries executable..
ruby-2.6.3 - #downloading rubygems-3.0.4
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 862k 100 862k 0 0 17724 0 0:00:49 0:00:49 --:--:-- 72436
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.6.3 - #extracting rubygems-3.0.4.....
ruby-2.6.3 - #removing old rubygems........
ruby-2.6.3 - #installing rubygems-3.0.4.........................................
ruby-2.6.3 - #gemset created /Users/biyao/.rvm/gems/ruby-2.6.3@global
ruby-2.6.3 - #importing gemset /Users/biyao/.rvm/gemsets/global.gems........................................................-
ruby-2.6.3 - #generating global wrappers.......
ruby-2.6.3 - #gemset created /Users/biyao/.rvm/gems/ruby-2.6.3
ruby-2.6.3 - #importing gemsetfile /Users/biyao/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.6.3 - #generating default wrappers.......
ruby-2.6.3 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.6.3 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
看到 Install of ruby-2.6.3 - #complete 说明成功安装了
接下来是安装cocoapods
gem install cocoapods
至此,坑全部踩完~然后就可以执行pod install 快乐的玩耍了~