Install ComfyUI for Stable Diffusion
Install ComfyUI for Stable Diffusion on Linux: set up a Python venv, install PyTorch for CUDA or ROCm, place models, tune GPU memory flags, and add custom nodes.
Before you start
- ▸NVIDIA drivers ≥ 525 with CUDA, or a working ROCm 5.7+ installation for AMD GPUs
- ▸At least 8 GB of disk space for ComfyUI plus several GB per model file
- ▸sudo privileges for installing system packages
- ▸At least one Stable Diffusion checkpoint in .safetensors or .ckpt format
ComfyUI is a node-based interface for Stable Diffusion that gives you fine-grained control over every part of the inference pipeline. It runs well on Linux, but the setup involves Python virtual environments, CUDA or ROCm drivers, multi-gigabyte model files, and optional custom node extensions. This guide walks through a clean, repeatable installation from source.
Prerequisites and Driver Check
Before touching Python, confirm your GPU drivers and compute stack are in place. ComfyUI works with NVIDIA (CUDA), AMD (ROCm), Intel Arc (IPEX), and CPU-only, but NVIDIA on CUDA gives the best out-of-the-box experience.
NVIDIA — verify CUDA
nvidia-smi
You need driver ≥ 525 for CUDA 12. If nvidia-smi is missing, install the proprietary driver first. On Fedora/RHEL that means the RPM Fusion repo; on Ubuntu, ubuntu-drivers autoinstall or a manual PPA.
AMD — verify ROCm
rocminfo | grep -i 'agent type'
ROCm 5.7+ is required for most current PyTorch ROCm builds. Installation is beyond this guide's scope — see AMD's official ROCm docs for your distro.
System Packages
You need Python 3.10 or 3.11 (3.12 has occasional compatibility gaps with some custom nodes as of mid-2025), git, and a few build tools.
Debian / Ubuntu
sudo apt update
sudo apt install -y git python3.11 python3.11-venv python3.11-dev \
libgl1 libglib2.0-0 build-essential
Fedora / RHEL 9 / Rocky 9
sudo dnf install -y git python3.11 python3.11-devel gcc gcc-c++ \
mesa-libGL glib2
Arch Linux
sudo pacman -S --needed git python python-pip base-devel
Arch ships a current Python; no version pinning needed in most cases.
Clone ComfyUI and Create a Virtual Environment
Always run ComfyUI inside a venv. This isolates its dependencies from the rest of your system and makes upgrades clean.
git clone https://github.com/comfyanonymous/ComfyUI.git ~/ComfyUI
cd ~/ComfyUI
python3.11 -m venv .venv
source .venv/bin/activate
Your prompt will gain a (.venv) prefix. Every subsequent Python and pip command in this guide assumes the venv is active.
pip install --upgrade pip wheel
Install PyTorch
PyTorch must match your compute backend. Pick exactly one block below.
NVIDIA CUDA 12.1 (recommended for most NVIDIA GPUs)
pip install torch torchvision torchaudio \
--index-url https://download.pytorch.org/whl/cu121
NVIDIA CUDA 11.8 (older cards, e.g. GTX 10-series)
pip install torch torchvision torchaudio \
--index-url https://download.pytorch.org/whl/cu118
AMD ROCm 5.7
pip install torch torchvision torchaudio \
--index-url https://download.pytorch.org/whl/rocm5.7
CPU only (slow but universal)
pip install torch torchvision torchaudio \
--index-url https://download.pytorch.org/whl/cpu
Check PyTorch's official Get Started page if your CUDA version differs — the wheel URLs follow a predictable pattern.
Install ComfyUI Requirements
pip install -r requirements.txt
This installs safetensors, transformers, diffusers, accelerate, and other dependencies declared by the project. It may take several minutes on a slow connection.
Model Placement
ComfyUI expects models in specific subdirectories under models/. The structure mirrors the model type:
| Model type | Directory |
|---|---|
| Stable Diffusion checkpoints (.safetensors, .ckpt) | models/checkpoints/ |
| VAE | models/vae/ |
| LoRA / LyCORIS | models/loras/ |
| ControlNet | models/controlnet/ |
| CLIP / text encoders | models/clip/ |
| Upscalers (ESRGAN etc.) | models/upscale_models/ |
| FLUX / SDXL UNET only | models/unet/ |
If your models already live elsewhere on disk, create symlinks rather than copying multi-gigabyte files:
ln -s /mnt/data/sd-models/v1-5-pruned-emaonly.safetensors \
~/ComfyUI/models/checkpoints/
Alternatively, edit extra_model_paths.yaml (copy the provided example and point it at your existing Automatic1111 or AUTOMATIC1111 model directories):
cp extra_model_paths.yaml.example extra_model_paths.yaml
nano extra_model_paths.yaml
Set base_path to your existing model root and ComfyUI will scan it on startup without any symlinking.
GPU Memory Flags
Stable Diffusion models range from 2 GB (SD 1.5 fp16) to 24+ GB (FLUX dev BF16). Tune memory behaviour with command-line flags when launching ComfyUI:
--lowvram— offloads most of the model to RAM; slower but works on 4–6 GB VRAM cards.--medvram— moderate offloading; good for 8 GB.--medvram-sdxl— like--medvrambut specifically helps SDXL on 8 GB.--cpu— run entirely on CPU (very slow; useful for debugging).--fp8_e4m3fn/--fp8_e5m2— quantise weights to 8-bit; dramatically reduces VRAM with minor quality loss on supported hardware.--force-fp16— force fp16 precision; helps on older NVIDIA cards that struggle with bf16.--disable-xformers— disable xFormers if you hit compatibility errors; ComfyUI will fall back to PyTorch's built-in attention.
xFormers is optional but can improve throughput on NVIDIA. Install it with:
pip install xformers
First Launch
cd ~/ComfyUI
source .venv/bin/activate
python main.py
For a card with 8 GB VRAM running SDXL:
python main.py --medvram-sdxl
ComfyUI starts a local web server, typically on http://127.0.0.1:8188. Open that URL in your browser. The default workflow loads automatically. If you need remote access (e.g., a headless server), add --listen 0.0.0.0 — but do this only on a trusted network since there is no built-in authentication.
Installing Custom Nodes
Custom nodes extend ComfyUI with new node types — upscalers, face detailers, prompt helpers, video support, and more. The recommended approach is ComfyUI-Manager, which adds an in-browser package manager.
cd ~/ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager.git
Restart ComfyUI. A Manager button appears in the top-right of the UI. From there you can search, install, and update nodes without touching the terminal. Each node may pull additional pip dependencies; ComfyUI-Manager installs them into the active venv automatically.
To install a node manually without the Manager:
cd ~/ComfyUI/custom_nodes
git clone https://github.com/example/SomeCustomNode.git
cd SomeCustomNode
pip install -r requirements.txt
Create a systemd User Service (Optional)
If you want ComfyUI to start on login without opening a terminal, create a user-level systemd service:
mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/comfyui.service
[Unit]
Description=ComfyUI Stable Diffusion
After=graphical-session.target
[Service]
Type=simple
WorkingDirectory=%h/ComfyUI
ExecStart=%h/ComfyUI/.venv/bin/python main.py --medvram
Restart=on-failure
Environment=PATH=%h/ComfyUI/.venv/bin:/usr/local/bin:/usr/bin:/bin
[Install]
WantedBy=default.target
systemctl --user daemon-reload
systemctl --user enable --now comfyui.service
Adjust the ExecStart flags to match your GPU memory situation. Logs are available via journalctl --user -u comfyui -f.
Verification
- Open
http://127.0.0.1:8188in a browser. - Confirm a checkpoint appears in the Load Checkpoint node's dropdown.
- Click Queue Prompt. Watch the terminal for CUDA/ROCm device output — it will print which device is being used.
- A completed image should appear in the browser output node within seconds to minutes depending on hardware.
Troubleshooting
"No module named 'torch'" after activating venv
You're likely in the wrong directory or the venv was not activated. Run source ~/ComfyUI/.venv/bin/activate explicitly, then python -c "import torch; print(torch.__version__)" to confirm.
CUDA out of memory
Add --lowvram or --medvram to the launch command. If still failing, try --fp8_e4m3fn for supported checkpoints, or reduce the image resolution in the workflow's empty latent node.
Black or green output images
Almost always a VAE mismatch. Some SDXL checkpoints need an external SDXL VAE. Place it in models/vae/ and wire a Load VAE node into your workflow explicitly rather than using the one baked into the checkpoint.
Custom node fails to load
Read the terminal output — missing pip packages are the most common cause. Activate the venv and run pip install -r custom_nodes/NodeName/requirements.txt manually. Some nodes also require matching versions of transformers or diffusers; check the node's README.
ROCm: "HIP error" or no GPU detected
Confirm your user is in the render and video groups (sudo usermod -aG render,video $USER then re-login). Also verify HSA_OVERRIDE_GFX_VERSION is set if your GPU is unofficially supported (e.g., RX 6600: export HSA_OVERRIDE_GFX_VERSION=10.3.0).
Frequently asked questions
- Can I share models with an existing Automatic1111 installation?
- Yes. Edit extra_model_paths.yaml and set base_path to your Automatic1111 models directory. ComfyUI will scan it on startup and list those checkpoints, VAEs, and LoRAs without copying any files.
- Which Python version should I use?
- Python 3.11 is the safest choice as of mid-2025. Python 3.10 also works. Python 3.12 is functional for the core install but some custom nodes have not updated their dependencies yet and will fail to import.
- How do I update ComfyUI after installation?
- Activate the venv, then run git pull inside ~/ComfyUI followed by pip install -r requirements.txt. This picks up both code changes and any new Python dependencies in one step.
- Does ComfyUI work on Wayland?
- ComfyUI's UI runs entirely in a browser, so it is Wayland-agnostic. There are no GTK or Qt windows involved. Any modern browser on Wayland will display the interface correctly.
- My 8 GB GPU still runs out of memory with --medvram. What else can I try?
- Enable fp8 quantisation with --fp8_e4m3fn if your card supports it, reduce the latent image resolution in the workflow, or switch to a pruned fp16 checkpoint. For SDXL specifically, use --medvram-sdxl rather than plain --medvram.
Related guides
Linux Clipboards Explained (+ Clipboard Managers)
Learn the difference between Linux's PRIMARY and CLIPBOARD selections, use xclip, xsel, and wl-clipboard from the terminal, and manage history with GPaste or Klipper.
Configure LibreOffice for Daily Use
Configure LibreOffice for daily use: set default save formats for MS Office interop, tune autosave, install fonts, and add productivity extensions.
Configure the Touchpad and Multitouch Gestures
Configure Linux touchpad behavior and multitouch gestures using libinput, libinput-gestures, and native GNOME and KDE Plasma settings on both Wayland and X11.
Wayland vs X11: How to Choose and Configure Each
Know when to run Wayland or X11, how to check your current session, switch at login with GDM/SDDM/LightDM, and handle NVIDIA and XWayland edge cases.