如何让Cocoapods与RVM一起运行?

时间:2016-03-10 11:00:29

标签: ruby rubygems rvm cocoapods

不幸的是,我最近在Mac上将系统Ruby升级到2.3。由于我必须将Cocoapods 0.39用于特定项目which does not properly work,我想使用旧版本的Ruby。为此,我安装了rvm然后切换到ruby-2.2-head:

> \curl -sSL https://get.rvm.io | bash -s stable --ruby
> rvm install 2.2-head
> rvm use 2.2-head --default

这很好用。然后我尝试安装Cocoapods并得到通常的错误消息:

> rvmsudo gem install cocoapods

Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:

    export rvmsudo_secure_path=1

to avoid the warning, put it in shell initialization file to make it persistent.

In case there is no `secure_path` in `/etc/sudoers`. Run:

    export rvmsudo_secure_path=0 
通过选择第二个选项我沉默了。然后我检查了Cocoapods并得到了一个很棒的错误信息:

> pod --version

/Users/bastian/.rvm/rubies/ruby-2.2-head/lib/ruby/site_ruby/2.2.0/rubygems.rb:250:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException)
    from /Users/bastian/.rvm/rubies/ruby-2.2-head/lib/ruby/site_ruby/2.2.0/rubygems.rb:278:in `activate_bin_path'
    from /Users/bastian/bin/pod:22:in `<main>'

此外,Cocoapods未列出以下命令:

> gem list

*** LOCAL GEMS ***

bigdecimal (1.2.6)
io-console (0.4.3)
json (1.8.1)
psych (2.0.8)
rake (10.4.2)
rdoc (4.2.0)

此外,Cocoapods似乎安装在错误的目录中:

> which pod
/Users/bastian/bin/pod

因此,如果我切换回系统Ruby,pod --version命令将返回0.39.0

我猜不知道Cocoapods是不是安装了RVM Ruby而是安装了系统版本。我做错了什么?

1 个答案:

答案 0 :(得分:2)

this Stackoverflow post的帮助下,我能够解决问题。我不知道为什么但是从--user删除单个条目.gemrc为我解决了这个问题。由于文件只包含这一行,我只是将其重命名并重新安装了Cocoapods:

 > mv ~/.gemrc ~/.gemrc_backup
 > gem install cocoapods`

现在Cocoapods正在再次工作,因为它位于正确的路径上:

> which pod
/Users/bastian/.rvm/gems/ruby-2.2-head/bin/pod