I tried to install cocoapods (http://cocoapods.org/) on my OSX Mountain Lion.
moshe-mbp:~ moshem$ gem install cocoapods
ERROR: Could not find a valid gem
I fixed it by only appending to the PATH variable in my ~/.bash_profile, which in my case meant changing
export PATH="/usr/local/mysql/bin:$PATH"
export PATH=$M2:$PATH
export PATH=$JAVA_HOME/bin:$PATH
to
export PATH="$PATH:/usr/local/mysql/bin"
export PATH=$PATH:$M2
export PATH=$PATH:$JAVA_HOME/bin
In terminal, type nano ~/.bash_profile to start editing.