Linux Tutorial: how to define the PATH environment variable for the sudo command
Problem: I have installed a program in the/usr/local/bin directory. This program requires root permission for execution. When I run it with sudo, I receive "sudo: XXXXX: command not found "error prompt. I don't know why/usr/local/bin is not included in the path environment variable. How can I solve this problem?
When you use sudo to execute a program, it is safe to consider that the program will be executed in a new and minimal environment, that is, environment variables such as PATH, the sudo command has been reset to the default status. So when a newly initialized PATH variable does not contain the directory of the program you want to run and runs it with sudo, you will receive an error message "command not found.
To change the initial value of PATH in the sudo session, open the/etc/sudoers file in the text editor and find the "secure_path" line. When you execute the sudo command, the PATH contained in "secure_path" will be used as the default PATH variable.
Add the required path (such as/usr/local/bin) to "secure_path", and solve the problems encountered in the beginning.
Defaults secure_path =/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
This modification takes effect immediately.
Use and enable the root account with Ubuntu sudo and su commands
Sudo: sorry, you must have a tty to run sudo
Configure sudo permissions in Linux
Temporary root permission for sudo Configuration
How to solve the problem that users cannot execute sudo in Linux
The Linux system administrator must not know the command: sudo
Sudo permission allocation
This article permanently updates the link address: