根据提示终端命令行输入:
gem install cocoapods --pre
正常来说有的人 可能这样就直接好了 ,但是我的报错:
/Users/Alan/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/config_file.rb:348:in `load_file': uninitialized constant Gem::SafeYAML (NameError)
from /Users/Alan/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/config_file.rb:203:in `initialize'
from /Users/Alan/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/gem_runner.rb:75:in `new'
from /Users/Alan/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/gem_runner.rb:75:in `do_configuration'
from /Users/Alan/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/gem_runner.rb:40:in `run'
from /Users/Alan/.rvm/rubies/ruby-2.2.2/bin/gem:21:in `<main>'
//解决办法
1、删除 删除 RVM
rm -rf ~/.rvm
2、安装 RVM
curl -L https://get.rvm.io | bash -s stable
$ rvm -v
RVM version 1.29.4 (latest) is installed yet 1.29.3 (latest) is loaded.
Please do one of the following:
* 'rvm reload'
* open a new shell
* 'echo rvm_auto_reload_flag=1 >> ~/.rvmrc' # for auto reload with msg.
* 'echo rvm_auto_reload_flag=2 >> ~/.rvmrc' # for silent auto reload.
$ rvm reload
Warning! PATH is not properly set up, '/Users/Alan/.rvm/gems/ruby-2.2.2/bin' is not at first place.
Usually this is caused by shell initialization files. Search for 'PATH=...' entries.
You can also re-add RVM to your profile by running: 'rvm get stable --auto-dotfiles'.
To fix it temporarily in this shell session run: 'rvm use ruby-2.2.2'.
To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
RVM reloaded!
3、用 RVM 安装 Ruby 环境
$ 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[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.7]
[ruby-]2.4[.4]
[ruby-]2.5[.1]
[ruby-]2.6[.0-preview2]
ruby-head
//我是安装的2.0.0
$ rvm install 2.0.0
//安装成功后查询已经安装的ruby
$ rvm list
=* ruby-2.0.0-p648 [ x86_64 ]
ruby-2.2.2 [ missing bin/ruby ]
ruby-2.4.1 [ missing bin/ruby ]
# => - current
# =* - current && default
# * - default
//发现之前安装的版本都报 [ missing bin/ruby ] 猜想有可能是这个的原因
//重新安装
$ rvm reinstall 2.4.1
//把2.4.1设置为默认
$ rvm 2.4.1 --default
4、更新 gem
$ sudo gem update --system
Password:
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)
//查看源
$ gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.org/
//发现是现在 https://gems.ruby-china.org/ 访问不了了
$ gem sources --remove https://rubygems.org/
$ gem sources --remove https://ruby.taobao.org/ //如果安装了淘宝的镜像
//等有反应之后再敲入以下命令
$ gem sources -a https://gems.ruby-china.com/
//成功后
$ gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
//执行
$ gem install cocoapods --pre
//执行成功
pod install 完美运行
**总结
可能有两个原因:
1、已经安装的ruby问题 [missing bin/ruby ]
2、Ruby的默认源 (可以先切换源试试)