Open a terminal by pressing Ctrl + Alt + T
Copy all lines per codeblock and paste lines into terminal using Shift + Ctrl + V

To begin you must have the 384 (or later) NVidia drivers installed, this can easily be done from Ubuntu’s built in additional drivers (press windows key and search additional drivers) after you update your driver packages via:

sudo add-apt-repository ppa:graphics-drivers/ppa && \
sudo apt update 

Once installed using additional drivers restart your computer. If you experience any troubles booting linux or logging in: try disabling fast & safe boot in your bios and modifying your grub boot options to enable nomodeset.

To install the nVidia Toolkit download base installation .run file from nVidia website. I prefer to use the .run file over the deb file because it will not override your current nVidia drivers.

# For version 9.1

cd ~/Downloads && \
wget https://developer.nvidia.com/compute/cuda/9.1/Prod/local_installers/cuda-repo-ubuntu1604-9-1-local_9.1.85-1_amd64 && \
sudo dpkg -i cuda-repo-ubuntu1604-9-1-local_9.1.85-1_amd64.deb && \
sudo apt-key add /var/cuda-repo-9-1-local/7fa2af80.pub && \
sudo apt-get update && \
sudo apt-get install cuda


# Or if you prefer the latest 9.2

cd ~/Downloads && \
wget https://developer.nvidia.com/compute/cuda/9.2/Prod/local_installers/cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64 && \
sudo dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb && \
sudo apt-key add /var/cuda-repo-9.2-local/7fa2af80.pub && \
sudo apt-get update && \
sudo apt-get install cuda

This will install cuda into: /usr/local/cuda

To install CudNN download cuDNN v7.13 Library for Linux for Cuda 9.0 from nVidia website and extract into /usr/local/cuda via:

For version 9.1

tar -xzvf cudnn-9.1-linux-x64-v7.1.tgz && \
sudo cp cuda/include/cudnn.h /usr/local/cuda/include && \
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 && \
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* && \
sudo ln -s /usr/local/cuda/lib64/* /usr/lib

# Or if you prefer the latest 9.2

tar -xzvf cudnn-9.2-linux-x64-v7.1.tgz && \
sudo cp cuda/include/cudnn.h /usr/local/cuda/include && \
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 && \
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* && \
sudo ln -s /usr/local/cuda/lib64/* /usr/lib

Then update your bash file:

echo $'export CUDA_HOME=/usr/local/cuda\nexport LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"\nexport PATH=$PATH:/usr/local/cuda/bin' >> ~/.bashrc

To update your terminal type this command to reload your .bashrc file, or easier yet just close your terminal and open a new one.

source ~/.bashrc

You should now have the Cuda Toolkit installed, next you can install GPU supported TensorFlow.