How do I fix the 'You don't have write permissions into the /usr/bin directory' error when installing a gem?


There are two ways to get over this annoying /usr/bin error

1. Install the same gem using RVM (Ruby Version Manager), but first, you'll need RVM. Here's how to install RVM on OSX

\curl -sSL | bash -s stable

PS: If that didn't work, here is some extra help


2. "-n flag"

Install the same gem using the mysterious "-n flag"

sudo gem install cocoapods -n /usr/local/bin


3. "Create a ~/.gemrc file"

code ~/.gemrc


With the following content:

   - ~/.gem/ruby
install: -n /usr/local/bin

Now you can install using gem install without the -n flag.


sudo gem install git_swap