3

Is it possible to install CUDA to a directory other than /usr/local/? I have very limited space on my drive. I'm using this answer to install it currently.

I'm using it for TensorFlow.

Abhishek Divekar
  • 714
  • 1
  • 7
  • 17

3 Answers3

3

The following worked when installing CUDA 8.0 on Ubuntu 16.04.

Download the (local) .run file from the CUDA downloads page.

Consulting NVIDIA's CUDA Installation Guide page 34 (PDF page 38):

The Runfile installation asks where you wish to install the Toolkit and the 
Samples during an interactive install. If installing using a non-interactive 
install, you can use the --toolkitpath and --samplespath parameters to 
change the install location:
$ ./runfile.run --silent \
  --toolkit --toolkitpath=/my/new/toolkit \
  --samples --samplespath=/my/new/samples

Where /my/new/ is your new CUDA install directory (on a partition with sufficient space). Previously, it was installed to /usr/local/cuda/ or /usr/local/cuda-x.x.

The folders /my/new/toolkit and /my/new/samples are created automatically.

Also, I found it useful to use the --tmpdir=/some/path/ flag, which sets which directory to temporarily store the files. Use a directory in a partition with a lot of space.

So finally, the command becomes:

$ ./runfile.run --silent --toolkit --toolkitpath=/my/new/toolkit --samples --samplespath=/my/new/samples --tmpdir=/my/new/

You can run the above with the --help flag or consult the CUDA Linux docs to see all installation possibilities.

After this, it is necessary to redirect the PATH and LD_LIBRARY_PATH variables. Add the following lines to the bottom of your .bashrc file (which is in your home directory):

export PATH=/my/new/toolkit/bin/:$PATH
export LD_LIBRARY_PATH=/my/new/toolkit/lib64/:$LD_LIBRARY_PATH

You must then run source /home/username/.bashrc to run the file and load the environment variables.

Run nvcc --version to confirm that CUDA is installed. Get the version with cat /my/new/toolkit/version.txt.

See this answer for more help.

Additional help to install TensorFlow with Anaconda:

This part was specific to my use-case, but to install TensorFlow with Anaconda after installing CUDA, run conda install -c jjhelmus tensorflow-gpu (from here. The Anaconda one doesn't seem to work).

Abhishek Divekar
  • 714
  • 1
  • 7
  • 17
  • Specifying the local directory for --tmpdir saved me from getting Disk space error, which had frustrated me for a while. I had used local directories for other two options and I kept on getting the space error. – Riyaz Jul 14 '20 at 04:24
2

Refer the NVIDIA's CUDA Installation Guide page 32/33(_according to PDF reader page 36/37) for more details on how to install at the custom location for the CUDA libaries, and also what environment variables to set to make it work.

Update:
As per the documentation:

Runfile
The Runfile can be extracted into the standalone Toolkit, Samples and Driver Runfiles by using the --extract parameter. The Toolkit and Samples standalone Runfiles can be further extracted by running:

$ ./runfile.run --tar mxvf

The Driver Runfile can be extracted by running:

$ ./runfile.run -x

...
For debian systems:

$ dpkg-deb -x  package.deb output_dir
# Where package.deb is the downloaded debian package for cuda 
# and output_dir is the directory where you want to extract the files.

Update 2:

As commented by the OP the installation guide page 34 ( PDF Reader Page 38) contains the necessary steps/references posted below for reference here:

How do I install the Toolkit in a different location?

The Runfile installation asks where you wish to install the Toolkit and the 
Samples during an interactive install. If installing using a non-interactive 
install, you can use the --toolkitpath and --samplespath parameters to 
change the install location:
$ ./runfile.run --silent \
  --toolkit --toolkitpath=/my/new/toolkit \
  --samples --samplespath=/my/new/samples


The RPM and Deb packages cannot be installed to a custom install location 
directly using the package managers. See the "Install CUDA to a specific 
directory using the Package Manager installation method" scenario in the 
Advanced Setup section for more information.
AmeyaVS
  • 536
  • Do you mind summarizing the instructions (as is standard for AskUbuntu incase the link goes dead). – Abhishek Divekar Aug 03 '17 at 16:13
  • 1
    Actually a possibly better answer is on page 34 of the same pdf: once you have the runfile, use$ ./runfile.run --silent \ --toolkit --toolkitpath=/my/new/toolkit \ --samples --samplespath=/my/new/samples. – Abhishek Divekar Aug 03 '17 at 16:34
0

In my case I required a custom location for all like toolkit, samples, librray. So instead of setting all separately I used --installpath=<path> which I got to know about by running ./cuda-installer.run --help

I was installing cuda 10.2 linux toolkit

Yug Singh
  • 103