How to Install PyTorch and TensorFlow on a VPS

PyTorch and TensorFlow are the two dominant machine learning frameworks, used for building, training, and running neural network models. This guide covers installing both (or either) on a CPU-only VPS.

Choosing Between PyTorch and TensorFlow

Both are capable, well-maintained frameworks — PyTorch is generally favored in research and has become the more common choice for many newer open-source models; TensorFlow remains widely used, particularly in some production deployment contexts. If you don't have a specific reason to prefer one, check which framework your specific model/project actually requires.

Step 1 — Set Up a Python Virtual Environment

python3 -m venv ml-env
source ml-env/bin/activate

Using a dedicated virtual environment avoids dependency conflicts with other Python projects on the same server — see How to Install Python on Ubuntu & Debian for the base setup.

Step 2 — Install PyTorch (CPU Version)

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

The CPU-specific index avoids downloading unnecessary GPU-related components, resulting in a smaller install.

Step 3 — Verify PyTorch Installation

python3 -c "import torch; print(torch.__version__); print(torch.cuda.is_available())"

cuda.is_available() correctly returns False on a CPU-only server — this is expected, not an error.

Step 4 — Install TensorFlow (CPU Version)

pip install tensorflow-cpu

Step 5 — Verify TensorFlow Installation

python3 -c "import tensorflow as tf; print(tf.__version__)"

Running a Simple Test Script (PyTorch)

import torch

x = torch.rand(3, 3)
print(x)
print(x @ x.T)  # basic matrix operation

Installing Additional Common Libraries

pip install numpy pandas scikit-learn matplotlib

Managing Memory for Larger Models

CPU-based deep learning can be memory-intensive — monitor usage with htop and consider setting explicit batch size limits in your code to avoid out-of-memory errors on smaller VPS plans.

Using a requirements.txt for Reproducibility

pip freeze > requirements.txt
pip install -r requirements.txt

Ensures consistent package versions if you redeploy this environment on another server later.

Common Errors

"Killed" message with no other error during training — almost always an out-of-memory condition where the OOM killer terminated the process; reduce batch size or model complexity, or check available RAM with free -h.

Installation is extremely slow — some ML package installations involve large downloads; ensure adequate disk space and a stable connection, and be patient with the initial install.

Continue Reading

Browse more articles in AI & Machine Learning on a VPS.

  • pytorch installation, tensorflow installation, machine learning framework vps, pytorch cpu
  • 0 brukere syntes dette svaret var til hjelp
Var dette svaret til hjelp?

Relaterte artikler

VPS Requirements for Running AI and Machine Learning Workloads

Before installing any AI tooling, it's worth understanding what a VPS can and can't realistically...

How to Install Ollama and Run Local LLMs on a VPS

Ollama makes running open-source large language models locally straightforward — handling...

How to Set Up a Private ChatGPT-Style Interface with Open WebUI

Open WebUI provides a familiar, browser-based chat interface for locally-run language models...

How to Install LocalAI as an OpenAI-Compatible API Alternative

LocalAI provides a drop-in, OpenAI-API-compatible endpoint backed by open-source models running...

How to Run Stable Diffusion for AI Image Generation on a VPS

Stable Diffusion generates images from text prompts using an open-source diffusion model. This...