In this article, we will have explained the necessary steps to install and configure TensorFlow on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo
privileges. All the commands in this tutorial should be run as a non-root user.
TensorFlow™ is an open-source Machine Learning framework released by Google. From its official site, TensorFlow™ is an open-source software library for high-performance numerical computation, which allows easy deployment of computation across a variety of platforms (CPUs, GPUs, TPUs), and from desktops to clusters of servers to mobile and edge device.
Prerequisite:
- Operating System with Ubuntu 20.04
- Server IPv4 Address with Superuser Privileges (Root Access)
- Gnome Terminal for Linux Desktop
- PuTTy SSH client for Windows or macOS
- Powershell for Windows 10/11
- Familiar with APT Commands
Install TensorFlow on Ubuntu 20.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install Python.
By default, Python 3 comes with Ubuntu repositories. To install the python3-venv package run the following command:
sudo apt install python3-venv python3-dev
Step 3. Create TensorFlow Directory.
Once the module is installed, you are ready to create a virtual environment for our TensorFlow project:
mkdir my_tensorflow cd my_tensorflow
Within the directory, run the following command to create the virtual environment:
python3 -m venv venv
To start using the virtual environment, activate it by running the activate
script:
source venv/bin/activate
Step 4. Install TensorFlow on the Ubuntu system.
To install the current release, which includes support for CUDA-enabled GPU cards (Ubuntu and Windows):
pip install tensorflow
Or if you’re a bit of a resource, use this other package:
pip install tensorflow-cpu
In case you want to update TensorFlow and Pip, just execute these commands:
pip install --upgrade pip pip install --upgrade tensorflow
To verify the installation, run the following command, which will print the TensorFlow version:
python -c 'import tensorflow as tf; print(tf.__version__)'
The command should output the version of TensorFlow:
2.2.0
When you’re done with your Python environment, simply run the commands below to deactivate:
deactivate
That’s all you need to do to install TensorFlow on Ubuntu 20.04 Focal Fossa. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.