Install TensorFlow GPU and its component on Ubuntu 16.04 (TensorFlow 1.8 with CUDA 9.2) - Part 1
- Khoa Nguyen
- Jul 21, 2018
- 3 min read
This guide explains how to install TensorFlow on Ubuntu. Although these instructions might also work on other Linux variants, I have only tested these instructions on machines meeting the following requirements:
- 64-bit desktops or laptops
- Ubuntu 16.04 (Haven't tested on newer version 17.04 or 17.10 yet)
Here, I installed with Virtualenv. It is a virtual Python environment isolated from other Python developments and incapable of interfering with or being affected by other Python programs on the same machine.
Open Terminal using shortcut: Ctrl + Alt + T
First thing first, let make sure that the system is up-to-date.
Verify You Have a CUDA-Capable GPU:
If your graphic card is NVIDIA, go to https://developer.nvidia.com/cuda-gpus to verify if it is listed in CUDA-capable lists.
If you see nothing, it means that your GPU isn't CUDA-capable.
3. Install all the dependencies:
Some of the dependencies might have been installed in your machine already, if that is the case, ignore it and continue to install the next one.
4. Install Python 2 and 3 header files so we can compile OpenCV and Python bindings.
5. Install Linux kernel header:
**Check your Linux kernel version first by typing "uname -r" into the Terminal. Then type the line below to install Linux kernel header:
6. Install CUDA (this step is extremely important, so please read carefully)
If you have previous version of CUDA, uninstall it first:
This command works for all versions of CUDA
Now you can freely install CUDA:
7. Reboot your system to load the newly installed NVIDIA drivers
8. Open Terminal again as we are not done yet (yike!):
Check your NVIDIA drivers, it should be the latest version: 396.26
9. Install CuDNN (CUDA Deep Learning Neural Network Library)
This step is a little bit tricky, because you will need to have a NVIDIA developers account to access the CuDNN downloads sections. I will show you how:
a. Go to https://developer.nvidia.com/developer-program to create a free account:

b. Go to https://developer.nvidia.com/cudnn to download CuDNN package, the name of the compatible package should be "cuDNN v7.1.4 Library for Linux."
c. Open the Download folder, right click, choose "Open in Terminal," and type the following:
10. Install more Dependencies:
libcupti:
For Python 2.7:
For Python 3.x:
11. Prepare for the Python Virtual Environment:
Install pip:
I'm using virtual environment because:
If you do multiple projects, it will allow isolate packages from different projects
You can install different versions of packages depend on each projects
For example, it will solve the problem "Project 1 need package N on version 1.x, but project 2 need N on version 3.x"
Enough talk, let's install virtualenv and virtualenvwrapper:
Once we have virtualenv and virtualenvwrapper installed, we need to update our ~/.bashrc file to include the following lines at the bottom of the file:
Reload the file:
12. Create the Python Virtual Environment using mkvirtualenv:
You can name your virtual environment whatever you want, but here I will choose "khoadl" and use it throughout the tutorial.
**To make sure that you are in the "khoadl" virtual environment everytime you code, you will need to use "workon khoadl" whenever you reboot Ubuntu or close Terminal.
This command will allow you to access your virtual environment.
Since the tutorial is long, I decided to split it into a 2-parts series.
This will be the end of part 1 of the tutorial. Click here to go to part 2.






Comments