• Wayne Cheng

Setting Up a New Ubuntu Linux Installation to Run Keras and Tensorflow on the GPU

Updated: Jan 21

Do you have a new Ubuntu installation, and you want to get Keras and Tensorflow running on your GPU? This guide describes the process of setting up my new Ubuntu 18.04 installation.

Keras and Tensorflow can be installed with either the Pip or Conda (Anaconda) package managers. Conda is the better choice because it is better at resolving dependency issues that can occur when installing a new package.

Step 1 : Install Anaconda

It’s necessary to use the terminal in Ubuntu to install the packages. The terminal in Ubuntu can be accessed in various ways as described here.

Using these instructions, I was able to install Anaconda with the following steps :

First, I installed the prerequisite packages by typing the following into the terminal :

apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6

Then I downloaded Anaconda to my Downloads folder.

After finishing the download, I checked the integrity of the installer by typing the following into the terminal :

sha256sum ~/Downloads/Anaconda3-2019.10-Linux-x86_64.sh

The hash key should match the key found on this page, or :


Once I confirmed that the hash key matched, I installed Anaconda by typing the following into the terminal :

bash ~/Downloads/Anaconda3-2019.10-Linux-x86_64.sh

When prompted by the installer, I chose the recommended choices (accept the default install location, initialize Anaconda3 by running conda init). After the Anaconda installation finished, I refreshed my terminal environment by typing the following into the terminal :

source ~/.bashrc

Step 2 : Install Tensorflow and Keras

First, I installed Tensorflow with Conda, by typing the following into the terminal :

conda install -c anaconda tensorflow-gpu

Once the Tensorflow installation finished, I then installed Keras by typing the following into the terminal :

conda install -c conda-forge keras

Note : some tutorials recommend using “conda install -c anaconda keras-gpu” instead of the two commands listed above, but this command installs an older version of Keras.

Step 3 : Check Installation of Tensorflow and Detection of GPU

To check whether Tensorflow was installed correctly, I first entered the Python shell by typing the following into the terminal :


Then I typed the following into the Python shell :

import tensorflow as tf

There were no errors, which means that I installed Tensorflow correctly. Then I typed the following into the Python shell :


I was able to see my GPU, and the Cuda libraries were successfully opened :

...gpu_device.cc:1618] Found device 0 with properties: name: GeForce RTX 2080 ... ...dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0 ...dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0 ...dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0 ...dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10.0 ...dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10.0 ...dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10.0 ...dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7

And that’s it! Thanks to Anaconda, it's very easy to install the Keras and Tensforflow packages to run on the GPU.

Thank you for reading. I hope you find this guide helpful for installing Keras and Tensorflow on your new Ubuntu installation.

Questions or comments? You can reach me at info@audoir.com

Wayne Cheng is an A.I., machine learning, and deep learning developer at Audoir, LLC. His research involves the use of artificial neural networks to create music. Prior to starting Audoir, LLC, he worked as an engineer in various Silicon Valley startups. He has an M.S.E.E. degree from UC Davis, and a Music Technology degree from Foothill College.

Copyright © 2020 Audoir, LLC

All rights reserved