PATH variables on and off sudo

asked 2017-08-18 11:44:32 -0500

bluesummers gravatar image

OK, I've learnt that the right way to add PATH variables permanently is by editting ~/.bash_profile just extending the PATH=xxx string with :/new/path.

But I now find myself when I'm running sudo commands those path variables aren't available... so I'm asking myself what is the best practice in that manner?

The real use case is using nvidia-docker-plugin and when I try to run something on top of it I get a missing file error that advises me to put /usr/lib64 in my PATH... The thing is that it is there and I believe the problem is that when I try to run something on top of that docker using sudo nvidia-docker run --rm nvidia/cuda nvidia-smi I guess it doesn't use the same PATH.

edit retag flag offensive close merge delete

Comments

The way you setup the variables is correct but for your user only so other users will not have those variables when you use sudo -s you using root environment therefore there are not such variables unless you add then on .bash_profile of your root user. To add those variables to all users you can modify /etc/environment and it will add it to all users after your login and log out.

aeperezt gravatar imageaeperezt ( 2017-08-18 14:23:30 -0500 )edit

I will try that, is that considered a bad practice though?

bluesummers gravatar imagebluesummers ( 2017-08-19 01:34:34 -0500 )edit