How to Install TensorFlow on CentOS 8

Published on

3 min read

Install TensorFlow on CentOS 8

TensorFlow is an open-source platform for machine learning built by Google. It can runs on CPU or GPU on different devices, and it is used by a number of organizations, including Twitter, PayPal, Intel, Lenovo, and Airbus.

TensorFlow can be installed system-wide, in a Python virtual environment, as a Docker container, or with Anaconda .

This tutorial explains how to install TensorFlow on CentOS 8.

TensorFlow supports both Python 2 and 3. We will be using Python 3 and install TensorFlow inside a virtual environment. A virtual environment allows you to have multiple different isolated Python environments on a single computer and install a specific version of a module on a per-project basis, without worrying that it will affect your other Projects.

Installing TensorFlow on CentOS

Unlike other Linux distributions, Python is not installed by default on CentOS 8. To install Python 3 on CentOS 8 run the following command as root or sudo user in your terminal:

sudo dnf install python3

The command above will install Python 3.6 and pip . To run Python 3, you need to type python3 explicitly, and to run pip type pip3.

Starting from Python 3.6, the recommended way to create a virtual environment is to use the venv module.

Navigate to the directory where you would like to store your TensorFlow project. It can be your home directory or any other directory where the user has read and write permissions.

Create a new directory for the TensorFlow project and switch into it:

mkdir tensorflow_project cd tensorflow_project

Within the directory, run the following command to create the virtual environment:

python3 -m venv venv

The command above creates a directory named venv, containing a copy of the Python binary, pip the standard Python library, and other supporting files. You can use any name you want for the virtual environment.

To start using the virtual environment, activate it by typing:

source venv/bin/activate

Once activated, the virtual environment’s bin directory will be added at the beginning of the $PATH variable . Also, your shell’s prompt will change, and it will show the name of the virtual environment you’re currently using. In this case, that is venv.

TensorFlow installation requires pip version 19 or higher. Run the following command to upgrade pip to the latest version:

pip install --upgrade pip

Now that the virtual environment is created and activated, install the TensorFlow library using the following command:

pip install --upgrade tensorflow

If you have a dedicated NVIDIA GPU and want to take advantage of its processing power, instead of tensorflow, install the tensorflow-gpu package, which includes GPU support.

Within the virtual environment, you can use the command pip instead of pip3 and python instead of python3.

To verify the installation, run the following command, which will print the TensorFlow version:

python -c 'import tensorflow as tf; print(tf.__version__)'

At the time of writing this article, the latest stable version of TensorFlow is 2.1.0:


Your TensorFlow version may differ from the version shown here.

If you are new to TensorFlow, visit the Get Started with TensorFlow page and learn how to build your first ML application. You can also clone the TensorFlow Models or TensorFlow-Examples repositories from Github and explore and test the TensorFlow examples.

Once you are done with your work, deactivate the environment by typing deactivate, and you will return to your normal shell.


That’s it! You have successfully installed TensorFlow, and you can start using it.


We have shown you how to install TensorFlow inside a virtual environment on CentOS 8.

If you hit a problem or have feedback, leave a comment below.