安装 cocoapods
1. 安装/更新 gem
看这个就好了 国内镜像官网 https://gems.ruby-china.com/
这里简单列下步骤
$ gem update --system #这里请翻墙一下
$ gem -v
$ gem sources -l
$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ #remove的网址应该是上一个结果打印出来的网址
2. 安装 cocoapods
$ gem install cocoapods
3. 添加 podfile 文件
输入
platform :ios, '11.0'
use_frameworks!
target '#这里填自己的项目名' do
# 这里是依赖的库
pod 'Alamofire', '~> 5.0.0-rc.3'
pod 'WCDB.swift'
end
执行 pod install
即可
常见问题及解决方案
错误 1: Permission denied
ERROR: While executing gem ... (Errno::EACCES)
Permission denied
Why 执行何命令导致:gem update --system
Solution 解决办法
$ rvm fix-permissions
$ rvm reinstall 2.5.6
错误 2:cannot load such file
kernel_require.rb:55:in `require':
Why 执行何命令导致:pod install
or pod update
solution 解决办法
- 更新 rvm 版本(非必要)
rvm get stable
- 删除多余的 ruby 版本,下面的 xxx 是版本号
• 查看 ./rvm/gems 中有几个 ruby 版本
•rvm remove xxx
,删除多余的版本
•rvm use xxx
设置 ruby 的使用版本
错误 3:GemNotFoundException
can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
why 执行何命令导致:pod install
solution 解决方案:
先卸载再安装
$ gem uninstall cocoapods
$ gem install cocoapods
详细过程记录(废话)
- 更新/安装 gem
gem update --system
过了几分钟,我这边跳出来的结果
Updating rubygems-update
Fetching: rubygems-update-3.0.6.gem (100%)
Successfully installed rubygems-update-3.0.6
Parsing documentation for rubygems-update-3.0.6
Installing ri documentation for rubygems-update-3.0.6
Installing darkfish documentation for rubygems-update-3.0.6
Done installing documentation for rubygems-update after 41 seconds
Parsing documentation for rubygems-update-3.0.6
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.0.6
ERROR: While executing gem ... (Errno::EACCES)
Permission denied @ rb_sysopen - /Users/joanfen/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/source_local.rb
加上 sudo 试了下,同样的错误
然后在 stackoverflow上找到了这个解决
$ rvm fix-permissions
$ rvm reinstall 2.5.6
当时 gem 安装成功后 pod 也更新成功了
两天后,中间电脑关过一次机,今天又抽风了
- 更新 pod 时报错
rubygems/core_ext/kernel_warn
/Users/joanfen/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- rubygems/core_ext/kernel_warn (LoadError)
from /Users/joanfen/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/joanfen/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems.rb:1390:in `<top (required)>'
from <internal:gem_prelude>:4:in `require'
from <internal:gem_prelude>:4:in `<internal:gem_prelude>'
执行了
rvm fix-permissions
# 这里的 2.5.6 是 ruby 版本号
rvm reinstall 2.5.6
发现还是不行,于是执行了
rvm info
发现没有设置过默认的 ruby 版本
system:
system:
uname: "Darwin joanfendeMacBook-Pro.local 19.0.0 Darwin Kernel Version 19.0.0: Wed Sep 25 20:18:50 PDT 2019; root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64"
system: "osx/10.15/x86_64"
bash: "/bin/bash => GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)"
zsh: "/bin/zsh => zsh 5.7.1 (x86_64-apple-darwin19.0)"
rvm:
version: "rvm 1.27.0 (latest) by Wayne E. Seguin wayneeseguin@gmail.com, Michal Papis mpapis@gmail.com [https://rvm.io/]"
updated: "3 years 2 months 18 days 22 hours 36 minutes 25 seconds ago"
path: "/Users/joanfen/.rvm"
homes:
gem: "not set"
ruby: "not set"
binaries:
ruby: "/usr/bin/ruby"
irb: "/usr/bin/irb"
gem: "/usr/bin/gem"
rake: "/usr/bin/rake"
environment:
PATH: "/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/Home/bin:/usr/local/bin/gradle-2.13/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/share/scala/bin:/usr/local/share/sbt/bin:/Users/joanfen/.rvm/bin"
GEM_HOME: ""
GEM_PATH: ""
MY_RUBY_HOME: ""
IRBRC: ""
RUBYOPT: ""
gemset: ""
看了下自己的 .rvm/gems/ 里面有好几个 ruby 版本,于是把除了 2.5.6 的那个版本删掉
rvm remove 版本号
看了下自己的 rvm 版本号也过低,更新rvm版本
rvm get stable
更新后设置 ruby 版本
rvm use 2.5.6
再查看
rvm info
得到信息
ruby-2.5.6:
system:
uname: "Darwin joanfendeMacBook-Pro.local 19.0.0 Darwin Kernel Version 19.0.0: Wed Sep 25 20:18:50 PDT 2019; root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64"
name: "OSX"
version: "10.15"
architecture: "x86_64"
bash: "/bin/bash => GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)"
zsh: "/bin/zsh => zsh 5.7.1 (x86_64-apple-darwin19.0)"
remote_path: "osx/10.15/x86_64"
xcode: "11.1"
rvm:
version: "1.29.9 (latest)"
updated: "7 minutes 59 seconds ago"
path: "/Users/joanfen/.rvm"
autolibs: "[4] Allow RVM to use package manager if found, install missing dependencies, install package manager (only OS X)."
ruby:
interpreter: "ruby"
version: "2.5.6p201"
date: "2019-08-28"
platform: "x86_64-darwin19"
patchlevel: "2019-08-28 revision 67796"
full_version: "ruby 2.5.6p201 (2019-08-28 revision 67796) [x86_64-darwin19]"
homes:
gem: "/Users/joanfen/.rvm/gems/ruby-2.5.6"
ruby: "/Users/joanfen/.rvm/rubies/ruby-2.5.6"
binaries:
ruby: "/Users/joanfen/.rvm/rubies/ruby-2.5.6/bin/ruby"
irb: "/Users/joanfen/.rvm/rubies/ruby-2.5.6/bin/irb"
gem: "/Users/joanfen/.rvm/rubies/ruby-2.5.6/bin/gem"
rake: "/Users/joanfen/.rvm/rubies/ruby-2.5.6/bin/rake"
environment:
PATH: "/Users/joanfen/.rvm/gems/ruby-2.5.6/bin:/Users/joanfen/.rvm/gems/ruby-2.5.6@global/bin:/Users/joanfen/.rvm/rubies/ruby-2.5.6/bin:/Users/joanfen/.rvm/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/Home/bin:/usr/local/bin/gradle-2.13/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/share/scala/bin:/usr/local/share/sbt/bin"
GEM_HOME: "/Users/joanfen/.rvm/gems/ruby-2.5.6"
GEM_PATH: "/Users/joanfen/.rvm/gems/ruby-2.5.6:/Users/joanfen/.rvm/gems/ruby-2.5.6@global"
MY_RUBY_HOME: "/Users/joanfen/.rvm/rubies/ruby-2.5.6"
IRBRC: "/Users/joanfen/.rvm/rubies/ruby-2.5.6/.irbrc"
RUBYOPT: ""
gemset: ""
再次执行
pod install
报错信息变化了,说明前面的问题解决
Traceback (most recent call last):
4: from /Users/joanfen/.rvm/gems/ruby-2.5.6@global/bin/ruby_executable_hooks:24:in `<main>'
3: from /Users/joanfen/.rvm/gems/ruby-2.5.6@global/bin/ruby_executable_hooks:24:in `eval'
2: from /usr/local/bin/pod:23:in `<main>'
1: from /Users/joanfen/.rvm/rubies/ruby-2.5.6/lib/ruby/2.5.0/rubygems.rb:303:in `activate_bin_path'
/Users/joanfen/.rvm/rubies/ruby-2.5.6/lib/ruby/2.5.0/rubygems.rb:284:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
没发现 cocoapods 这就很明显,重新安装了下 cocoapods,这里很诡异,明明前天才安装的 cocoapods,不知道自己做了什么操作搞成这样
gem install cocoapods
再次尝试 pod install
开始 Analyzing dependencies
问题解决
网友评论