Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install CUDA Toolkit v8.0 and cuDNN v6.0 on Ubuntu 16.04
#!/bin/bash
# install CUDA Toolkit v8.0
# instructions from https://developer.nvidia.com/cuda-downloads (linux -> x86_64 -> Ubuntu -> 16.04 -> deb (network))
CUDA_REPO_PKG="cuda-repo-ubuntu1604_8.0.61-1_amd64.deb"
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/${CUDA_REPO_PKG}
sudo dpkg -i ${CUDA_REPO_PKG}
sudo apt-get update
sudo apt-get -y install cuda
# install cuDNN v6.0
CUDNN_TAR_FILE="cudnn-8.0-linux-x64-v6.0.tgz"
wget http://developer.download.nvidia.com/compute/redist/cudnn/v6.0/${CUDNN_TAR_FILE}
tar -xzvf ${CUDNN_TAR_FILE}
sudo cp -P cuda/include/cudnn.h /usr/local/cuda-8.0/include
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64/
sudo chmod a+r /usr/local/cuda-8.0/lib64/libcudnn*
# set environment 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}}
@ytakashina

This comment has been minimized.

Copy link

ytakashina commented Jun 3, 2017

I found the following line contains an unnecessary backslash, which causes errors on some libraries. (e.g., tensorflow)

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
@AashishV

This comment has been minimized.

Copy link

AashishV commented Jun 7, 2017

@y-takashina Do you know what is correct path? Because I am also getting the errors in tensorflow

@ytakashina

This comment has been minimized.

Copy link

ytakashina commented Jun 8, 2017

@AashishV
Removing the backslash worked for me.
You can confirm your operating system recognizes the correct path by checking $LD_LIBRARY_PATH.

$ echo $LD_LIBRARY_PATH
/usr/local/cuda-8.0/lib64
@clintonyeb

This comment has been minimized.

Copy link

clintonyeb commented Aug 22, 2017

The backslash is used in the documentation to show continuation of the command

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib\
                         ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

is same as this on the same line without the backslash:

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
@luizhenriquesoares

This comment has been minimized.

Copy link

luizhenriquesoares commented Oct 3, 2017

@luizhenriquesoares

This comment has been minimized.

@Ricocotam

This comment has been minimized.

Copy link

Ricocotam commented Oct 29, 2017

Now Cuda 9.0 is installed, you have to specify the version to apt. If you don't, cuda9 is installed :

sudo apt-get install cuda-8-0

I get it from here.

@kenshiro-o

This comment has been minimized.

Copy link

kenshiro-o commented Nov 5, 2017

Thanks for the gist! Definitely saved my Tensorflow life today...
My paths were already well set but after I tried to echo your suggested LD_LIBRARY_PATH, I realised I had extra }} in it (maybe caused by the backwards slash?). Just using the following should suffice:

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
@EICT321

This comment has been minimized.

Copy link

EICT321 commented Nov 6, 2017

i have installed cuda 9.0 and operating system is centos 7. I just want to know which version of tensor flow will support cuda 9 and centos 7. Also please let me know which version of cudnn should I install?

@Mahedi-61

This comment has been minimized.

Copy link

Mahedi-61 commented Nov 30, 2017

At last i found a resource that really works. Thanks for this. Please remove the unnecessary backslash from last line.

@washcycle

This comment has been minimized.

Copy link

washcycle commented Dec 6, 2017

@EICT321 You might be moving too fast... it might work, but I don't think they official support 9 yet. https://www.tensorflow.org/install/install_sources list tensorflow versions and their tested configurations.

@kitovyj

This comment has been minimized.

Copy link

kitovyj commented Dec 26, 2017

Cuda 9.0 is installed instead of 8.0

@blaine12100

This comment has been minimized.

Copy link

blaine12100 commented Jan 2, 2018

I have tried to add the LD_LIBRARY_PATH as instructed and i am still getting the 'libcudnn.so.6: cannot open shared object file: No such file or directory' error.This is a screenshot of my ~./bashrc file and Nvidia-smi screenshot.

Do let me know if there is anything else i need to try.
screenshot from 2018-01-02 21-06-00
bashrc screenshot

@srhrshr

This comment has been minimized.

Copy link

srhrshr commented Jan 11, 2018

In case running nvidia-smi throws the following error, just try rebooting. That seemed to work for me.
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running

This script works by the way! Ubuntu 16.04.3 represent here. I successfully installed Cuda 8.0 and cuDNN 6.0, without running into any problems with the display/graphics like I usually used to. I highly recommend using the package manager installation over the runfile method.

Thanks!

@wyfSunflower

This comment has been minimized.

Copy link

wyfSunflower commented Jan 12, 2018

This script is not suitable for default graphic card is not nvidia card, such as " dell precision tower 7910", after I run this script and reboot ubuntu, system could not login. And now tensorflow can only support cuda8, but this script will install cuda9.1

@pbertsch

This comment has been minimized.

Copy link

pbertsch commented Feb 25, 2018

For Ubuntu 16.04 users only:

change the the following line in the script
sudo apt-get -y install cuda to sudo apt-get -y install cuda-8-0

@JohnAllen

This comment has been minimized.

Copy link

JohnAllen commented Jan 30, 2019

GPU TensorFlow now requires cudnn 9.0. Anyone have an updated link for 9.0?

@anujonthemove

This comment has been minimized.

Copy link

anujonthemove commented Feb 13, 2019

If you are still facing installation issues, try out this guide: https://medium.com/@anujonthemove/deep-learning-environment-setup-on-ubuntu-16-04-83078e1cba1f

@prameshbajra

This comment has been minimized.

Copy link

prameshbajra commented Apr 3, 2019

GPU TensorFlow now requires cudnn 9.0. Anyone have an updated link for 9.0?

@JohnAllen Did you find a updated script for GPU tensorflow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.