nvcc not found, but only when using sudo

22,247

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 nvcc to sudo /path/to/nvcc
  • Create a symlink to nvcc in one of the directories listed in secure_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
Share:
22,247

Related videos on Youtube

dsp_099
Author by

dsp_099

Updated on September 18, 2022

Comments

  • dsp_099
    dsp_099 over 1 year

    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 2
    

    So, kind of interesting. Output of nvcc:

    nvcc fatal   : No input files specified; use option --help for more information
    

    Whereas the output of sudo nvcc:

    sudo: nvcc: command not found
    

    I 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:/bin
    

    Thanks in advance!

  • dsp_099
    dsp_099 about 10 years
    Is there a way I can include /usr/local/cuda-5.0/bin/ just for the current session in the terminal such that when time comes and make script calls upon it it will find it? I don't think I'll ever need it again.
  • janos
    janos about 10 years
    @dsp_099 yup, see my updated answer
  • James Tobin
    James Tobin almost 10 years
    I tried the symlink way with the command listed and that didn't work, however editing the installer script worked great. Might also want to include the link to askubuntu.com/questions/231503/nvcc-compiler-setup-ubuntu-12‌​-04 so people who are noobs(like myself) can let this be a one stop shop
  • janos
    janos almost 10 years
    Thanks @JamesTobin! I'm happy to add links that improve the answer, but I don't see the added value in the link you posted. Can you explain?
  • James Tobin
    James Tobin almost 10 years
    For those people who wouldn't know how to find where their nvcc is located. Its hard to add it to the path if you don't know where it is
  • janos
    janos almost 10 years
    @JamesTobin I see, I added a note about that.
  • James Tobin
    James Tobin almost 10 years
    @janos very nice, hopefully others will find it useful as well