---
title: How to Install PyTorch on Debian 12
url: https://docs.vultr.com/how-to-install-pytorch-on-debian-12
description: Learn how to install PyTorch on Debian 12 with step-by-step instructions. This guide covers multiple installation methods for both CPU and GPU support.
publish_date: 2025-07-02T16:00:04.120901Z
last_updated: 2025-07-02T16:00:04.120901Z
author: Deepak Vohra
header_image: https://docs.vultr.com/public/doc-assets/2247/120c815a-72ce-44fc-b492-5630932111b2.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

PyTorch is an open-source tensor computation library developed by Meta AI. It supports GPU and CPU acceleration and is widely used for building deep learning models in applications like computer vision, NLP, and reinforcement learning.

This article shows you how to install PyTorch on Debian 12 using either `pip` or Anaconda, create an isolated Python environment, and verify the installation with a simple test script.

## Prerequisites

Before you begin, you need to:

* Have access to a [Debian 12 server](https://www.vultr.com/servers/debian/) as a non-root user with sudo privileges.

## Create a Python Virtual Environment

To isolate your PyTorch project and avoid system-level conflicts, create a virtual environment using the `virtualenv` tool.

1. Verify that Python 3.9 or later is installed.

    ```console
    $ python3 --version
    ```

    Output:

    ```
    Python 3.11.2
    ```

1. Confirm that `pip` is available.

    ```console
    $ pip --version
    ```

    Output:

    ```
    pip 23.0.1 from /usr/lib/python3/dist-packages/pip (python 3.11)
    ```

1. Install `virtualenv`.

    ```console
    $ sudo apt install virtualenv -y
    ```

1. Create a new virtual environment named `pytorch_project_env`.

    ```console
    $ virtualenv pytorch_project_env
    ```

1. Activate the virtual environment.

    ```console
    $ source pytorch_project_env/bin/activate
    ```

    The shell prompt changes to indicate the active environment.

    ```
    (pytorch_project_env) linuxuser@vultr:~$
    ```

### When to Use `pip` vs. `conda`

* Use `pip` if you're working in a lightweight virtual environment using `virtualenv` or prefer to manage packages manually.

* Use **Anaconda** if you're already using Conda environments or need access to a broader scientific computing stack with simplified dependency management.

Both methods install the same PyTorch libraries. Choose the one that best fits your development setup.

???+ note "Install PyTorch with pip"

    To install the latest CPU-only version of PyTorch, use the official PyTorch wheel repository with `pip`.

    1. Make sure your virtual environment is active.

    1. Install PyTorch and related packages.

        ```console
        $ pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
        ```

        * `torch`: Core PyTorch library for tensor computation and deep learning.
        * `torchvision`: Utilities and pretrained models for computer vision.
        * `torchaudio`: Audio processing tools for deep learning applications.

??? note "Install PyTorch with Anaconda"

    Anaconda is a Python distribution that includes Conda, a package and environment manager. You can use Conda to install PyTorch and its associated libraries from the official PyTorch channel.

    If you haven't installed Anaconda yet, follow the [Anaconda installation guide for Debian 12](https://docs.vultr.com/how-to-install-anaconda-on-debian-12) before proceeding.

    1. Run the following command to install PyTorch with CPU-only support.

        ```console
        $ conda install pytorch torchvision torchaudio cpuonly -c pytorch
        ```

    1. When prompted, confirm the installation by typing `y`.

        The output should include lines similar to:

        ```
        Downloading and Extracting Packages:

        Preparing transaction: done
        Verifying transaction: done
        Executing transaction: done
        ```

    This method installs `torch`, `torchvision`, and `torchaudio` with compatible versions for your Conda environment.

## Verify Installation

You can verify your PyTorch installation by launching the Python interpreter and running a few basic commands.

1. Open the Python interpreter.

    ```console
    $ python
    ```

    Output:

    ```
    Python 3.11.2 (main) [GCC 12.2.0] on linux
    Type "help", "copyright", "credits", or "license" for more information.
    >>>
    ```

1. Import the PyTorch package.

    ```python
    >>> import torch
    ```

1. Print the installed PyTorch version.

    ```python
    >>> print(torch.__version__)
    ```

    Output:

    ```
    2.7.0+cu126
    ```

1. Generate a 5x3 tensor of random values to confirm basic functionality.

    ```python
    >>> x = torch.rand(5, 3)
    ```

    ```python
    >>> print(x)
    ```

    The output should be similar to:

    ```
    tensor([[0.7363, 0.4839, 0.1370],
        [0.6429, 0.0108, 0.9823],
        [0.8575, 0.9642, 0.5792],
        [0.8951, 0.8762, 0.7949],
        [0.7175, 0.0135, 0.9493]])
    ```

1. To exit the interpreter, type:

    ```python
    >>> exit()
    ```

## Conclusion

You successfully installed PyTorch on a Debian 12 server using either `pip` or Anaconda and verified the setup with a test script. With PyTorch, you can now build and train deep learning models for computer vision, natural language processing, and reinforcement learning.

To explore additional libraries and capabilities, visit the [official PyTorch documentation](https://docs.pytorch.org/docs/stable/index.html).
