8

There are some answers saying using gem 'cocoapods', '0.33.1' or gem 'pod', '0.33.1

but this does not work.

ERROR: While executing gem ... (Gem::CommandLineError) Unknown command cocoapods,

In one project I need to use 0.33.1, but 0.34.4 in another. How do I switch the cocoapods version quickly on command line? I don't want to use gem install or uninstall.

I am using rbenv with ruby version 2.0.0p0. Keep using rbenv is preferred but I can switch to rvm or pure ruby only if there is no other options.

Thanks.

fangmobile
  • 839
  • 8
  • 23
  • What's the problem with using the newest version in both projects? – Keith Smiley Jan 25 '15 at 00:58
  • It breaks things if I use the 0.34.4 in one project. Team decision to stay with 0.33.1. This can not be changed at this moment. – fangmobile Jan 25 '15 at 01:06
  • I'm sure whatever issue you're having could be resolved. But ignoring that you should be very wary of using old versions of CocoaPods. At anytime the specs repo support for the old versions could be removed, leaving you with a broken build. – Keith Smiley Jan 25 '15 at 23:29

3 Answers3

17

You can do the following to use different versions:

pod _0.34.4_ install 

or

pod _0.34.1_ install
rantunes
  • 376
  • 4
  • 7
8

This is precisely the purpose of Bundler

In one project, you specify this in the Gemfile:

gem 'cocoapods', '0.33.1'

along with all other gems.. and run bundle install to install them.

There are some other steps to make sure you load those gems from bundler, I'd read that site for the full documentation.

Rails projects have this already set up for you, but if this is a plain old ruby project, you have to wire it up yourself.

DGM
  • 26,629
  • 7
  • 58
  • 79
  • there is no Gemfile. I just need to switch cocoapods version on command line. – fangmobile Jan 24 '15 at 22:56
  • 3
    I'm recommending that you add a Gemfile and the relevant parts of bundler to the program. – DGM Jan 25 '15 at 03:59
  • These are ios projects, we try not to add any gem file in the project. This should work but not for us. I am giving 1 up but can't accept it as answer. – fangmobile Jan 25 '15 at 04:11
  • 2
    If the project only works with one particular gem version, then Gemfile and bundler are the exact correct solution. Can't make it any more clear. – DGM Jan 25 '15 at 15:01
3

FYI I am using the following temp solution. Since I am using rbenv, I install different versions of cocoapods under different version of ruby. For example,

rbenv global 2.1.0 gem install cocoapods -v 0.34.4 rbenv global 2.0.0-p0 gem install cocoapods -v 0.33.1

When I work on different Xcode projects that requires different version of Cocoapods, I just switch ruby version on the fly, and Cocoapods version is switched accordingly.

As I mentioned these are xCode projects and we are not allowed to add gemfile or install gem in the project folder. So this works for me.

fangmobile
  • 839
  • 8
  • 23