Jul 24, 2023 4 min read

How to Install TensorFlow on Ubuntu 20.04

Install TensorFlow on Ubuntu 20.04 with our step-by-step tutorial. It is used for machine learning and artificial intelligence applications.

Install TensorFlow on Ubuntu 20.04
Table of Contents

Choose a different version or distribution


Before we begin talking about how to install TensorFlow on Ubuntu 20.04. Let’s briefly understand - What is TensorFlow?

TensorFlow is a powerful open-source library widely used for machine learning and artificial intelligence applications. Developed by Google, TensorFlow simplifies the creation and deployment of deep learning models. With its flexible architecture, it allows developers to build and train neural networks efficiently.

By harnessing the potential of distributed computing, TensorFlow enables faster and more accurate data processing. Its user-friendly interface makes it accessible to beginners and experts alike, making it a popular choice in the AI community.

In this tutorial, you will install TensorFlow on Ubuntu 20.04. We will also address a few FAQs on how to install TensorFlow on Ubuntu 20.04.

Advantages of TensorFlow

  1. Powerful: TensorFlow offers a robust and comprehensive framework for building and deploying machine learning models.
  2. Flexibility: Its versatile architecture allows developers to create and train neural networks with ease, adapting to diverse project requirements.
  3. Scalability: TensorFlow leverages distributed computing, enabling efficient processing of large-scale datasets for faster and more accurate results.
  4. Accessibility: With a user-friendly interface, TensorFlow is accessible to both beginners and experts in the field of machine learning.
  5. Community Support: TensorFlow has a thriving community that provides extensive resources, tutorials, and libraries, fostering collaboration and innovation.

Step 1 - Install Python 3 and the venv

1) Ubuntu 20.04 comes by default with Python 3.8. You can verify if Python is installed by using the following command:

python3 -V

The output will be:


Python 3.8.2

2) The best way to create the virtual environment is to use the venv module, which is used in the python3-venv package.

Run the following command to create a virtual environment:

sudo apt install python3-venv python3-dev

If you got an error as you have broken package, fix it using the below command and rerun the above command to install python-venv.

sudo apt --fix-broken install

After installing, you are ready to create a virtual environment for your TensorFlow project.

Step 2 - Create a Virtual Environment

1) Now, start by navigating to the directory where you would like to store your Python 3 virtual environments. It can either be your home directory or any other directory where you have read and write permissions.

2) After that, create a new directory and cd into it using the following command:

mkdir my_tensorflow
cd my_tensorflow

3) Once you are inside the directory. Continue to run the below command. It will create a virtual environment:

python3 -m venv venv
The second venv is the name of the virtual environment that you are creating. You can keep the name based on your choice.

The command which you just used will create a directory as venv. It contains a copy of the Python binary, Pip package manager, standard Python library, and other supporting files.

Now, you need to activate the virtual environment using the below command:

source venv/bin/activate

4) After activation, the virtual environment’s bin directory gets added at the beginning of $PATH variable. Shell’s prompt will change as well and will show the name of the virtual environment you are currently using. Here we have kept it as venv.

5) The TensorFlow installation needs pip version 19 or higher. Run the below command to upgrade pip to the latest version:

pip install --upgrade pip

Step 3 - Install the TensorFlow

1) Now that the virtual environment activation is complete, it is time to install the TensorFlow package using the following command:

pip install --upgrade tensorflow
Note: If you have a dedicated NVIDIA GPU and want to take advantage of its processing power then instead of TensorFlow install the tensorflow-gpu package. It includes GPU support.

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

If you are getting errors  killed while downloading the module, fix it using the below command.

pip install --upgrade tensorflow --no-cache

2) After that, to verify the installation, do it using the below command. It will print the TensorFlow version:

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

3) Here, the latest version of TensorFlow is 2.0.0.



Your TensorFlow version can differ from the version displayed here.

4) If you are new to TensorFlow, then, visit the Get Started with TensorFlow page and learn to build your first ML application.

5) After your work is complete, you may deactivate the virtual environment by typing deactivate and you will return to your normal shell.

FAQs to Install TensorFlow on Ubuntu 20.04

What are the system requirements for installing TensorFlow on Ubuntu 20.04?

TensorFlow requires a 64-bit operating system, Python 3.6-3.9, and a CUDA-enabled GPU for accelerated performance (optional).

Can I install TensorFlow without GPU support?

Yes, you can install TensorFlow without GPU support. It will run on the CPU, but you won't benefit from GPU acceleration.

How do I verify if TensorFlow is installed correctly?

After installation, you can open a Python terminal and import TensorFlow. If there are no errors, TensorFlow is installed correctly.

Are there any additional dependencies required for TensorFlow installation on Ubuntu 20.04?

TensorFlow's installation requires dependencies such as pip, numpy, wheel, and other optional packages depending on your use case.

Can I install multiple versions of TensorFlow on the same Ubuntu 20.04 system?

Yes, you can create separate virtual environments and install different versions of TensorFlow within each environment.

How do I upgrade TensorFlow to the latest version on Ubuntu 20.04?

You can upgrade TensorFlow by running the appropriate upgrade command in your virtual environment, such as pip install --upgrade tensorflow.


We hope this detailed tutorial helped you to install TensorFlow on Ubuntu 20.04.

If you have any queries or doubts, please leave them in the comment below. We'll be happy to address them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.