
TensorFlow is an open-source software library that allows implementations of common algorithms used for machine learning, artificial intelligence, and deep neural networks. By using Tensorflow, you can develop and deploy deep learning models such as Stable Diffusion and Large Language Models (LLMs).
This article explains how to install Tensorflow on Ubuntu 22.04 with either a GPU or CPU-only configuration. Depending on your system capabilities, you can use a Python package or a Conda environment to install and activate Tensorflow on your server.
Before you begin:
Deploy a fresh Ubuntu 22.04 Server on Vultr
Using SSH, access the server as a non-root user with sudo privileges
Install the latest Python3 version
To install TensorFlow on a Vultr Cloud GPU server, verify that the NVIDIA drivers are correctly installed, then choose your desired installation method as described below.
To install TensorFlow using Pip, verify the required CUDA and CUDNN versions to correctly activate the software package on your GPU server. The TensorFlow version 2.13 installed in this article requires the following respective packages.
11.88.6.0Verify that you install the required CUDA toolkit and cuDNN packages natively to avoid compatibility errors as described in the following resources:
Update the pip Python package manager
Using pip, install TensorFlow
The above command installs the TensorFlow version 2.13. To install the latest version, visit the TensorFlow releases page and further verify the required dependency package versions.
Conda is an environment package manager that allows you to install applications together with the necessary dependencies. To install TensorFlow, you must select a source Conda channel, and install the latest tensorflow-gpu version as described below.
Activate your Conda environment if not active
Install the TensorFlow GPU package
The above command installs the TensorFlow version 2.12.1 from the Conda-forge channel along with CUDA Toolkit 11.8 and cuDNN 8.8
To work with GPUs, TensorFlow requires the CUDA and cuDNN packages. The Conda installation process installs all necessary dependencies. However, they are not fully-fledged packages as compared to manually installed variants. For example, the
cudatoolkitpackage, which Conda installs as a TensorFlow dependency, does not allow you to use thenvcccompiler. If your use case requires these packages, explicitly install the CUDA Toolkit and cuDNN within your Conda environment.
If your server does not have an attached GPU interface. Install TensorFlow using the non-GPU package as described in the optional methods below.
Using pip, install the latest TensorFlow package
The above command installs TensorFlow version 2.13. To install the latest version, visit the TensorFlow releases page.
To install TensorFlow using Conda, run the following command in your environment
The above command installs the CPU-only tensorflow package without any GPU dependency packages. To install the latest available Conda package, visit the packages page
To verify that your TensorFlow installation is successful, perform sample computation tasks that allow you to test the application functionality using Python as described below.
Using Python, Import the TensorFlow package and print the list of available GPU devices
Output:
Test that TensorFlow can perform a tensor-based operation using random numbers:
When successful, your output should look like the one below:
As displayed in the above output, the last line is the tensor computation result
Verify that TensorFlow can perform a basic tensor-based computation
The above command executes a tensor-based operation using random numbers. When successful, your output should look like the one below:
In the above output, the last line is the computation result
If you receive the following TensorRT prompt while using TensorFlow
Install the latest TensorRT to optimize your inference operations
In this article, you installed TensorFlow on a Ubuntu 22.04 server, you explored how to install the package on both GPU-based and CPU-only systems. For more information, please visit the following resources:
0 Comments
Be the first to comment and share your perspective with the community.