when I run a compiled program with sudo, ex: sudo ./program
it says:
You must install .NET to run this application.
App: /home/pi/program Architecture: arm App host version: 6.0.10 .NET location: Not found
Learn about runtime installation: https://aka.ms/dotnet/app-launch-failed
Download the .NET runtime: https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=arm&rid=raspbian.11-arm&apphost_version=6.0.10
Yet it's installed in both accounts, root
and pi
, I know it has to do with sudo, but I don't know how to fix it. Afaik sudo creates a clean environment but no matter if I disable the secure_path
in /etc/sudoers
or even adding the paths there, it just keeps showing the above message.
I've installed the script version of dotnet 6.0.10 in a raspberry pi 3b :
uname -a
output:
Linux raspberrypi 5.15.74-v7 #1595 SMP Wed Oct 26 11:03:05 BST 2022 armv7l GNU/Linux
And I have exported both paths to env in root
and pi
:
.bashrc
content:
export DOTNET_ROOT=$HOME/.dotnet export PATH=$PATH:$HOME/.dotnet
I have rebooted several times after each modification, env paths are updated accordingly yet it keeps failing
The only way it works is logging in as root with sudo su
or sudo -i
but it's a headache doing this every time I want to run my programs with root access
What can I do?
CodePudding user response:
Well, the simplest solution is always the best.
sudo
has a param -E which preserves the environment, so it recognizes the dotnet path.
A simple solution is to run sudo -E ./program
or create an alias to include -E and preserve the environment for every use.