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.


  1. Keep in mind that sudo/su reset $PATH on purpose to prevent you from running (possibly exploited) programs with the same name from your local path, but with root privileges.

  2. @downland: Very good point. Security and convenience are often at odds -- the old MS Windows security model is a good example of the pitfalls.

    In this case, I'm on a box that is very secure, and the only addition to my PATH is the /opt/ruby-enterprise/bin.