Specifically, I am using conda command part of Miniconda distribution. It happens that the installer put files in /root/miniconda3/.

The problem is that /root/miniconda3/bin is in path, but the command conda can only be run by root, not other sudoer.

I tried to set rights to 777 (I know this is bad since it contains compiler and stuff, and it's under root, but this is only for test environment).

Note: I own the root and the sudoer.

  • everything under /root is by definition only accessible by root by default, and using sudo you become "root" (sort of). What is your doubt here? – Rui F Ribeiro Feb 25 '18 at 12:24
  • I know. But using sudo conda returns sudo: conda: command not found whil switching to SU mode it does run. – Curcuma_ Feb 25 '18 at 12:30

sudo conda won't necessarily run /root/.bash_profile but instead your original account's, unless the /etc/sudoers option always_set_home is set.

This is by design: it allows multiple administrators on the same system to become root and still maintain their personal shell environment preferences.

Also, because sudo always resets the PATH environment variable to a standard default value before executing the command as the target user, your PATH setting as the original user won't be preserved across sudo.

In this case, you'll want the sudo command to set HOME=/root before executing the conda command using the shell, so that the PATH setting in /root/.bash_profile will take effect and conda will also find its other configuration files:

  • $HOME/.condarc file
  • $HOME/.conda/ directory
  • $HOME/.continuum/ directory

To do that, run sudo -H conda or sudo -i conda instead of just sudo conda.

| improve this answer | |

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