15

Installing the CUDA toolkit results in the following instructions being printed to the console.

Please make sure your LD_LIBRARY_PATH for 64-bit Linux distributions includes /usr/local/cuda-5.0/lib64:/usr/local/cuda-5.0/lib

OR

for 64-bit Linux distributions add /usr/local/cuda-5.0/lib64 and /usr/local/cuda-5.0/lib to /etc/ld.so.conf and run ldconfig as root

The following code in /etc/profile had no effect.

if [ -z "$LD_LIBRARY_PATH" ]; then    
  LD_LIBRARY_PATH=/usr/local/cuda-5.0/lib64:/usr/local/cuda-5.0/lib
else
  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-5.0/lib64:/usr/local/cuda-5.0/lib
fi
export LD_LIBRARY_PATH

That is, rebooting and issuing echo $LD_LIBRARY_PATH showed the variable was not defined.

To try the alternative suggestion, I added the two lines to the file /etc/ld.so.conf so my file looks like this

include /etc/ld.so.conf.d/*.conf 
/usr/local/cuda-5.0/lib64
/usr/local/cuda-5.0/lib

Then I issued:

sudo ldconfig

then

echo $LD_LIBRARY_PATH

Still the environment variable was not set. How do I comply with the CUDA installation instructions shown above?

1
  • 1
    ldconfig doesn't set LD_LIBRARY_PATH, it includes libraries in a different way. Apr 7, 2013 at 12:47

2 Answers 2

20

Add a file with the .conf extension to /etc/ld.so.conf.d/ that contains the paths to the libraries and then run ldconfig. Be sure to set the permissions and ownership of the file to match the other files in the directory.

This is a system wide solution as opposed to the user specific solution of modifying .bashrc.

On my system I made nvidia.conf in /etc/ld.so.conf.d/. The file contains the lines:

/usr/local/cuda-5.0/lib64
/usr/local/cuda-5.0/lib

If you create the file as sudo then your permissions should be good to go, but my nvidia.conf is owner/group root and rw-r--r-- (or 644).

4
  • 1
    This doesn't seem to work. ldconfig doesn't set the $LD_LIBRARY_PATH.
    – Nick
    Nov 30, 2015 at 12:31
  • 2
    My understanding is that it fixes the problem in such a way that you do not need to set the path variable. So if "doesn't work" means the variable isn't set, then sure. If "doesn't work" means CUDA isn't working, then more information on your problem is needed as this enabled (and continues to enable) CUDA development on my setup. Nov 30, 2015 at 15:51
  • I'm sure it works for some things, the program I was trying to compile wants to use the $LD_LIBRARY_PATH, which is probably not best practise, it means I need to set it!
    – Nick
    Nov 30, 2015 at 16:54
  • in my case on Ubuntu 22.04 with cuda 12.1 this worked just replace 5.0 with 12.1 May 4, 2023 at 5:06
14

Put the following in .bashrc.

if [ -z $LD_LIBRARY_PATH ]; then
  LD_LIBRARY_PATH=/usr/local/cuda-5.0/lib64:/usr/local/cuda-5.0/lib
else
  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-5.0/lib64:/usr/local/cuda-5.0/lib
fi
export LD_LIBRARY_PATH
1
  • 1
    I think the preferred method is to create a .conf file. I described this in my answer below. Apr 7, 2013 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .