Mac 系统出现两个ruby 怎么安装cocaopods 记录

至于为什么要安装ruby不知道你们有没有弄清楚,这位好友写得很清晰:
参考网址:https://www.jianshu.com/p/709896b204e1

因为cocaopods 需要用gem 来安装,gem 是ruby 语言开发出来的,所以需要先安装ruby,rvm 或者rben都是用来管理ruby版本的,所以按照这样的倒序来安装就好了(MAC 一般有自带的ruby版本)

系统的ruby版本是2.6.0 之前安装过pods, 使用pods 命令 发现报错了,看样子是ruby的错误,所以我想重新安装一个, 总觉得用一个常用的管理库来管理会好一点,rbenv 用来管理多个版本的 ruby 在用户目录的安装和使用 , 所以我安装了rbenv ,再安装了ruby

安装 rbenv 参考网址:https://ruby-china.org/wiki/rbenv-guide

在 osx 上可以直接用 homebrew 安装, 下面是手动安装过程. (不用 zsh 的童鞋注意替换成自己的 shell 配置文件)

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
# 用来编译安装 ruby
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# 用来管理 gemset, 可选, 因为有 bundler 也没什么必要
git clone git://github.com/jamis/rbenv-gemset.git  ~/.rbenv/plugins/rbenv-gemset
# 通过 rbenv update 命令来更新 rbenv 以及所有插件, 推荐
git clone git://github.com/rkh/rbenv-update.git ~/.rbenv/plugins/rbenv-update
# 使用 Ruby China 的镜像安装 Ruby, 国内用户推荐
git clone git://github.com/AndorChen/rbenv-china-mirror.git ~/.rbenv/plugins/rbenv-china-mirror

安装 ruby

rbenv install --list # 列出所有 ruby 版本
rbenv install 1.9.3-p392 # 安装 1.9.3-p392
rbenv install jruby-1.7.3 # 安装 jruby-1.7.3

我安装的是3.0.0,不记得具体命令了,安装后好,终端显示需要配置环境变量

Screen Shot 2021-05-30 at 2.50.39 PM.png

这个就是在说需要弄环境变量,因为不太懂咋操作没及时弄
如果不设置环境变量,接下来的输入的ruby 版本还是旧版本2.6.0 ,查看了$ gem list ,里面的ruby 已经是3.0.0了,但是终端 使用的ruby 还是2.6.0 ,企图删掉系统ruby 2.6.0版本,但是大家都说不能删掉系统的,怕出现其他错误,所以还是放回原位了
后面设置了变量也可能移动了系统ruby 文件,所以终端输入 ruby 这时候的版本是3.0.0了,此时输入pod 还是会报ruby 2.6.0 的错误 , 总是会报错

       sh-3.2# pod -v
    Traceback (most recent call last):
    20: from /usr/local/bin/pod:23:in `
' 19: from /Library/Ruby/Site/2.6.0/rubygems.rb:297:in `activate_bin_path' 18: from /Library/Ruby/Site/2.6.0/rubygems.rb:297:in `synchronize' 17: from /Library/Ruby/Site/2.6.0/rubygems.rb:298:in `block in activate_bin_path' 16: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1371:in `activate' 15: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `activate_dependencies' 14: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `each' 13: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1403:in `block in activate_dependencies' 12: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1371:in `activate' 11: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `activate_dependencies' 10: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `each' 9: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1403:in `block in activate_dependencies' 8: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1371:in `activate' 7: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `activate_dependencies' 6: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `each' 5: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1403:in `block in activate_dependencies' 4: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1371:in `activate' 3: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `activate_dependencies' 2: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1389:in `each' 1: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1400:in `block in activate_dependencies' /Library/Ruby/Site/2.6.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'ffi' (>= 1.3.0) among 155 total gem(s) (Gem::MissingSpecError) Checked in 'GEM_PATH=/var/root/.gem/ruby/2.6.0:/Library/Ruby/Gems/2.6.0:/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0', execute `gem env` for more information

所以干脆舍弃这个pod,用新的ruby 3.0.0安装cocoapods,所以需要卸载掉当前的pod

================= 载掉当前的pod ==================
先寻找到当前的pod ,终端输入命令

$ which pod

然后一般出现这个目录 /usr/local/bin/pod
搜索或者go to folder 找到这个目录, 可以把名字改掉 (个人觉得这个应该是很low的方式,但有效

期间想过使用这个,但是告诉我没安装,应该还是路径问题吧
sh-3.2# sudo gem uninstall cocoapods
Gem 'cocoapods' is not installed
================== 载掉当前的pod =================

这个时候终端输入 pod 会说找不到该命令了,所以需要开始使用ruby 3.0.0安装cocoapods

  sh-3.2# sudo gem install cocoapods

   如果出现 sudo 命令不允许访问,密码可能没有正确,再者 之前如果没有设置过sudo su ,可以尝试着直接按enter键,表示没有密码 ,然后自己可以设置一个新密码,我这边自己设置了新密码,最好是和登录密码一样,统一方便记忆
$ sudo su
Password:
sh-3.2# passwd
Changing password for root.
New password:
Retype new password:

################################### WARNING ###################################
# This tool does not update the login keychain password.                      #
# To update it, run `security set-keychain-password` as the user in question, #
# or as root providing a path to such user's login keychain.                  #
###############################################################################
sh-3.2# exit;
exit
zzzzMac:~zzzz$ exit
logout
There are stopped jobs.

如果安装pods后还是会出现pod 的工程文件没有出现,有可能pod就没有安装好,需要重新安装
比如我的这个:

$ pod repo update --verbose
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local
because checking is only perfomed in repo update

Updating spec repo `edu-git-cocoapods-specs`
  $ /usr/bin/git -C /Users/zhengyi/.cocoapods/repos/edu-git-cocoapods-specs
  fetch origin --progress
  $ /usr/bin/git -C /Users/zhengyi/.cocoapods/repos/edu-git-cocoapods-specs
  rev-parse --abbrev-ref HEAD
  fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git  [...] -- [...]'
  HEAD
  [!] CocoaPods was not able to update the `edu-git-cocoapods-specs` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`

/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:178:in `rescue in update_git_repo'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:169:in `update_git_repo'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-core-1.10.1/lib/cocoapods-core/source.rb:347:in `update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:135:in `block (3 levels) in update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/user_interface.rb:64:in `section'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:134:in `block (2 levels) in update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:133:in `each'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:133:in `block in update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:131:in `open'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/sources_manager.rb:131:in `update'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/command/repo/update.rb:23:in `run'
/usr/local/lib/ruby/gems/3.0.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/lib/cocoapods/command.rb:52:in `run'
/usr/local/lib/ruby/gems/3.0.0/gems/cocoapods-1.10.1/bin/pod:55:in `'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `
'

这里面提到了这个 :edu-git-cocoapods-specs
这是因为我的pod的源实在太多了,而且安装也没有正确,edu-git-cocoapods-specs这个是清华大学开源镜像站的库 ,需要先清理,再重新下载,因为主工程是和其他人共有的使用的,所以需要统一一下,
清华大学开源软件镜像站: https://mirror.tuna.tsinghua.edu.cn/help/CocoaPods/ (不需要翻墙)
国外代码源:https://github.com/CocoaPods/Specs.git (需要翻墙访问)
这个是看自己的需求
查看自己的源

 $ cd ~/.cocoapods/repos 
$ pod repo

edu-git-cocoapods-specs
- Type: git (unknown)
- URL:  https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
- Path: /Users/zhengyi/.cocoapods/repos/edu-git-cocoapods-specs

  master
- Type: git (remotes/origin/master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/zhengyi/.cocoapods/repos/master

trunk
- Type: CDN
- URL:  https://cdn.cocoapods.org/
- Path: /Users/zhengyi/.cocoapods/repos/trunk

3 repos

有3个,先删掉了 edu-git-cocoapods-specs 这个

$  pod repo remove edu-git-cocoapods-specs
Removing spec repo `edu-git-cocoapods-specs`


$ pod repo

  master
- Type: git (remotes/origin/master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/zhengyi/.cocoapods/repos/master

trunk
- Type: CDN
- URL:  https://cdn.cocoapods.org/
- Path: /Users/zhengyi/.cocoapods/repos/trunk

2 repos

还剩2个

因为希望安装的是 edu-git-cocoapods-specs,主要是master的路径不是清华大学的开源镜像所以删掉 master

 $  pod repo remove master
 Removing spec repo `master`

安装 从清华大学开源镜像下载下来的pod 设置为master

$  git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
Cloning into 'master'...
remote: Counting objects: 4911133, done.
remote: Compressing objects: 100% (1415138/1415138), done.
remote: Total 4911133 (delta 3250248), reused 4898061 (delta 3239554)
Receiving objects: 100% (4911133/4911133), 725.59 MiB | 4.25 MiB/s, done.
Resolving deltas: 100% (3250248/3250248), done.
Updating files: 100% (497010/497010), done.
warning: the following paths have collided (e.g. case-sensitive paths
on a case-insensitive filesystem) and only one from the same
colliding group is in the working tree:

'Specs/5/1/1/Governor/1.0.11-APPS-1582-beta11/Governor.podspec.json'
'Specs/5/1/1/Governor/1.0.11-apps-1582-beta11/Governor.podspec.json'

可以看到master 的URL 和之前的master的URL 不一样,后面pod 正常使用

$ pod repo list

 master
 - Type: git (remotes/origin/master)
 - URL:  https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
 - Path: /Users/zhengyi/.cocoapods/repos/master

  trunk
- Type: CDN
- URL:  https://cdn.cocoapods.org/
- Path: /Users/zhengyi/.cocoapods/repos/trunk

你可能感兴趣的:(Mac 系统出现两个ruby 怎么安装cocaopods 记录)