Install CUDA to different directory in 16.04
Solution 1
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.
Solution 2
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
ML Scientist at Amazon Machine Learning. Working on research problems in Natural Language Processing and AutoML. Part-time student at UTexas Austin MSCS Linkedin: https://www.linkedin.com/in/ardivekar/
Updated on September 18, 2022Comments
-
Abhishek Divekar over 1 year
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.
-
AmeyaVS over 6 yearsCan you update the question with the method you are installing the cuda libraries or a link to the installation guide?
-
Abhishek Divekar over 6 years@AmeyaVS: Done.
-
-
Abhishek Divekar over 6 yearsDo you mind summarizing the instructions (as is standard for AskUbuntu incase the link goes dead).
-
Abhishek Divekar over 6 yearsActually 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
. -
Riyaz almost 4 yearsSpecifying 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.