FedoraRHEL Based

How To Install TensorFlow on Fedora 40

Install TensorFlow on Fedora 40

In this tutorial, we will show you how to install TensorFlow on Fedora 40. TensorFlow, an open-source machine learning framework, has revolutionized the field of artificial intelligence. Its powerful tools and libraries enable developers and researchers to create sophisticated deep-learning models for various applications. One of the key advantages of TensorFlow is its ability to leverage the power of GPUs for accelerated computations.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the TensorFlow open-source machine learning on Fedora 40.

Prerequisites

Before we dive into the installation process, ensure that you have the following prerequisites in place:

  • A server running one of the following operating systems: Fedora 40.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • You will need access to the terminal to execute commands. Fedora provides the Terminal application for this purpose. It can be found in your Applications menu.
  • A stable internet connection to download the necessary packages.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install TensorFlow on Fedora 40

Step 1. Update the System.

To ensure a smooth installation process, it is essential to update your Fedora system to the latest version. Run the following commands in the terminal:

sudo dnf clean all
sudo dnf update

These commands will update your system packages to their latest versions, providing stability and compatibility.

Step 2. Installing Dependencies.

You will need to install several essential packages and dependencies. Open a terminal and run the following command:

sudo dnf install gcc gcc-c++ git python3-devel python3-pip

Step 3. Installing NVIDIA GPU Drivers.

TensorFlow requires NVIDIA GPU drivers to take advantage of GPU acceleration. Follow these steps to install the appropriate drivers:

First, add the NVIDIA repository to your system:

sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Install the NVIDIA GPU drivers:

sudo dnf update
sudo dnf install akmod-nvidia

Reboot your system to load the newly installed drivers

reboot

Verify the driver installation by running the following command:

nvidia-smi

If the command outputs information about your NVIDIA GPU, the drivers are successfully installed.

Step 4. Installing CUDA Toolkit.

The CUDA Toolkit is a set of libraries and tools required for GPU-accelerated computing. Follow these steps to install CUDA:

wget https://developer.download.nvidia.com/compute/cuda/12.5.0/local_installers/cuda_12.5.0_555.42.02_linux.run
sudo sh cuda_12.5.0_555.42.02_linux.run

Follow the on-screen instructions to complete the installation. Make sure to select the option to install the CUDA Samples.

Update your environment variables by adding the following lines to your ~/.bashrc file:

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

Apply the changes:

source ~/.bashrc

Verify the CUDA installation by running the following command:

nvcc --version

Step 5. Installing cuDNN.

cuDNN (CUDA Deep Neural Network) is a library that provides optimized primitives for deep learning. Follow these steps to install cuDNN:

wget https://developer.download.nvidia.com/compute/cudnn/redist/cudnn/linux-x86_64/cudnn-linux-x86_64-9.2.0.82_cuda12-archive.tar.xz

Extract the downloaded archive:

tar -xvf cudnn-linux-x86_64-9.2.0.82_cuda12-archive.tar.xz

Copy the extracted files to the CUDA directory:

sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

Verify the cuDNN installation by running the following command:

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

Step 5. Installing TensorFlow on Fedora 40.

There are multiple ways to install TensorFlow with GPU support, such as using pip, Anaconda, or building from source. For optimal performance, we recommend building TensorFlow from the source. Follow these steps:

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow

Checkout the desired TensorFlow version (e.g., v2.5.0):

git checkout v2.5.0

Configure the build:

./configure

Build TensorFlow:

bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

Build the Python package:

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

Install the TensorFlow package:

pip3 install /tmp/tensorflow_pkg/tensorflow-<version>-cp<python_version>-cp<python_version>m-linux_x86_64.whl

Replace <version> with the TensorFlow version and <python_version> with your Python version (e.g., “38” for Python 3.8).

To verify that TensorFlow is installed correctly and can access your GPU, run the following Python code:

import tensorflow as tf

print("TensorFlow version:", tf.__version__)
print("GPU available:", tf.test.is_gpu_available())

If the output shows the TensorFlow version and confirms that a GPU is available, your installation is successful.

Congratulations! You have successfully installed TensorFlow. Thanks for using this tutorial for installing the TensorFlow machine learning on Fedora 40. system. For additional help or useful information, we recommend you check the TensorFlow website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button