Thursday, November 12, 2009

sudo PATH fix for Ubuntu

angry cat
Photo by gumuz

Passenger is fantastic way to run Rails apps. The installation is nothing short of awe inspiring, and the thing just works. If you are using Rails, you should be using it along with Ruby Enterprise Edition.

Rails deployments used to be a nasty mix of different software with configuration nightmares that would make a sysadmin weep. The Phusion folks deserve a huge round of applause, and some donations on their very funny "Enterprise License" page.

sudo PATH bug in Ubuntu

The only annoyance I've had, and this is no fault of Passenger, is with running the passenger-status tool. It requires some extra permissions, but running it with sudo does not work "out of the box."

Permission denied

$sudo passenger-status
sudo: passenger-status: command not found

The problem here is that although I've modified my PATH to include the path to the passenger-status command (/opt/ruby-enterprise/bin), my PATH does not include it when using sudo. A quick glance at the sudoers man file reveals the env_keep option, but this totally doesn't work on ubuntu.

the "fix"

The workaround for this bug is incredibly low-tech, but works like a champ. Just add the following line to your .bashrc file.

alias sudo='sudo env PATH=$PATH'

To test it without logging out and back in, just reload that file...

source ~/.bashrc

Not pretty, but it does the job.