sudo returns “xyz: command not found”


I ran into the situation that I could not execute any command with “sudo” without passing the entire path to the actual command (you can get the path with “which”).

I.e. “sudo port install subversion” always returned “port: command not found”.

The reason is, that the superuser / root does not know the “port” command.

One solution would be to add the path to the command to the .bash_rc or .profile file in the root user folder (on my Mac it’s “/var/root”).
But if your root account / machine happens to be managed by Puppet or so, then this setting would be removed by Puppet immediately.

Therefore the solution for my problem was (using bash terminal on my Mac) to add the following to my .profile file:

After restarting the terminal I was able to use “mydo” instead of “sudo”.

It works perfectly :-)