4

The Background

I am somewhat new to Unix coming from a .NET environment but I know enough now to get me in trouble.

I got an existing code I am working with that uses Cocoapods so I tried to install Cocoapods.

Initially when I installed it it failed saying it requires a newer version of Ruby. To install Ruby I used an installer called rvm. With some effort I got RVM installed and got Ruby Version 2.1.0.

When I go to directory where the app is and i type pod install it responds with pod: command not found. The assumption is that there must be something wrong with the install of cocoa pods. If I try any command to install or uninstall Cocoapods

gem install cocoapods    or gem uninstall cocoa pods

it returns the same response which is:

/Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_gem.rb:59:in `gem': uninitialized constant Gem::LOADED_SPECS_MUTEX (NameError)
from /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:46:in `require'
from /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems.rb:601:in `load_yaml'
from /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/config_file.rb:328:in `load_file'
from /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/config_file.rb:197:in `initialize'
from /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:74:in `new'
from /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:74:in `do_configuration'
from /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:39:in `run'
from /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/bin/gem:21:in `<main>'

I am thinking that perhaps the failed attempts to install cocoa pods may have either corrupted something, put something in the wrong place. I want to completely uninstall cocoapods and reinstall it but install and uninstall are not doing anything.

UPDATE: Using gem list --local | grep cocoa pods just to see what version of CocoaPods I have installed gives me the same exact output.

The Question:

Does anyone know a way to either fix this issue or completely rip and rebuild CocoaPods?

logixologist
  • 3,694
  • 4
  • 28
  • 46

3 Answers3

24

I was brilliantly assisted with help from @Pedros (the currently accepted answer) but because there were so many comments back and forth I decided to clean up the answer that worked for me. I will keep his as the accepted answer since he really helped me tremendously on this one. If this is helpful to you and you choose to up vote, please also up vote the accepted answer since this is derived almost completely from his answer.

Here is what I found out : In my case it was that RVM was not installed correctly so RubyGems wasn't installed correctly. That in turn made CocoaPods not install correctly.

To completely uninstall and remove RVM: try sudo rvm implode or you can do sudo rm -rf ~/.rvm

I did some checks to see if I had the correct versions. I will post what they should be right now but this can be different as versions keep getting updated.

ruby --version should be 2.1.2

which ruby should be the RVM ruby. (To see if there is no conflict with OSX`s ruby)

gem --version should be 2.2.2

Reinstall RVM by doing this: \curl -sSL https://get.rvm.io | bash -s stable --ruby

Reinstall CocoaPods like this: gem install cocoapods

I hope this saves someone some development hours and hair loss :)

pedros
  • 1,197
  • 10
  • 18
logixologist
  • 3,694
  • 4
  • 28
  • 46
  • Why `which ruby` should point to RVM ruby when we've just uninstalled RVM..? I suppose these outputs you've pasted should be valid AFTER reinstallation of RVM, shouldn't they? – Nat Oct 06 '15 at 11:03
  • Ok in my opinion (which may be wrong, as I'm weak in the topic): `ruby --version` should point your system version of ruby. You should not mess with it - whatever version it is, its ok. `which ruby` before installation should point to system, after installation to RVM. `gem --version` should be the newest one, in case of the day 6.10.2015 it's 2.4.6. – Nat Oct 06 '15 at 12:27
  • reinstalling rvm and then cocoapods worked for me, but I don't think my original issue was a bad installation of rvm. It was working fine before and after I pulled some changes from a master branch and merged them it suddenly broke. – Minimi Oct 04 '16 at 20:22
  • It helped - implode->reboot->install ruby->install cocoapods – Nike Kov Nov 22 '16 at 04:36
  • Thanks for this, it looks like RVM was my problem too. (M1 processor Mac has a lot of issues with CocoaPods. Hoping this will be sorted in the new version.) – Ash Dec 16 '21 at 09:04
3

gem env will tell you the installation path of your gems.

By the error you got on the first time you installed the gem it could be a PATH error. Maybe your gems folder is not properly set in the PATH and shell is not finding Cocoapods.

Try to print your PATH with echo $PATH and see if the - EXECUTABLE DIRECTORY: from gem env is there.

Also try gem pristine --all

If that doesn't work try to change to ruby 2.1.2 and reinstall cocoapods.

pedros
  • 1,197
  • 10
  • 18
  • all commands returning the same error. I tried to change the ruby version like this `sudo gem update --system 2.4.1` and even `gem env` returns the same error above. – logixologist Jul 29 '14 at 14:55
  • OK my path shows this: `/Users/aliabidhusain/.rvm/gems/ruby-2.1.2/bin:/Users/aliabidhusain/.rvm/gems/ruby-2.1.2@global/bin:/Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/aliabidhusain/.rvm/bin` – logixologist Jul 29 '14 at 14:57
  • 1
    The problem must be with your rubygems. Try `rvm rubygems latest --force`. This should reinstall Rubygems – pedros Jul 29 '14 at 15:04
  • Just to make sure, tell me the output of the following commands: `ruby --version` `which ruby` `gem --version` – pedros Jul 29 '14 at 15:06
  • Progress…. so it turns out running that command does attempt a reinstall of Rubygems but I get an error: `Permission denied @ rb_sysopen - /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/available_set.rb` – logixologist Jul 29 '14 at 15:06
  • `sudo rvm rubygems latest --force` – pedros Jul 29 '14 at 15:07
  • ruby --version = ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin12.0] – logixologist Jul 29 '14 at 15:07
  • which ruby gem --version /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/bin/ruby /Users/aliabidhusain/.rvm/rubies/ruby-2.1.2/bin/gem – logixologist Jul 29 '14 at 15:08
  • running the sudo command return this error: `/Users/aliabidhusain/.rvm/rubies/system/bin/ruby: No such file or directory` – logixologist Jul 29 '14 at 15:10
  • Do I need to be in a specific directory when running these commands or will it know where to put them? – logixologist Jul 29 '14 at 15:12
  • No, they should run anywhere. This errors are weird, here is what I would try to do. Uninstall RVM with `rvm implode`. Reinstall RVM, only using sudo if you get a permission error. And after that check the same three commands `ruby --version`:should be 2.1.2. `which ruby`: should have RVM in the path. `gem --version`: should be 2.2.2. If all is right run `gem install cocoapods` – pedros Jul 29 '14 at 15:23
  • ummmm ok that was weird: I assume it uninstalled but this is a strange message: `Psychologist intervened, cancelling implosion, crisis avoided :)` – logixologist Jul 29 '14 at 15:24
0

Try bundle install first, then you can run pod install again.

mim
  • 1,301
  • 14
  • 24