I want to install dotnet to root on a linux vm and be able to run the dotnet with just a
sudo dotnet
call instead of needing to give the full path every time.
I installed dotnet on a linux VM with sudo using dotnet-install.sh. Dotnet is installed in /root/.dotnet/ . I can run the dotnet executable with sudo /root/.dotnet/dotnet –version which prints the version as expected. However, even though I did export PATH=’$PATH:/root/.dotnet" to add the dotnet folder to $PATH, and I can see that it’s been added by doing echo $PATH, trying to execute sudo dotnet –version will result in a Command not found error. How can I add the path properly so the dotnet executable can be ran with just sudo dotnet …?
2
Answers
You can try two options:
/root/.dotnet/dotnet
binary to/usr/local/bin
, and then you should be able to execute it.OR
sudo
doesn’t typically use your personalPATH
variable as that would be a security risk. A bad user could run a program with elevated privileges by installing it in a directory they control and putting that directory on their path ahead of a trusted directory.To demonstrate, the output of these two commands will likely be different for you:
The intended way to configure this is with the
secure_path
option in your sudoers file. See the sudoers manpage:If you trust
/root/.dotnet
and want programs there to be executable withsudo
then you can add it to the sudoers file: