0

I have just install anaconda (python 2.7 version) in /usr/local/bin

I added /usr/local/bin/anaconda2/bin/ to the path.

Now when I run conda from the command prompt it runs fine (but can't install anything without sudo because of the directory it's in).

However when I run the same command with sudo it can't find conda.

Does anyone know why this is?

Without sudo:

$ conda
usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command

With sudo:

$ sudo conda
sudo: conda: command not found
Zanna
  • 69,223
  • 56
  • 216
  • 327
Grant
  • 382
  • 3
  • 11

2 Answers2

2

Try to call conda with its absolute path :

 sudo /path/to/conda

You probably added conda location to your user $path but not to the sudo account

If this works, you can modify the $path for the root user the same way you did for your user

sudo export PATH=$PATH:/usr/local/bin

EDIT : export doesn't work with sudo, but you can change your path in /etc/sudoers (secure_path)

Félicien
  • 1,163
  • 1
  • 10
  • 18
  • Ah thanks. It does work with the absolute path using sudo. However when i try to add to the path using sudo it tells me sudo: export: command not found. Surely export must be on sudo's path by default? – Grant Feb 13 '18 at 19:21
  • You're right, export doesn't work with sudo because it's a build in shell command – Félicien Feb 13 '18 at 19:29
  • Try sudo -E conda – Félicien Feb 13 '18 at 19:29
  • https://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo – Félicien Feb 13 '18 at 19:30
  • @Grant `export` is a shell builtin - so `sudo export` fails for essentially the reason that [sudo cannot do cd](https://askubuntu.com/questions/419287/sudo-cannot-do-cd). It wouldn't help anyway because sudo uses its own `secure_path` defined in the `/etc/sudoers` file. – steeldriver Feb 13 '18 at 19:30
0

I ended up with a similar situation; by trying to update conda it required permissions which I couldn't give because with sudo it didn't appear as well, so I tried to give permissions to my user like this post suggested but with miniconda3 and after running the update again it worked.