Updated: 28 September 2026 · Applies to: PyTorch 2.14 (CUDA 13 build) on Ubuntu 24.04 / 26.04 LTS

PyTorch is the most common framework for training and running AI models. Its pip packages contain the CUDA libraries they need, so a GPU server only needs the NVIDIA driver, not the CUDA Toolkit. This guide installs PyTorch in a virtual environment and proves that it can use the GPU.

Before you start

  1. nvidia-smi prints a table (How to install the NVIDIA driver on Ubuntu 24.04 / 26.04 for a GPU server?).
  2. The default PyTorch package for Linux is built for CUDA 13, which needs driver 580 or newer. With an older driver use the CUDA 12.6 package in step 4.
  3. PyTorch needs Python 3.10 or newer. Ubuntu 24.04 and 26.04 include a suitable version.

Install PyTorch

  1. Install the Python tools:
    sudo apt update
    sudo apt install -y python3-venv python3-pip
  2. Create and activate a virtual environment. Ubuntu 24.04 and newer refuse pip install outside a virtual environment ("externally-managed-environment"), so this step is required:
    python3 -m venv ~/torch-env
    source ~/torch-env/bin/activate
  3. Install PyTorch (the download is large, several GB):
    pip install torch
  4. Only if your driver is older than 580: install the CUDA 12.6 build instead:
    pip install torch --index-url https://download.pytorch.org/whl/cu126

Test the GPU

python3 -c "import torch; print(torch.__version__); print('GPU available:', torch.cuda.is_available()); print('GPU count:', torch.cuda.device_count()); print(torch.cuda.get_device_name(0))"

You should see GPU available: True and your GPU's name. For a real workload test, run a large matrix multiplication on the GPU while you watch nvidia-smi in a second SSH window:

python3 -c "import torch; a=torch.randn(8192,8192,device='cuda'); b=torch.randn(8192,8192,device='cuda'); [a@b for _ in range(50)]; torch.cuda.synchronize(); print('done')"

If GPU available is False

Frequently asked questions

Do I need to install CUDA first?
No. The driver is enough.

How do I use only one of my GPUs?
See How to choose which GPU an application uses on a multi-GPU server?.

Which PyTorch version does this guide use?
PyTorch 2.14, the current release when this article was written.

Official documentation: PyTorch: Get started locally.

Need a GPU server, or a hand with the setup?

  • GPU dedicated servers: NVIDIA GPU servers for AI training and inference; our engineers can install the driver, CUDA, PyTorch or a private LLM and hand it over ready to use.
  • Private LLM installation: we install Ollama, the GPU driver and a chat interface on your own server.

Prefer a hand with the setup? Our engineers can do it for you: Hire an Expert, or use our on-demand server management.

Was this answer helpful? 0 Users Found This Useful (0 Votes)