PATH & LD_LIBRARY_PATH

  1. Set up the development environment by modifying the PATH and
    LD_LIBRARY_PATH variables:
$ export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
$ export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\
                         {LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

The above paragraph is extracted from CUDA Quick Start Guide, 4.1.5.1. Debian Installer.
I would to understand the following:

  1. 1. Do I need these environment settings on a new terminal every time I use CUDA, its libraries and other tool kits?
  2. 2. If answer to 1 is yes, can I just write them into my ``` .profile ```

    or

    .bashrc
    

    or is there another better suited location to hard code it?

  3. 3. For the last command, should is be
    export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\ {LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} in one line or in 2 sentences as shown above
    
  4. 4. Where are this variable stored after the ``` export ```

    command is used? I can see them using e.g. echo $PATH I would like to make corrections using a text editor.

4 Likes
  1. Yes
  2. Yes - some distros automatically set up .bashrc to look for a .bash_aliases if it exists, that might be the best place for it.
  3. the backslash: \ is a “line extender” in bash, which is why it can be on two lines. I would actually suggest:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/lib64

all on one line. If you learn more about bash shell interpreter (plenty of online resources for this) you can understand all the variations here.

  1. exported variables are stored in your “environment” settings - learn more about the bash “environment”. Normally, you would not “edit” such, you would simply reissue with the new settings, which will replace the old definition of it in your “environment”. So this:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/lib64

says, approximately “as the new LD_LIBRARY_PATH variable for my environment, take the existing LD_LIBRARY_PATH variable in my environment, and append to it /usr/local/cuda/lib64”

3 Likes

Dear admin,

Regarding updating the PATH & LD_LIBRARY_PATH,

I notice from many tutorial found on the net, there are two common ways of doing this.

Point 1) First as suggested by mod. Adding the following into the bashrc

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/lib64

Where it is recommended to put the line at the last line of the bashrc

Point 2) Updating the PATH variable to include the CUDA binaries, such that

Using the nano text editor
sudo nano /etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

into

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/cuda-8.0/bin"

I wonder whether, we have to do only

  • Point 1 or Point 2, or
  • both point 1 and Point 2.

This is because, despite having do the following 3 alternatives,

  1. Updating only point 1
  2. Updating only POint 2
  3. Updating both point 1 and Point 2

and then validating the CUDA installation using the command

nvcc --version

I still got the error
nvcc: command not found

I really hope if someone can advice where did I do wrong.

FYI,
The installation is done using the following environment

-Docker with UBUNTU 16.04 as the base image

  • CUDA Version: CUDA 8 > cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb

Thanks in advance for the advice

1 Like

You need to log out and log in again for those changes to take effect.

The requirement for the changes is spelled out in the linux install guide.

[url]Installation Guide Linux :: CUDA Toolkit Documentation