44

I have installed cuda8.0, the latest version. I followed the procedure provided by Nvidia; but, when I type the command nvcc --version it says nvcc is not installed!

What do I do now?

10
  • do a which nvcc see if it returns any thing... Feb 21, 2017 at 4:45
  • No it didnt return Feb 21, 2017 at 4:46
  • That means it didn't install well or is not in your PATH, find where it is with whereis nvcc.. Feb 21, 2017 at 4:49
  • it only displayed "nvcc: " Feb 21, 2017 at 4:56
  • Close and launch terminal and try nvcc --version to be sure Feb 21, 2017 at 5:01

5 Answers 5

80

The problem is [ based on the link you provided] you haven't added it the .bashrc. file so it can be seen:

  1. From the terminal:

     nano /home/username/.bashrc
    
     # or
    
     nano /home/$USER/.bashrc
    
  2. Inside there add the following: (replace cuda-8.0 with your version)

     export PATH="/usr/local/cuda-8.0/bin:$PATH"
     export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH"
    
  3. Then do the following to save and close the editor:

     On you keyboard press the following: 
    
     ctrl + o             --> save 
     enter or return key  --> accept changes
     ctrl + x             --> close editor
    
  4. Now either do source .bashrc or close and open another terminal

  5. Now run nvcc --version

Information:

  • .bashrc: is the file read by the terminal before opening and its found in the /home/$USER diretory of the user in question.
  • the . before the file means its hidden from view unless you instruct you file manager to show hidden files
1
  • 1
    thank you George.
    – arilwan
    Nov 12, 2021 at 11:26
13

The above solution by @George Udosen is fine. If you want to save the manual procedure, you can automate it by the following:

1.create a file "add_to_bashrc"

export CUDA_HOME=/usr/local/cuda
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64
export PATH=$PATH:$CUDA_HOME/bin

2.create a shell script "automate.sh":

(... some installation procedure ...)

cat add_to_bashrc >> ~/.bashrc
. ~/.bashrc

Then you just need to run your shell script

sh automate.sh

Don't forget to check if the CUDA's shortcut (symLink) works correctly. Simply execute:

ls /usr/local/cuda
2
6

The answer from @George Udosen is perfect.

Just for increment it, you can also export to /usr/local/cuda which is a symbolic link to /usr/local/cuda-10.1, based on this answer. So, you can also write:

export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}$ 
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
1

For later versions of CUDA (11.7 for me), I followed the below steps:

  1. Go to https://developer.nvidia.com/cuda-downloads and follow the install instructions.

  2. Inside of the .bashrc file, update the path as follows:
    export PATH="/usr/local/cuda-11.7/bin:$PATH"
    export LD_LIBRARY_PATH="/usr/local/cuda-11.7/lib64:$LD_LIBRARY_PATH"\

  3. The output of nvcc -V, then looks like:
    nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2022 NVIDIA Corporation Built on Wed_Jun__8_16:49:14_PDT_2022 Cuda compilation tools, release 11.7, V11.7.99 Build cuda_11.7.r11.7/compiler.31442593_0

0

The above solution by @Agile Bean is fine. If you want to you can use the env var CUDA_HOME instead of /usr/local/cuda in the LD_LIBRARY_PATH and edit your .bashrc or .zshrc file or the resource file for your shell with emacs or vi or nano or your favorite editor:

  1. emacs $HOME/.zshrc

  2. Add the following lines to the .zshrc file export CUDA_HOME=/usr/local/cuda

export LD_LIBRARY_PATHlrwxrwxrwx 1 root root 20 Sep 11 19:59 =$LD_LIBRARY_PATH:$CUDA_HOME/lib64:$CUDA_HOME/extras/CUPTI/lib64

export PATH=$PATH:$CUDA_HOME/bin

  1. Then open a new shell or source your shell's resource file (e.g. source .zshrc) from the current shell.

(base) ➜ ~ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2022 NVIDIA Corporation Built on Wed_Jun__8_16:49:14_PDT_2022 Cuda compilation tools, release 11.7, V11.7.99 Build cuda_11.7.r11.7/compiler.31442593_0 (base) ➜ ~ which nvcc
/usr/local/cuda/bin/nvcc

Where is cuda really located? Let's follow the symbolic links to find out.

(base) ➜ ~ ls -ld /usr/local/cuda

/usr/local/cuda -> /etc/alternatives/cuda

(base) ➜ ~ ls -ld /etc/alternatives/cuda

/etc/alternatives/cuda -> /usr/local/cuda-11.7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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