How to get Cocoapods running with RVM?

2019-06-12 01:53发布

问题:

Unfortunately, I recently upgraded the system Ruby to 2.3 on my Mac. Since I have to use Cocoapods 0.39 for a specific project which does not properly work, I would like to use an older version of Ruby. For this purpose, I installed rvm and then switched to 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

This worked fine. Then I tried to install Cocoapods and got the usual error message:

> 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 

which I silenced by chosing the second option. Then I checked Cocoapods and got a fantastic error message:

> 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>'

Furthermore, Cocoapods is not listed with the following command:

> 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)

Furthermore, Cocoapods seems to be installed into the wrong directory:

> which pod
/Users/bastian/bin/pod

So if I switch back to the system Ruby, the pod --version command returns 0.39.0.

I guess that somehow Cocoapods was not installed with the RVM Ruby but rather with the system version. What did I do wrong?

回答1:

With the help of this Stackoverflow post I was able to solve the problem. I don't know why but the removal of the single entry --user from .gemrc solved this problem for me. Since the file only contained this one line I just renamed it and reinstalled Cocoapods:

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

Now Cocoapods is working again as it resides at the correct path:

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