PyTorch is one of the most popular open-source machine learning frameworks developed by Facebook’s AI Research lab. It is widely used for deep learning applications, including computer vision and natural language processing. If you’re using AlmaLinux, a stable and reliable RHEL-based Linux distribution, this guide will show you how to install PyTorch quickly and efficiently.
Before you begin, ensure that:
You have a running instance of AlmaLinux 8 or 9
You have root or sudo privileges
Python 3.7 or higher is installed
Open your terminal and run the following command to update all system packages:
Optionally, install EPEL for access to additional packages:
Check if Python is already installed:
If it’s not installed, you can install it with:
To keep your Python environment clean and isolated, it’s a good idea to create a virtual environment:
To install PyTorch with CPU-only support:
If you want GPU acceleration and have a supported NVIDIA GPU along with proper drivers and CUDA installed, use the appropriate command. For example, to install PyTorch with CUDA 11.8 support:
You can find the latest installation options at the official PyTorch website:
https://pytorch.org/get-started/locally
To verify that PyTorch has been installed correctly, run:
Then enter the following in the Python shell:
If everything is working, you will see the installed version of PyTorch and whether CUDA is available.
If you encounter issues with pip or SSL certificates, update pip:
If using CUDA, make sure the NVIDIA drivers and CUDA toolkit are correctly installed and compatible with the version of PyTorch you’re installing.
You have successfully installed PyTorch on AlmaLinux. Whether you’re developing deep learning models or running experiments, PyTorch provides a flexible and powerful framework for machine learning on Linux systems. For more advanced setups, consider integrating with Jupyter Notebook or using Docker containers.