sudo: rake: command not found
Posted by javier ramirez on July 6, 2009
I hate it when it happens, don’t you?
And it’s not only rake, but some other utilities too.
Bottom line is, in Ubuntu sudo is by default set to use a secure path. You can change the secure path if you are compiling from source, but we are talking Ubuntu here, the windows for the rest of us, so you get what your package says you get and that’s fine.
There are a couple of good solutions (other than switching to gentoo or slackware ;) )
If you want to use always the same PATH as you are using in your environment, you can just set an alias to sudo and make it set the PATH every time you are invoking it.
alias sudo=”sudo env PATH=$PATH”
It’s safe enough, but notice every time you are using sudo, you will be setting the environment to that of the calling user. Do your maths and reckon whether you are comfortable with that or not.
The option I chose is a bit pickier, making a link to the rake executable from /usr/local/bin, which is one of the secure paths.
sudo ln -s `which rake` /usr/local/bin/
Either way, your problem is solved. Now go save the world! You’re welcome ;)