0

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)

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?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Bastian
  • 4,638
  • 6
  • 36
  • 55
  • This smells like a `sudo`-based problem. On a single-user system using `sudo` can really confuse things quickly because it implies RVM will act upon the system version of Ruby, not the individual user's version in the home directory. https://rvm.io/rvm/install#installing-rvm is the definitive documentation for this. – the Tin Man Jan 20 '20 at 19:57

1 Answers1

3

With the help of "How to get RVM to set correct gem path" 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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Bastian
  • 4,638
  • 6
  • 36
  • 55
  • Was it not related to you install firstly with `rvmsudo gem install` and then re-installing it with `gem install`? – cefigueiredo Sep 06 '17 at 15:59
  • Just to add to this I did both `mv ~/.gemrc ~/.gemrc_backup` and `mv ~/.gem ~/.gem_backup` and then ran `gem install cocoapods` – Francois Jan 30 '23 at 11:02