I have installed Maven on Ubuntu 16.04 following instructions.

I edited /etc/environmentand added path to maven/bin folder to $PATH variable.

Under my normal user everything works just fine, but when I try to run e.g. sudo mvn test it tells me that mvn is unknown command. Restart didn't help.


/bin/sh: 1: mvn: not found

I am also little perplexed by /bin/sh piece - I am using bash.

So where should I put path to maven binary to make even sudo commands see it? Thank you.


When using sudo your $PATH is getting overridden for security reasons by a line like this in your /etc/sudoers file:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin


Even though an entry such as this is present in /etc/environment:

$ cat /etc/environment

And it appears to be picked up:

$ sudo env | grep PATH

And we have a script in /tmp:

$ ls -l /tmp/blah.bash
-rwxrwxr-x 1 vagrant vagrant 20 Aug  8 20:57 /tmp/blah.bash

And this script will print whoami when run:

$ cat /tmp/blah.bash


Sudo won't let us do it:

$ sudo blah.bash
sudo: blah.bash: command not found

Changing sudo's secure path

But if I edit my /etc/sudoers file:

$ sudo visudo
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/tmp

Now it works:

$ sudo blah.bash


Think long and hard about why you're adding additional directories to sudo's secure path. This is set up like this for a very good reason. Do not take lightly the addition of extra paths for sudo commands!

Adding extra directories exposes you and your users to additional risks which you many not realize until it's too late.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.