1.不管怎么搞运行gem 和ruby安装或更新都会报一些错,比如:

ERROR:  Could not find a valid gem 'cocoapods' (>= 0) in any repository

Error loading RubyGems plugin "/Users/jack/.rvm/rubies/ruby-2.4.2/lib/ruby/gems/2.4.0/gems/executable-hooks-1.3.2/lib/rubygems_plugin.rb": cannot load such file -- executable-hooks/wrapper (LoadError)

Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

解决

a.直接删除本机所有的ruby环境,运行ruby -v命令,如果有回显,用which ruby找到目录,直接删除,把用户和系统关于ruby的环境变量变量全删了,.bash_profile和系统的 直接搜索ruby 和rvm有的全删掉或者注释掉。

b.按顺序运行如下命令

brew install ruby
brew link --overwrite ruby

c.然后看看ruby的源能不能访问,如果你使用gem install出现如下错,就要查看一下源了

ERROR:  Could not find a valid gem 'cocoapods' (>= 0) in any repository

查看当前源的命令,https://rubygems.org 是默认源:

✘ ⚙ jack@mimi  ~  gem source
*** CURRENT SOURCES ***

https://rubygems.org

可以用命令设置源,默认的源可能需要FAN墙:

gem sources -a https://rubygems.org

还可以设置淘宝的源:

gem sources -a http://ruby.taobao.org/

到这里应该就差不多了,然后运行gem install安装你要的软件吧