How to Install PyTorch on AlmaLinux
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.
Prerequisites
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
Step 1: Update Your System
Open your terminal and run the following command to update all system packages:
sudo dnf update -yOptionally, install EPEL for access to additional packages:
sudo dnf install epel-release -yStep 2: Install Python and pip
Check if Python is already installed:
python3 --versionIf it’s not installed, you can install it with:
sudo dnf install python3 python3-pip -yStep 3: Create a Virtual Environment (Optional)
To keep your Python environment clean and isolated, it’s a good idea to create a virtual environment:
python3 -m venv pytorch_env
source pytorch_env/bin/activateStep 4: Install PyTorch Using pip
To install PyTorch with CPU-only support:
pip install torch torchvision torchaudioIf 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:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118You can find the latest installation options at the official PyTorch website:
https://pytorch.org/get-started/locally
Step 5: Verify the Installation
To verify that PyTorch has been installed correctly, run:
pythonThen enter the following in the Python shell:
import torch
print(torch.__version__)
print("CUDA available:", torch.cuda.is_available())If everything is working, you will see the installed version of PyTorch and whether CUDA is available.
Troubleshooting Tips
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.
Conclusion
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.


