How to Install TensorFlow GPU on Ubuntu 18.04


TensorFlow is an open-source machine-learning platform. Google designed the software to help researchers, data scientists, and developers simplify the process of implementing machine-learning models.

This end-to-end library for numerical computation can run on multiple CPUs, GPU, as well as mobile operating systems. In this tutorial, learn how install to TensorFlow on Ubuntu 18.04.

tutorial on installing tensorflow on ubuntu system

Note: For CentOS, see our guide on installing TensorFlow on CentOS.


  • An Ubuntu Linux system (16.04 or later)
  • Access to a command line/terminal window (Ctrl+Alt+T)
  • A user account with sudo privileges
  • Pip 19.0 or later

Step 1: Install Required Packages

Before you can install TensorFlow, you’ll need to set up the Python development environment. It includes the following software:

  • Python (version 3.4 or later)
  • the pip package manager (no older than version 19.0)
  • Virtualenv (software for isolating Python environments)

Open the terminal window and start by updating the repository with:

sudo apt update

Next, install the first two packages with the command:

sudo apt install python3-dev python3-pip
screenshot of installing pip and python for tensorflow

Then, run the following command for a wide-system installation of Virtualenv:

sudo pip3 install -U virtualenv
installation of virtualenv on ubuntu 18.04

Step 2: Creating a Virtual Environment

Now that you have Virtualenv on your Ubuntu system, you can use it to create and isolate Python environments.

Create your first enviroment in a new ./venv directory:

virtualenv --system-site-packages -p python3 ./venv
createing a new virtual environment

Then, activate the virtual environment to start working inside it. Run the following command:

source ./venv/bin/activate

Your shell prompt should now have a (venv) prefix as in the image below:

virtual environment acctivated example

Once you activate venv, move on to installing pip inside the isolated environment:

pip install --upgrade pip
installing pip in virtual environment on ubuntu

If you want to see a complete list of all the packages inside the virtual environment, use the command:

pip list

It displays all the packages and their respective versions, as in the following image:

listing packages using pip list

Step 3: Installing TensorFlow

The next step differs depending on whether you are installing TensorFlow for CPU or TensorFlow for GPU. The choice depends on the nature of your workload and hardware options.

Option 1: Install TensorFlow for CPU

The default TensorFlow software package supports CPU-based workloads. To install the package and its dependencies, type the following command:

pip install --upgrade tensorflow

Option 2: Install TensorFlow for GPU

TensorFlow for GPU requires a dedicated NVIDIA CUDA®-enabled GPU and related drivers. This software package is intented for GPU-based machine-learning workloads.

To install the latest stable version of TensorFlow for GPU, run the command:

pip install --upgrade tensorflow-gpu

For a list of hardware and software requirements for TensorFlow for GPU, please refer to TensorFlow’s documentation on GPU support.

Option 3: Installing Old Versions of TensorFlow

Older versions of TensorFlow for CPU and GPU are also available for download.

Version 1.14 and older is installed by running the command in the following format:

pip install tensorflow==package_version

To install TensorFlow for CPU 1.14, run the command:

pip install tensorflow==1.14

To install TensorFlow for GPU 1.14, run the command:

pip install tensorflow-gpu==1.14

Version 1.15 supports both CPU and GPU-based workloads. To install TensorFlow 1.15, type the  command:

pip install tensorflow-gpu==1.15rc2

Step 4: Verifying TensorFlow Installation

To verify the installation of TensorFlow in Ubuntu , enter the command in the terminal window:

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"


This article showed you steps for installing TensorFlow on Ubuntu 18.04. With the desired TensorFlow version (CPU or GPU support) installed on your system, you can now move on to developing your machine-learning models.

Was this article helpful?
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How to Install Keras With TensorFlow Backend on Linux
August 24, 2020

Follow the step by step instructions to learn how to prepare your system for the installation of Keras and...
Read more
How to Install and Use TensorFlow on CentOS 7
October 8, 2019

TensorFlow is Google's open-source platform for machine learning. It was designed to simplify the process of...
Read more
What is Server Virtualization? Definition and How it Works
February 24, 2019

A virtualized server allows one piece of hardware to be used as multiple virtual servers. Learn about Server...
Read more
How to Install NVIDIA Tesla Drivers on Linux or Windows
September 7, 2018

Growing demands for extreme computing power have lead to the unavoidable presence of bare metal servers...
Read more
  • © 2022 Copyright phoenixNAP | Global IT Services. All Rights Reserved.