sudo gem install buildr -v 1.3.5
recently failed. I got an environment variable JAVA_HOME not set error which was definitely set to /System/Library/Frameworks/JavaVM.framework/Home in ~/.profile.
I noticed later that exporting the java home in that file unfortunately doesn’t have an effect on the environment variables under sudo. The trick is to pass it to sudo.
sudo env JAVA_HOME=$JAVA_HOME gem install buildr -v 1.3.5