38

The Tensorflow linux installation instructions say:

Ensure that you create the CUDA_HOME environment variable as described in the NVIDIA documentation.

I cannot find any mention of CUDA_HOME in the NVIDIA instructions for cuDNN v6 or in the NVIDIA CUDA Toolkit install instructions. Does anyone know how this variable should be set on linux?

Ron Cohen
  • 2,815
  • 5
  • 30
  • 45
  • 2
    If you installed CUDA in `/usr/local` then in `.bashrc` file enter `export PATH=/usr/local/cuda-8.0/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH`. – zindarod Sep 05 '17 at 23:04
  • 1
    @Zindarod that is definitely part of the LD_LIBRARY_PATH step, which is the step before the question about CUDA_HOME, but that doesn't address the question about CUDA_HOME. – carbocation Oct 21 '17 at 14:29

4 Answers4

38

Run the following command in the terminal:

export CUDA_HOME=/usr/local/cuda-X.X

Where you replace X.X by the first two digits of your version number (can be found out e.g. via nvcc --version).

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
Dmitry
  • 14,306
  • 23
  • 105
  • 189
  • 6
    This should probably be updated to cuda-9.0 now that the recommended installation is version 9.0. – Wade Feb 18 '18 at 08:14
  • 5
    Or just use `export CUDA_HOME=/usr/local/cuda` if you have a symlink to the newest version – Baschdl Apr 14 '18 at 09:35
  • 1
    I note that the `nvidia-cuda-toolkit` package on Ubuntu 20.04 creates a folder `/usr/lib/cuda` which contains `bin`, `include` etc. So presumably `CUDA_HOME` should in this case be set to /usr/lib/cuda? – user2023370 Sep 04 '20 at 11:13
  • @user2023370 , I have the same doubt. did you figure this out in the end? – desmond13 Oct 07 '21 at 08:58
  • @desmond13 Alas no. I don't find that this variable is properly documented by NVIDIA. – user2023370 Oct 08 '21 at 11:32
  • if install cudatoolkit via anaconda , can try: `export CUDA_HOME=$CONDA_PREFIX/bin/` – Watson21 Dec 13 '22 at 08:29
  • If installed via the official Nvidia CUDA Toolkit installer, there will be multiple locations: `/usr/local/cuda/`, `/usr/local/cuda-X` (X - major version) and `/usr/local/cuda-X.Y` (Y - minor version). All are connected to each other via symlinks. If you want to use the latest version (in case you have multiple), you eather go with `cuda` or `cuda-X.Y`. – rbaleksandar Aug 11 '23 at 09:49
7

If using anaconda to install, the following would apply:

export CUDA_HOME=$CONDA_PREFIX

You can add this to ~/.bashrc or ~/.bash_profile to have this environment variable persist between sessions. To apply this change in the bash file to your current session run: source ~/.bashrc or source ~/.bash_profile

Verify this by issuing an echo $CUDA_HOME command.

Andrew S
  • 71
  • 1
  • 2
1

Just had this issue whilst trying to install NVIDIAs Kaolin. As @user2023370 said the nvidia-cuda-toolkit creates a bunch of folders and I can confirm that it will set CUDA_HOME. This circumvents the need to set the variable with export CUDA_HOME=/usr/local/cuda-X.X

tldr; install nvidia-cuda-toolkit to set CUDA_HOME

qwertyuiop
  • 21
  • 2
-1

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#post-installation-actions

or for the latest version of cuda put export PATH=/usr/local/cuda-11.6/bin${PATH:+:${PATH}} at the end of your bashrc.

It should work

NatiCog
  • 49
  • 3