- Posted on
- • Artificial Intelligence
Artificial Intelligence Linux Migration Guide
- Author
-
-
- User
- linuxbash
- Posts by this author
- Posts by this author
-
Artificial Intelligence Linux Migration Guide
Move your AI stack to Linux and stop losing time to driver mismatches, flaky environments, and throttled training. This guide shows you how to stand up a fast, reproducible Linux workstation or server for AI—covering drivers, Python environments, containers, and real-world steps to get your models training today.
Problem/value in one line: Migrating AI workflows to Linux gives you better performance, reliability, and automation with the same tools used in production clusters.
Why this matters
Performance and stability: Linux is the default OS in AI research and production. GPU drivers and libraries are best supported here, and your jobs won’t be preempted by OS background tasks.
Reproducibility: Package managers, containers, and systemd make it easy to pin versions and run jobs reliably.
Cost and scale: You can reuse the same tooling from your laptop to multi-GPU servers and cloud VMs.
Who this is for
Data scientists and ML engineers coming from Windows or macOS.
Researchers standardizing environments across laptops, workstations, and clusters.
DevOps/SREs building AI infra.
Step 1: Choose a distro and prepare the base system
Pick a mainstream distro with good GPU and container support:
Ubuntu LTS (22.04/24.04) for widest community support.
Fedora (latest) for newer kernels and fast updates.
openSUSE Tumbleweed/Leap for stability and YaST tooling.
Update and install essential build/dev tools.
Ubuntu/Debian (apt):
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential git curl wget pkg-config cmake \
python3 python3-pip python3-venv python3-dev libffi-dev
Fedora/RHEL/CentOS Stream (dnf):
sudo dnf upgrade --refresh -y
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y git curl wget pkg-config cmake \
python3 python3-pip python3-devel libffi-devel
openSUSE (zypper):
sudo zypper refresh && sudo zypper update -y
sudo zypper install -y -t pattern devel_basis
sudo zypper install -y git curl wget pkg-config cmake \
python3 python3-pip python3-devel libffi-devel
Optional remote/dev quality-of-life:
SSH server
apt:
sudo apt install -y openssh-server && sudo systemctl enable --now sshdnf:
sudo dnf install -y openssh-server && sudo systemctl enable --now sshdzypper:
sudo zypper install -y openssh && sudo systemctl enable --now sshdTmux
apt:
sudo apt install -y tmuxdnf:
sudo dnf install -y tmuxzypper:
sudo zypper install -y tmux
Step 2: Enable your GPU (NVIDIA/AMD/Intel)
General rule: Prefer framework wheels that bundle CUDA/ROCm (e.g., PyTorch binary with CUDA) to avoid managing system CUDA yourself. You still need a correct GPU driver.
NVIDIA drivers
- Ubuntu (recommended):
sudo ubuntu-drivers autoinstall
sudo reboot
- Debian:
sudo apt install -y nvidia-driver firmware-misc-nonfree
sudo reboot
- Fedora (via RPM Fusion):
sudo dnf install -y https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install -y akmod-nvidia xorg-x11-drv-nvidia-cuda
sudo reboot
- openSUSE:
- Tumbleweed example (adjust repo for Leap):
sudo zypper addrepo --refresh https://download.nvidia.com/opensuse/tumbleweed NVIDIA sudo zypper refresh sudo zypper install -y nvidia-driver-G06 sudo reboot
- Tumbleweed example (adjust repo for Leap):
Verify:
nvidia-smi
AMD ROCm (for supported GPUs)
- You must enable AMD’s ROCm repository for your distro per AMD docs, then:
- apt:
sudo apt install -y rocm-dev - dnf:
sudo dnf install -y rocm-dev - zypper:
sudo zypper install -y rocm-devNote: ROCm support varies by GPU model and distro; check compatibility first.
- apt:
Intel (oneAPI for Arc/Xe/iGPU)
- After enabling Intel’s oneAPI repository, install base/HPC kits:
- apt:
sudo apt install -y intel-basekit intel-hpckit - dnf:
sudo dnf install -y intel-basekit intel-hpckit - zypper:
sudo zypper install -y intel-basekit intel-hpckit
- apt:
Step 3: Create a reproducible Python environment
Use venv for lightweight isolation or conda/mamba for multi-language stacks.
Install Python tooling (already installed above). Create a project venv:
cd ~/projects/my-ai-project
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip wheel
Install popular libraries. PyTorch with bundled CUDA (no system CUDA required):
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
Test GPU:
python - <<'PY'
import torch
print("Torch:", torch.__version__)
print("CUDA available:", torch.cuda.is_available())
if torch.cuda.is_available():
print("GPU:", torch.cuda.get_device_name(0))
PY
Lock dependencies for reproducibility:
pip freeze > requirements-lock.txt
If you prefer conda/mamba:
apt:
sudo apt install -y python3-virtualenv # optional; for virtualenv usersdnf:
sudo dnf install -y python3-virtualenvzypper:
sudo zypper install -y python3-virtualenvThen install Miniconda/Mambaforge from the official installer and create an env:
conda create -n ai python=3.11
conda activate ai
Step 4: Containerize for portability (Docker/Podman)
Containers let you run the same stack on laptops, servers, and CI.
Install Docker
- apt:
sudo apt install -y docker.io
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
# Log out/in to use docker without sudo
- dnf:
sudo dnf install -y docker
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
- zypper:
sudo zypper install -y docker
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
Or install Podman (rootless by default)
- apt:
sudo apt install -y podman
- dnf:
sudo dnf install -y podman
- zypper:
sudo zypper install -y podman
GPU in containers (NVIDIA)
Install NVIDIA Container Toolkit after adding NVIDIA’s repo for your distro:
- apt:
sudo apt install -y nvidia-container-toolkit- dnf:
sudo dnf install -y nvidia-container-toolkit- zypper:
sudo zypper install -y nvidia-container-toolkitThen restart Docker and test:
sudo systemctl restart docker
docker run --rm --gpus all nvidia/cuda:12.3.2-runtime-ubuntu22.04 nvidia-smi
Tip: Many AI images exist (e.g., pytorch/pytorch, tensorflow/tensorflow). Pin tags to avoid surprises.
Step 5: Migrate your code, data, and jobs
Code
- Use git to pull your repo and keep history:
git clone https://github.com/you/your-repo.git
Data
- Use rsync to move datasets:
rsync -avh --progress /path/to/local/data/ user@linux:/data/
Secrets
- Store API keys in environment files and never commit them:
echo "export WANDB_API_KEY=xxxx" >> ~/.bash_profile
source ~/.bash_profile
Automation
- Run periodic training/eval with cron or systemd user services. Example cron (daily at 1 AM):
crontab -e
# Add:
0 1 * * * cd /home/you/projects/my-ai-project && /home/you/projects/my-ai-project/.venv/bin/python train.py >> /home/you/train.log 2>&1
Real-world example: Port a Windows PyTorch project to Linux
Scenario: You trained on Windows CPU-only. Now you want Linux + NVIDIA GPU acceleration.
1) Update and install essentials (Step 1). 2) Install NVIDIA driver and reboot (Step 2). Verify with:
nvidia-smi
3) Clone your repo and set up venv:
git clone https://github.com/you/your-repo.git
cd your-repo
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip wheel
4) Install deps and GPU-enabled PyTorch:
pip install -r requirements.txt # if you had one
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
5) Test and train:
python - <<'PY'
import torch
assert torch.cuda.is_available(), "CUDA not available"
print("Device:", torch.cuda.get_device_name())
PY
python train.py --epochs 10 --batch-size 64 --device cuda
Optional: Containerize it
cat > Dockerfile <<'DOCKER'
FROM pytorch/pytorch:2.4.0-cuda12.1-cudnn8-runtime
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r requirements.txt
CMD ["python","train.py","--device","cuda"]
DOCKER
docker build -t your-repo:cuda .
docker run --rm --gpus all -v $PWD:/app your-repo:cuda
Common pitfalls and quick fixes
Driver mismatch: If
nvidia-smifails, reinstall drivers for your exact distro and kernel, then reboot.Mixed CUDA installs: Prefer framework wheels that include CUDA to avoid system CUDA conflicts.
Permissions on Docker: If
dockerneeds sudo, re-login after adding your user to the docker group.Memory errors: Increase swap for big tokenizers/batches on small RAM boxes:
sudo fallocate -l 32G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Conclusion and next step (CTA)
You now have a clean, fast, and reproducible Linux AI stack: drivers verified, Python isolated, and containers ready. Your next move:
Pick one project and fully migrate it today.
Lock dependencies, write a minimal Dockerfile, and schedule one automated job.
Document your setup script so new machines match in minutes.
When you’re ready, extend this workflow to multi-GPU training, remote clusters, and CI. Linux is where AI lives—welcome home.