Introduction
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.
Note: For CentOS, see our guide on installing TensorFlow on CentOS.
Prerequisites
- 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
Then, run the following command for a wide-system installation of Virtualenv:
sudo pip3 install -U virtualenv
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
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:
Once you activate venv, move on to installing pip inside the isolated environment:
pip install --upgrade pip
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:
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])))"
Conclusion
This article showed you steps for installing TensorFlow on Ubuntu 18.04. With the desired version (CPU or GPU support) installed on your system, you can now move on to developing your machine-learning models.
Next you should also read
SysAdmin,DevOps and Development
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…
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…
Virtualization,Bare Metal Servers
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…
How to Install NVIDIA Tesla Drivers on Linux or Windows
September 7, 2018
Growing demands for extreme compute power lead to the unavoidable presence of bare metal servers in today’s…
Author
Sofija Simic
Sofija Simic is an aspiring Technical Writer at phoenixNAP. 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.