nvcc not found, but only when using sudo
I can't get ANYTHING working on linux. I'm trying to compile CudaMiner. Output of sudo make:
ypt-jane.o `test -f 'scrypt-jane.cpp' || echo './'`scrypt-jane.cpp
mv -f .deps/cudaminer-scrypt-jane.Tpo .deps/cudaminer-scrypt-jane.Po
nvcc -g -O2 -Xptxas "-abi=no -v" -arch=compute_10 --maxrregcount=64 --ptxas-options=-v -I./compat/jansson -o salsa_kernel.o -c salsa_kernel.cu
/bin/bash: nvcc: command not found
make[2]: *** [salsa_kernel.o] Error 127
make[2]: Leaving directory `/var/progs/CudaMiner'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/var/progs/CudaMiner'
make: *** [all] Error 2So, kind of interesting. Output of nvcc:
nvcc fatal : No input files specified; use option --help for more informationWhereas the output of sudo nvcc:
sudo: nvcc: command not foundI have identical exports listed in ~/.bashrc AND /etc/bash.bashrc. (Nvcc is located in: /usr/local/cuda-5.0/bin/nvcc)
I also tried changing the current path, to no avail:
$ sudo bash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ PATH=$PATH:/usr/local/cuda-5.0/bin/nvcc
$ sudo bash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binThanks in advance!
3 Answers
So apparently, nvcc is not on the PATH when you run it with sudo. You can confirm this with:
sudo bash -c 'echo $PATH'The easiest solution is to call sudo with the absolute path of nvcc:
sudo $(which nvcc)When running commands without absolute path like nvcc, sudo uses the value of the secure_path configuration in /etc/sudoers as the PATH, for example in my system:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"So even if you set PATH in one of the startup files that the shell normally sources, it won't work. If you want to make sudo nvcc work temporarily, just to get your build working, I think you have two options:
- Edit the installer script and change the lines with
sudo nvcctosudo /path/to/nvcc - Create a symlink to
nvccin one of the directories listed insecure_path, like this:sudo ln -s /path/to/nvcc /sbin/nvcc
UPDATE
If you have a hard time finding the path of nvcc, you can try these commands, in this order (they get slower and slower), until you find a match:
which nvcc
find /usr/local/cuda-5.0 -name nvcc
find /usr/local/ -name nvcc
find /opt -name nvcc
find / -name nvcc 7 You can use -E option of sudo to preserve your user environment. From the man page:
-E, --preserve-env Indicates to the security policy that the user wishesto preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.You can test this with:
$ sudo bash -c 'echo $PATH'and then
sudo nvcc The cause might be a read-only folder. In my case the 'Make' file that calls nvcc was in a read-only folder. Changing the folder permission settings solved my problem.