Installing CocoaPods With Rbenv

Installing CocoaPods With Rbenv

come from:http://www.egeek.me/2012/07/28/installing-cocoapods-with-rbenv/

2012-07-28 | comments

Usually, each and every iOS project I’ve been working on uses different open-source libraries and frameworks, such as MKStoreKit, JSONKit, CocoaLumberjack, to reuse existing, mostly high-quality, code. Adding them to your Xcode projects brings a question of updating them once in a while. What’s a solution?

The vast majority of the libraries use git as an SCM and are hosted on github. Unfortunately, I had to use corporate subversion for my projects. To relieve the pain, locally every project is also controlled with git. In this scheme, the only solution I saw was to copy the libraries’ sources right in the project’s directory, which has some drawbacks: you can’t easily update them, and unintentionally someone may change the source code, resulting in some complications during updates later.

If the projects used only git, I could add the libraries as submodules. However, these subprojects would contain the whole structure of the project (with demos, tests, etc.). I could add only the required files to the project. But what’s the point of keeping all the rest files?

And then I came across the CocoaPods project, “an Objective-C library manager”. Looks nice. Why not try it?

The text above was a little long prelude to the way I installed CocoaPods on Mac. The article will be interesting to developers who have no idea what to do with Ruby and its environment, such as me. I had no previous experience with Ruby, except for octopress.

First of all, reading the installation instructions here and here suggests that I need to install cocoapods gem (a package in ruby), having updated all the other system gems. But I didn’t feel like messing with system gems in /Library/Ruby/Gems/1.8 directory, that’s why the first command failed:

1
2
3
4
$ gem install cocoapods

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.

Almost grasped the need of the procedure, I bumped into this article, where it’s recommended to use RVM. At this point, I recollected that there are RVM and rbenv tools that manage different ruby installations on the same host. Which one to choose? According to the README, rbenv is unobtrusive and simple, and newer than rvm. Ding, we’ll use it.

Install it with:

1
$ brew update --rebase && brew install rbenv ruby-build

A minute, and it’s here. Then I add the if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi line to my ~/.zshrc, and source it. Next step is to install a newer local version of Ruby: rbenv install 1.9.3-p194 (to check available versions, run rbenv install).

To use this version, I ran rbenv global 1.9.3-p194, and rbenv rehash just in case. It didn’t seem to work, because:

1
2
$ ruby --version
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]

Five minutes of thoughts later I did source ~/.zshrc and it worked! Now we can easily install bundler (I’m not sure if it’s required here, I read somewhere it helps to manage gems) and cocoapods:

1
2
$ gem install -V bundler
$ gem install -V cocoapods

Do rbenv rehash to be sure. It’s installed now, and you can continue with other tutorials.

你可能感兴趣的:(ios)