Installing CUDA has gotten a lot easier over the years thanks to the CUDA Installation Guide, but there are still a few potential pitfalls to be avoided. Below is a working recipe for installing the CUDA 9 Toolkit and CuDNN 7 (the versions currently supported by TensorFlow) on Ubuntu 18.04.
