Skip to content

Instantly share code, notes, and snippets.

@arpu-nagar
Last active April 11, 2024 03:00
Show Gist options
  • Save arpu-nagar/5d54e397323928c354ddfd27e15360d0 to your computer and use it in GitHub Desktop.
Save arpu-nagar/5d54e397323928c354ddfd27e15360d0 to your computer and use it in GitHub Desktop.
Ultimate Guide to Install Pytorch (CUDA) on Ubuntu 22.4

This gist contains a step-by-step procedure to install Pytorch with CUDA on Ubuntu 22.4.

1. Install conda

I prefer Miniconda but you can choose between Anaconda and Miniforge.

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh

2. Verify whether the installation is complete

bash

You should enter (base)

3. Create a new conda enviroment with Python 3.10 (packages matching to default Google Collab environment)

conda create --name prog python=3.10
conda activate prog

4. Install Pytorch

Please visit the Pytorch Get Started Page and follow the instructions depending on your CUDA requirements.

You can check your version of CUDA by

nvidia-smi

5. Verify Pytorch installation

python
import torch
torch.cuda.is_available()
exit()

You are ready to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment