Capistrano: 'rake command not found'
Apr 27 2009 // Comments
I recently ran into a strange error; after successfully using Capistrano to deploy numerous projects I recently discovered that a non-standard installation of ruby and/or rubygems, rake, and other gems leads to a deployment error: 'rake command not found'. I was configuring and deploying to a new slice (at slicehost) -- now since this was going to a fairly low traffic site, I was using Apache w/ Phusion Passenger to host the rails environment.
Passenger simplifies deployment as it's an apache module and requires very little configuration to get up and running. The guys that wrote Passenger also bundle a "enterprise" version of ruby that supposedly reduces memory requirements over the standard ruby distro. I thought since this site is very basic, it would be the perfect opportunity to give it a whirl.
Everything installed seamlessly and passenger worked as advertised. Even installing the ruby "enterprise" version was nice and easy. It installs into a non-standard location (/opt/ruby-enterprise-*); this is nice as it will not step on an existing version of ruby. However, one gotcha, you will need to reinstall all your gems into the new location of ruby after you add the "enterprise" location to your path (in my case /opt/ruby-enterprise-1.8.6-20090201)
I deployed the application with migrations, and BOOM! hit a "rake command not found" error during the migrations phases of the deployment. Now, being the amateur sysadmin that I am, I just assumed it was a PATH issue on the server and logged in to update the PATH with the correct location. To my surprise, I had already done this, so the PATH was already correct. To make a long story shorter -- capistrano uses SSH to deploy, and the standard install of ssh is compiled with the basic PATH setup (non over-loadable by default); my non-standard location for my "enterprise" version of ruby was not included in the ssh default PATH (sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin), check our sshd_config for a comment telling you what default path was compiled into your ssh server.
So to enable per user PATH environments for ssh logins, here is what you need to add to your sshd_config:
PermitUserEnvironment yes
Then in your "users" ssh home directory (~/.ssh/environment), add something to this effect (your mileage will vary):
PATH=/opt/ruby-enterprise-1.8.6-20090201/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin
This should now set the PATH variable correctly upon an ssh login for "user" to run non-interactive commands. So, retrying the deployment yields a successful migration and therefore a successful deployment.
~ Happy deploying ~

I'm a Ruby and Rails programmer with tons of web development
experience with various technologies. I'm an active private pilot and
always looking for excuse to go flying.