TensorFlow, developed by Google, is a powerful open-source platform for machine learning and artificial intelligence. It’s used by researchers and developers worldwide to build and deploy machine learning models. Whether you’re working on a small hobby project or a large-scale application, TensorFlow provides the tools you need.

In this article, we’ll walk you through each step of the installation process of TensorFlow on Ubuntu 22.04.

Step 1 – Update and Upgrade Your System

Before anything else, let’s ensure your system is up to date. Open your terminal and run the following commands:

apt update -y 
apt upgrade -y

Updating your system is crucial as it ensures you have the latest security patches and features, setting a strong foundation for TensorFlow installation.

Step 2 – Install Python

Next, you’ll need Python, which is essential for running TensorFlow. To install Python, enter the command:

apt install python3 -y

You can verify the installation by checking the version:

python3 --version

You should see an output like Python 3.10.12. Great, Python is installed!


Python 3.10.12

Step 3 – Install Pip, Virtual Environment, and Development Tools

To manage your Python packages, you’ll need Pip. Also, creating a virtual environment is a good practice to keep your TensorFlow installation isolated. Install Pip, the virtual environment module, and development tools with:

apt install python3-pip python3-venv python3-dev -y

Step 4 – Set Up Your Project Directory

Next, create a directory for your project and navigate to the directory:

mkdir project  
cd project

Now you’re in your project directory. Perfect!

Step 5 – Create and Activate a Virtual Environment

Creating a virtual environment is crucial to avoid conflicts with other Python packages. Create one with the following command:

python3 -m venv venv

Activate the virtual environment:

source venv/bin/activate

You’ll notice your terminal prompt changes, indicating the virtual environment is active.

Step 6 – Install TensorFlow

With the virtual environment activated, you can now install TensorFlow. Use Pip to install the latest version:

pip3 install --upgrade TensorFlow

TensorFlow will be downloaded and installed in your virtual environment. This might take a few minutes, so grab a coffee while you wait!

Step 7 – Verify the Installation

To ensure TensorFlow is installed correctly, you can check the installation details. Run:

python3 -m pip show TensorFlow

You should see an output similar to this:

Name: tensorflow
Version: 2.16.1
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /root/project/venv/lib/python3.10/site-packages
Requires: absl-py, astunparse, flatbuffers, gast, google-pasta, grpcio, h5py, keras, libclang, ml-dtypes, numpy, opt-einsum, packaging, protobuf, requests, setuptools, six, tensorboard, tensorflow-io-gcs-filesystem, termcolor, typing-extensions, wrapt
Required-by: 

This confirms that TensorFlow is installed and ready to use.

Once you’re done, you can deactivate the virtual environment by simply running:


deactivate

This will return your terminal to its normal state.

Conclusion

In this article, we’ve walked through the steps to install TensorFlow on Ubuntu 22.04. We started by updating and upgrading the system, then installed Python and Pip. We set up a project directory, created a virtual environment, and installed TensorFlow. Finally, we verified the installation and deactivated the virtual environment. Try to install TensorFlow on dedicated server hosting from Atlantic.Net!