Skip to content

Instantly share code, notes, and snippets.

@mveeneman mveeneman/
Last active Mar 25, 2019

What would you like to do?
Quick install Cuda 10.0 and Tensorflow on Ubuntu 18.04
title author date output
Install for Cuda 10.0 Tensorflow on Ubuntu 18.04
Mourad Veeneman
November 26, 2018

Install for Cuda 10.0 Tensorflow on Ubuntu 18.04

This will show you how to install tensorflow with NVIDIA's Cuda 10.0 GPU environment on Ubuntu 18.04. It will install all required packages and then compile Tensorflow from source. Note that building tensorflow from source is a lenghty process and can take up to 60 minutes depending on the speed of your machine.

These steps also work with a completely fresh Ubuntu 18.04 install.

Installing NVIDIA video driver and Cuda 10.0

Always first update to the latest versions of your packages:

sudo apt update
sudo apt upgrade

First uninstall Nouveau video driver:

Create a blacklist configuration file with:

sudo nano /etc/modprobe.d/blacklist-nouveau.conf

with the following contents:

blacklist nouveau
options nouveau modeset=0

Regenerate the kernel with initramfs:

sudo update-initramfs -u

and finally reboot machine:

sudo reboot

Don't worry, since you have now disabled the video driver the the login screen will be low resolution VGA. This will get fixed in the next section after you've rebooted at the end.

Installing Cuda from NVIDIA repo

The quickest way to install all nvidia software is from the NVIDIA repo:

sudo apt-key adv --fetch-keys
sudo bash -c 'echo "deb /" > /etc/apt/sources.list.d/cuda.list'
sudo apt update
sudo apt install nvidia-driver-410
sudo apt install cuda-10-0
echo "/usr/local/cuda/lib64" | sudo tee -a /etc/
echo "/usr/local/cuda-10.0/extras/CUPTI/lib64" | sudo tee -a /etc/
sudo ldconfig

reboot the machine. The machine will come online using the NVIDIA video driver.

Installing CuDNN 7.4.1

To download this library, you will need to have a registered NVIDIA developer account. Login with your credentials on, find CuDnn and download these packages:

sudo dpkg -i libcudnn7_7.4.1.5-1+cuda10.0_amd64.deb
sudo dpkg -i libcudnn7-dev_7.4.1.5-1+cuda10.0_amd64.deb
sudo dpkg -i libcudnn7-doc_7.4.1.5-1+cuda10.0_amd64.deb

Building Tensorflow from source

Installing Bazel before compiling Tensorflow

To build Tensorflow you will first need Bazel. The easiest way to install, is to add the Bazel repo and install the package.

sudo apt --yes install curl
# echo "deb [arch=amd64] stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
# curl | sudo apt-key add -
# sudo apt --yes update
# sudo apt --yes install bazel
# --Removed because of issues with bazel 0.19/0.20
curl -O
sudo dpkg -i bazel_0.18.0_amd64.deb

Configuring and compiling Tensorflow

Building Tensorflow from source is very well explained on the Tensorflow website. Here are the steps:

sudo apt install python-dev python-pip
sudo -H pip install -U pip six numpy wheel mock
sudo -H pip install -U keras_applications==1.0.5 --no-deps
sudo -H pip install -U keras_preprocessing==1.0.3 --no-deps
sudo apt --yes install git
git clone
cd tensorflow

Don't forget to type Y for for Cuda, Cuda version 10.0 and CuDNN version 7.4.1 and CuDNN library location /usr/lib. For all others you can leave the default values.

Building Tensorflow from source will take a while, so prepare for a long build process.

bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

Once you have built Tensorflow, you will need to build the Python package and install it:

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo -H pip install /tmp/tensorflow_pkg/tensorflow-<version-tags>.whl

All done!

Please help improve this document by reporting any issues.

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.