How to Run Stable Diffusion on Linux: Complete Setup Guide

How to Run Stable Diffusion on Linux: Complete Setup Guide

Tested on: Ubuntu 24.04 LTS · Ubuntu 22.04 LTS · Debian 12 — NVIDIA RTX 3080 (10 GB VRAM), AMD RX 6700 XT (12 GB VRAM) — Last updated: June 2026

Stable Diffusion runs natively on Linux with better performance and control than Windows: direct GPU memory access, no antivirus interference with model loading, and ROCm support for AMD GPUs that simply doesn't exist on Windows. This guide covers the full stack — NVIDIA and AMD GPU setup, AUTOMATIC1111 WebUI, ComfyUI, and command-line generation via the Diffusers library — from a clean system to generating your first image.

Prerequisites

  • Ubuntu 24.04 / 22.04 or Debian 12 (other distros work, package names may differ)
  • NVIDIA GPU with 4 GB+ VRAM (CUDA), or AMD RX 5000 series or newer (ROCm), or CPU only (slow — testing only)
  • Python 3.10 or 3.11 (python3 --version)
  • Git installed: sudo apt install git
  • 20–50 GB free disk space for models and dependencies
  • For AMD: a supported ROCm GPU — check the ROCm compatibility matrix

VRAM Requirements at a Glance

VRAMWhat runs comfortably
4 GBSD 1.5 with --medvram. Functional, not fast.
6 GBSD 1.5 well. SDXL with --medvram, slowly.
8 GBSDXL at 1024×1024. SD 1.5 fast with room to spare.
10–12 GBSDXL at full resolution, img2img, inpainting, ControlNet.
16 GB+SDXL batch generation, video frames, multiple ControlNets.

NVIDIA Setup

The AUTOMATIC1111 installer handles PyTorch automatically, but the NVIDIA driver and CUDA toolkit must already be present on the system before you run it.

# Confirm your driver is loaded:
nvidia-smi

Expected output:

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.15    Driver Version: 550.54.15    CUDA Version: 12.4               |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
|   0  NVIDIA GeForce RTX 3080       Off  | 00000000:01:00.0  Off  |                  N/A |
+-----------------------------------------------------------------------------------------+

If nvidia-smi is not found, install the driver first — see our NVIDIA drivers on Ubuntu guide before continuing.

# Install CUDA toolkit (if nvcc is missing):
sudo apt install -y nvidia-cuda-toolkit

# Verify:
nvcc --version
# nvcc: NVIDIA (R) Cuda compiler driver
# Cuda compilation tools, release 12.4

# Install Python venv support and build deps:
sudo apt install -y python3-pip python3-venv git libgoogle-perftools-dev wget

AMD Setup (ROCm)

AMD GPU compute on Linux uses ROCm — AMD's answer to CUDA. It works only on Linux, which is one reason Linux is the preferred platform for AMD-based Stable Diffusion rigs. Supported hardware includes RX 5000 series and newer, RX 6000, RX 7000, and Instinct cards.

# Download and install the amdgpu meta-package (Ubuntu 22.04/24.04):
wget https://repo.radeon.com/amdgpu-install/latest/ubuntu/jammy/amdgpu-install_6.1.60100-1_all.deb
sudo dpkg -i amdgpu-install_6.1.60100-1_all.deb
sudo amdgpu-install --usecase=rocm --no-dkms

# Add your user to the required groups:
sudo usermod -aG render,video $USER

# Reboot before proceeding:
sudo reboot

# After reboot, verify ROCm sees your GPU:
rocminfo | grep -E "gfx|Name"
rocm-smi

Expected output from rocm-smi:

========================= ROCm System Management Interface =========================
=================================== Concise Info ===================================
GPU  Temp   AvgPwr  SCLK    MCLK    Fan  Perf  PwrCap  VRAM%  GPU%
  0  38.0c  15.0W   800Mhz  875Mhz  0%   auto  186.0W    0%   0%

Note the gfx version from rocminfo — you'll need it when launching AUTOMATIC1111. RX 6000 series reports gfx1030; RX 7000 series reports gfx1100.

Install AUTOMATIC1111 WebUI

AUTOMATIC1111 (A1111, sd-webui) is the most feature-complete Stable Diffusion frontend. It handles txt2img, img2img, inpainting, upscaling, and supports hundreds of community extensions. The webui.sh script creates its own Python virtual environment and installs all dependencies automatically — do not run it as root.

# Clone the repository:
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui

# First launch — this downloads PyTorch (~2 GB), all Python deps, and sets up the venv.
# Expect 10–30 minutes on the first run:
./webui.sh

The script will print its progress. When you see Running on local URL: http://127.0.0.1:7860, the server is ready.

AMD-Specific Launch Configuration

AMD users must set environment variables to tell ROCm which GPU architecture to target, and skip the CUDA presence check:

# For RX 6000 series (gfx1030):
export HSA_OVERRIDE_GFX_VERSION=10.3.0
export PYTORCH_HIP_ALLOC_CONF=garbage_collection_threshold:0.9,max_split_size_mb:512

./webui.sh --skip-torch-cuda-test

