Published in


Installing Tensorflow GPU on Ubuntu 20.04, This Is the Way

This guide is the best way to install Tensorflow GPU when other methods are not successful on my Ubuntu 20.04 machine.

  1. Removing the old package.
sudo apt-get clean
sudo apt-get update
sudo apt-get purge cuda
sudo apt-get purge nvidia-*
sudo apt-get autoremove

2. Install Nvidia package repositories

wget mv /etc/apt/preferences.d/cuda-repository-pin-600sudo apt-key adv --fetch-keys add-apt-repository "deb /"sudo apt-get update

3. Install Nvidia cudnn package repositories


sudo apt install ./nvidia-machine-learning-repo-ubuntu2004_1.0.0-1_amd64.deb
sudo apt-get update

4. Install Nvidia cuda and cudnn

sudo apt-get install cuda-11-2 nvidia-cuda-toolkit libcudnn8 libcudnn8-devsudo reboot # Reboot your machine

5. Install the Tensorflow on the system Python3.8 from Ubuntu

sudo apt install python3 python3-pipsudo pip3 install tensorflow

6. Test in Python

python3 -c 'import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices("GPU")))'

The result should be like this:

If found error “Failed to call ThenRnnBackward with model config” use this code to allow memory growth.

gpu_devices = tf.config.experimental.list_physical_devices('GPU')
for device in gpu_devices:
tf.config.experimental.set_memory_growth(device, True)




Handcrafted Software and Innovation.

Recommended from Medium

My First Experience as a Lecturer

Machine Learning Models

Finding image pathways

History of the Neural Networks — Part 2

Remove 1 or multiple Column in Pytorch Tensor

Image Captioning With Flickr8k Dataset & BLEU

LSTM-FCN for cardiology

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Programmer • Innovator • Photographer

More from Medium

Nexus: Using Machine Learning to Label Abstract Art

Recognize Volleyball Game Stages with Machine Learning

I Walk so Randomly on the Boulevard of Broken Links: Random Walks and Node Embeddings

Intelligent automation: when RPA meets AI

Intelligent automation masterclass