Skip to content

Instantly share code, notes, and snippets.

@vbalnt
Last active March 29, 2021 09:58
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save vbalnt/a0f789d788a99bfb62b61cb809246d64 to your computer and use it in GitHub Desktop.
Save vbalnt/a0f789d788a99bfb62b61cb809246d64 to your computer and use it in GitHub Desktop.
Installation of CUDA & Tensorflow in Ubuntu 14.04 or 16.04

This document describes how to install the combination of 14.04 + CUDA 7.5 + Tensorflow. This combination is the easiest to install without anything like compilation from sources etc.

Download and install Ubuntu 14.04 or 16.04

http://releases.ubuntu.com/14.04/ http://releases.ubuntu.com/16.04/

Install CUDA 8

This way below installs CUDA and all the related things (e.g. drivers needed).

After download is over, open a terminal and navigate to Downloads.

sudo dpkg -i cuda-repo-ubuntu1404-8-0-local_8.0.44-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda

the dpkg -i cuda-repo-ubuntu1404-8-0-local_8.0.44-1_amd64.deb might differ (check the download name - or use tab for autocomplete)

Restart the PC to activate CUDA + the new drivers.

Install CUDNN 5.1

CUDNN makes CNNs faster with some convolutional and other optimizations.

Navigate to https://developer.nvidia.com/cudnn and register for an account (it's free). After you make your account, login and go to downloads.

Choose the following Download cuDNN v5.1 (August 10, 2016), for CUDA 8 cuDNN v5.1 Library for Linux

after it is downloaded navigate to Downloads and extract the tar file. You will get a folder called cuda. Open a terminal and run the following to navigate to this folder and put the cudnn files to your system folders.

cd ~/Downloads/cuda
sudo cp lib64/* /usr/local/cuda/lib64/
sudo cp include/cudnn.h /usr/local/cuda/include/

Update your .bashrc

Open .bashrc from your home folder with an editor (the dot indicates that it is a hidden file). a way to do this for example is

gedit ~/.bashrc

Add the following lines to the end of the file.

# add cuda tools to command path
export PATH=/usr/local/cuda/bin:${PATH}
export MANPATH=/usr/local/cuda/man:${MANPATH}

# add cuda libraries to library path
if [[ "${LD_LIBRARY_PATH}" != "" ]]
then
  export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}
else
  export LD_LIBRARY_PATH=/usr/local/cuda/lib64
fi

Install tensorflow

Open a terminal and write

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0rc2-cp27-none-linux_x86_64.whl
sudo pip install --upgrade $TF_BINARY_URL

Enjoy your new gpu-enabled deep learning setup :)

@themmer
Copy link

themmer commented Nov 30, 2017

For some reason there was not ubuntu 14.x version in the cuda downloads link on the nvidia site. I did find it in the archive here though: LINK

@Stopforth
Copy link

Thanks a bunch

@ashish-farande
Copy link

Thank you

@ashish-farande
Copy link

Can you help with installing tensorflow 0.11 for python3.

@monogenea
Copy link

Worked with tensorflow 1.12.0 on my Ubuntu 14.04! @vbalnt you are the man

#### Install CUDA 8 ####
# Go to https://developer.nvidia.com/cuda-downloads, Linux -> x86_64 -> Ubuntu -> 14.04 or 16.04 -> deb (local)
# After download, cd Downloads

sudo dpkg -i cuda-repo-ubuntu1404-8-0-local_8.0.44-1_amd64.deb # Whatever the .deb name might be
sudo apt-get update
sudo apt-get install cuda

# restart PC

#### Install CUDNN 5.1 ####
# Follow https://developer.nvidia.com/cudnn, register and hit Downloads
# Choose Download cuDNN v5.1 (August 10, 2016), for CUDA 8, then cuDNN v5.1 Library for Linux

cd ~/Downloads/cuda
sudo cp lib64/* /usr/local/cuda/lib64/
sudo cp include/cudnn.h /usr/local/cuda/include/

# Update .bashrc

nano ~/.bashrc

# Add following lines

# add cuda tools to command path
export PATH=/usr/local/cuda/bin:${PATH}
export MANPATH=/usr/local/cuda/man:${MANPATH}

# add cuda libraries to library path
if [[ "${LD_LIBRARY_PATH}" != "" ]]
then
  export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}
else
  export LD_LIBRARY_PATH=/usr/local/cuda/lib64
fi

#### Install TF ####
# I recommend using a conda env
conda create -n tensorflow_gpu python==3.6
conda activate tensorflow_gpu
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp36-cp36m-linux_x86_64.whl
python3.6 -m pip install --upgrade $TF_BINARY_URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment