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 ;)
Keith said
Thankyou ever so much for posting this. I still don’t get quite how that symbolic link actually works, but it definitely fixes the problem!!
Ian said
The alias command works well.
Another option is to chmod a directory to allow execution for users.
Dean said
Thanks for this. I had issues with both gem and ruby, so created symbolic links for all of the ruby bin executables…
find /home/dean/.rvm/rubies/ruby-1.9.3-p0/bin/ -name “*” -exec sudo ln -s {} /usr/local/bin \;
this makes an extra “bin” link which needs deleting: (it make a symlink of the “.” directory)
sudo rm /usr/local/bin/bin
now it works!
sudo gem install mysql
Fetching: mysql-2.8.1.gem (100%)
Building native extensions. This could take a while…
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1…
Installing RDoc documentation for mysql-2.8.1…