# For RX 7000 series (gfx1100):
export HSA_OVERRIDE_GFX_VERSION=11.0.0
./webui.sh --skip-torch-cuda-test

To avoid retyping these exports, add them to a launch wrapper script:

cat > ~/launch-sd-amd.sh << 'EOF'
#!/bin/bash
export HSA_OVERRIDE_GFX_VERSION=10.3.0
export PYTORCH_HIP_ALLOC_CONF=garbage_collection_threshold:0.9,max_split_size_mb:512
cd ~/stable-diffusion-webui
./webui.sh --skip-torch-cuda-test "$@"
EOF
chmod +x ~/launch-sd-amd.sh

Download Your First Model

A1111 ships without a model checkpoint. Place .safetensors or .ckpt files in stable-diffusion-webui/models/Stable-diffusion/. Prefer .safetensors over .ckpt — the format is faster to load and cannot execute arbitrary code.

Recommended starting models:

  • SD 1.5 base — Fast, 4 GB VRAM minimum, enormous ecosystem of LoRAs and fine-tunes.
  • SDXL 1.0 — Higher quality at 1024×1024 native, needs 8 GB+ VRAM.
  • DreamShaper XL — Fine-tuned SDXL, excellent for portraits, available on Civitai.
  • Realistic Vision v6 — Photorealistic results on SD 1.5 base, popular and well-maintained.
# Method 1: Hugging Face CLI (for official base models):
pip install huggingface_hub
huggingface-cli login    # requires a free HF account

huggingface-cli download runwayml/stable-diffusion-v1-5 
  v1-5-pruned-emaonly.safetensors 
  --local-dir stable-diffusion-webui/models/Stable-diffusion/

# Method 2: wget with a direct URL (Civitai models, no login required for free models):
wget -O stable-diffusion-webui/models/Stable-diffusion/dreamshaper_xl.safetensors 
  "https://civitai.com/api/download/models/MODEL_ID"
# Replace MODEL_ID with the actual numeric ID from the Civitai download button URL

# Confirm the file is in place:
ls -lh stable-diffusion-webui/models/Stable-diffusion/

Launch Flags and First Generation

cd stable-diffusion-webui

# Standard NVIDIA launch:
./webui.sh

# Common flags — combine as needed:
./webui.sh --xformers               # memory-efficient attention, faster on most NVIDIA GPUs
./webui.sh --medvram                # offloads model components to RAM; for 4–6 GB VRAM
./webui.sh --lowvram                # maximum offloading; <4 GB VRAM (very slow)
./webui.sh --listen                 # bind to 0.0.0.0; accessible from LAN
./webui.sh --port 7861              # use a different port
./webui.sh --api                    # enable REST API at /docs
./webui.sh --xformers --medvram     # combine flags freely

Open http://127.0.0.1:7860 in your browser. For a first test generation:

  1. Select your model checkpoint in the top-left dropdown. Click the refresh icon if it doesn't appear.
  2. Set image size to 512×512 for SD 1.5 models, 1024×1024 for SDXL.
  3. Enter a positive prompt: portrait of a woman, cinematic lighting, shallow depth of field, 8k, hyperrealistic
  4. Enter a negative prompt: blurry, deformed, bad anatomy, extra limbs, watermark, low quality, jpeg artifacts
  5. Sampling steps: 20 is a solid default. Sampler: DPM++ 2M Karras.
  6. CFG Scale: 7. Higher values follow the prompt more strictly but can over-saturate.
  7. Click Generate.

Install ComfyUI

ComfyUI uses a node-graph interface where each operation in the diffusion pipeline is an explicit, connectable node. It's more complex than A1111 but gives you exact control over every step — useful for chaining multiple models, building repeatable workflows, or implementing advanced techniques like IPAdapter and SDXL refiners. A1111 and ComfyUI can share the same model files by configuring paths in ComfyUI's extra_model_paths.yaml.

git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI

# Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate

# Install PyTorch for NVIDIA (CUDA 12.1):
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

# For AMD ROCm:
# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.7

# Install remaining dependencies:
pip install -r requirements.txt

# Link or copy a model into ComfyUI's checkpoint directory:
cp /path/to/your/model.safetensors models/checkpoints/

# Or point ComfyUI at your A1111 model directory:
cp extra_model_paths.yaml.example extra_model_paths.yaml
# extra_model_paths.yaml — point ComfyUI at your A1111 models folder:
a111:
  base_path: /home/youruser/stable-diffusion-webui/
  checkpoints: models/Stable-diffusion
  loras: models/Lora
  vae: models/VAE
  controlnet: models/ControlNet
  embeddings: embeddings
# Launch ComfyUI:
python main.py
# Opens at http://127.0.0.1:8188

# Memory flags for lower VRAM:
python main.py --medvram    # 6–8 GB
python main.py --lowvram    # <6 GB
python main.py --cpu        # CPU-only fallback

Command-Line Generation with Diffusers

The Hugging Face diffusers library lets you drive Stable Diffusion from Python scripts with no WebUI involved — ideal for batch processing, integration into pipelines, or running on headless servers.

pip install diffusers transformers accelerate
python3 << 'EOF'
from diffus




Go up