AI

Install Stable Diffusion on Linux with ComfyUI (Ubuntu & RHEL)

Stable Diffusion runs fine on your own Linux box with an NVIDIA GPU. No cloud subscription, no per-image credits, no queue. This guide installs it end to end on Ubuntu and on Rocky/RHEL, generates real images, and shows the generation times and VRAM you should actually expect. The driver repositories, PyTorch and ComfyUI 0.45.0 install steps were re-run on Ubuntu 24.04 and Rocky Linux 10 in November 2026, and the generation numbers come from an earlier RTX 4090 run.

Original content from computingforgeeks.com - post 171338

We build this on ComfyUI, not AUTOMATIC1111. That choice matters now, so here is the reasoning before you type anything.

ComfyUI or AUTOMATIC1111?

Most older tutorials install the AUTOMATIC1111 web UI. It still works, but active development has stalled and it cannot run Flux, the model family that now sets the quality bar for local generation. ComfyUI is the maintained default. It picks up new model architectures first, runs faster, and uses less VRAM on the same card.

 ComfyUIAUTOMATIC1111
Active developmentYes, frequent releasesStalled
SDXL / SD 3.5BothSDXL only
Flux.1YesNo
Speed on the same GPUFasterSlower
VRAM useLowerHigher
InterfaceNode graphForm and tabs

The node graph has a learning curve, but it ships with ready-made workflows, so you generate your first image without wiring a single node yourself. If you specifically want the form-style AUTOMATIC1111 interface, the driver and Python steps below still apply. Only the final clone and launch differ.

What you need

Stable Diffusion is GPU bound. An NVIDIA card with enough VRAM is the one hard requirement. CPU generation technically works and is unusably slow, so this guide assumes a GPU. VRAM is what decides which models you can run:

VRAMWhat runs comfortably
8 GBSD 1.5 and SDXL at 1024px, slower as ComfyUI streams weights
12 GBSDXL comfortably, Flux in fp8 with offloading
16 GBSDXL and SD 3.5, Flux fp8 with little offloading
24 GB and upEverything here at full speed, room for larger batches

No local GPU? You can rent one by the hour. We ran this entire build on a single RTX 4090 rented from vast.ai for well under a dollar an hour, which is the cheapest way to follow along if your workstation has no NVIDIA card. If you rent GPUs often, it pays to script the rent-and-destroy cycle so you never leave one running idle. If you are weighing a card to buy for image work, our best GPU for ComfyUI and Stable Diffusion guide times SDXL, FLUX and video models on 12 GB, 16 GB and 24 GB cards, and the GPU picks for local AI cover the text-model side.

Budget about 30 GB of free disk for the two models we download, plus room for your outputs.

Install the NVIDIA driver

ComfyUI runs on PyTorch, and the PyTorch pip wheel bundles its own CUDA runtime. You need the NVIDIA driver so the GPU is visible, but you do not need the full CUDA Toolkit that older guides tell you to install. Skip nvcc unless you compile CUDA code yourself.

On Ubuntu 26.04 or 24.04, the packaged driver is the simplest path. Server and cloud images do not ship the helper, so install it first:

sudo apt update
sudo apt install -y ubuntu-drivers-common
sudo ubuntu-drivers install

If you want a specific driver branch, use NVIDIA’s own repository instead. Add the CUDA repo key and install the driver metapackage. Swap ubuntu2404 for ubuntu2604 on 26.04:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
sudo apt install -y cuda-drivers

On Rocky Linux, AlmaLinux, or RHEL 10, the driver builds a kernel module, so install the prerequisites first: EPEL and CRB for the dependencies, the compiler toolchain, and kernel headers matched to the running kernel.

sudo dnf install -y epel-release
sudo dnf config-manager --set-enabled crb
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y kernel-devel-matched kernel-headers

Those first two lines are the Rocky and AlmaLinux form. On subscription-based RHEL, install EPEL from the Fedora project RPM and enable CodeReady Builder with subscription-manager repos --enable codeready-builder-for-rhel-10-x86_64-rpms instead.

Now add the NVIDIA CUDA repository for EL10 and install the driver metapackage:

sudo dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel10/x86_64/cuda-rhel10.repo
sudo dnf clean all
sudo dnf -y install cuda-drivers

Reboot after the driver installs so the kernel module loads, then confirm the GPU is visible:

nvidia-smi

You should see the card, its total memory, and the driver version in the header:

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.159.03             Driver Version: 580.159.03     CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
|   0  NVIDIA GeForce RTX 4090        On  |   00000000:C2:00.0 Off |                  Off |
| 30%   40C    P8             28W /  450W |       1MiB /  24564MiB |      0%      Default |
+-----------------------------------------+------------------------+----------------------+

If nvidia-smi reports “command not found” or “no devices were found”, the module did not load. On RHEL that usually means Secure Boot rejected the unsigned module, so either enroll the key it prompts for or turn Secure Boot off in firmware. Our longer walk-through covers the details in installing NVIDIA drivers and CUDA on Ubuntu.

Install ComfyUI

ComfyUI is a Python application. Install Git, Python, and the tools to build a couple of wheels, then run it inside a virtual environment so it never touches your system Python.

On Ubuntu or Debian:

sudo apt update
sudo apt install -y git python3 python3-venv python3-pip

On Rocky, AlmaLinux, or RHEL, the virtual-environment module ships inside the base python3 package, so there is no separate venv package to add. You do need a compiler and the Python headers:

sudo dnf install -y git python3 python3-pip python3-devel gcc

Clone the repository into your home directory:

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

Create and activate a virtual environment:

python3 -m venv venv
source venv/bin/activate

Install the CUDA build of PyTorch first, then the rest of ComfyUI’s requirements. This is the command the ComfyUI installation guide now gives for NVIDIA cards, with the CUDA 13 wheel index added as an extra source:

pip install --upgrade pip
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu130
pip install -r requirements.txt

The old cu128 advice is out of date. ComfyUI’s installation guide now says a cu130 or newer PyTorch is required on RTX 20 series cards and above, and DynamicVRAM, the memory manager covered further down, only switches on with PyTorch 2.8 or later. Because the index is an extra one, pip takes the newest matching wheel from either source. On both lab boxes that was PyTorch 2.15.0 from PyPI, built against CUDA 13.2. Check what you got:

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

The Ubuntu 24.04 and Rocky Linux 10 runs both printed the same build:

2.15.0+cu132 13.2

A CUDA 13.2 wheel doesn’t need a 13.2 driver. NVIDIA’s minor version compatibility lets any CUDA 13.x runtime run on a driver from the 580 branch or newer, which is what nvidia-smi showed earlier. On a 570 or older driver (the header says CUDA 12.x), upgrade the driver before going further. The NVIDIA repository offered driver 620.70.06 to both lab boxes in November 2026.

Confirm PyTorch actually sees the GPU before going any further. The torch.cuda.is_available() call below is the same check PyTorch’s install guide recommends, and this one line saves a lot of confusion later:

python3 -c "import torch; print(torch.cuda.is_available(), torch.cuda.get_device_name(0))"

A working install prints True and the GPU name:

True NVIDIA GeForce RTX 4090

Here is that check together with the driver confirmation on our test box:

nvidia-smi showing an RTX 4090 with driver 580 and PyTorch reporting CUDA available on Linux
Driver and PyTorch both see the RTX 4090.

With the driver and PyTorch both working, ComfyUI has everything it needs to run. Next come the models.

Download the models

ComfyUI ships no models. You download the checkpoints yourself and drop them into models/checkpoints. We use two: SDXL, the Stable Diffusion baseline that still holds up, and Flux.1 schnell, a sharper model that ComfyUI runs and AUTOMATIC1111 cannot.

Grab SDXL base first. It is about 6.9 GB:

cd ~/ComfyUI/models/checkpoints
wget https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors

Then the all-in-one fp8 build of Flux.1 schnell. It packs the text encoders and VAE into a single file, so there are no extra downloads to chase. It is Apache-2.0 licensed and needs no account, unlike the gated Flux dev and SD 3.5 weights:

wget https://huggingface.co/Comfy-Org/flux1-schnell/resolve/main/flux1-schnell-fp8.safetensors

Both files should now sit in the checkpoints folder:

ls -lh ~/ComfyUI/models/checkpoints

The sizes confirm the downloads completed in full. ls reports in GiB, so the 6.9 GB and 17.2 GB files show as 6.5G and 17G:

-rw-r--r-- 1 user user 6.5G sd_xl_base_1.0.safetensors
-rw-r--r-- 1 user user  17G flux1-schnell-fp8.safetensors

With both checkpoints in place, you can start the server.

Launch ComfyUI and open the web UI

Start the server. The --listen flag binds it to all interfaces so you can reach it from another machine on your network, which is what you want on a headless GPU box. On a local desktop you can drop the flag and use the default localhost bind:

cd ~/ComfyUI
source venv/bin/activate
python3 main.py --listen

The startup log reports the detected GPU, the VRAM it sees, and the address to open. This one is from the RTX 4090 run, which used ComfyUI 0.34.0 on a cu128 wheel:

Total VRAM 24081 MB, total RAM 61747 MB
pytorch version: 2.11.0+cu128
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 4090 : cudaMallocAsync
ComfyUI version: 0.34.0
comfyui-frontend-package version: 1.51.9
Starting server
To see the GUI go to: http://0.0.0.0:8188

A current checkout prints the newer versions in the same spot. The November runs on Ubuntu 24.04 and Rocky Linux 10 had no GPU, so these lines are all that carries over from their logs:

pytorch version: 2.15.0+cu132
ComfyUI version: 0.45.0
comfyui-frontend-package version: 1.58.5

On an NVIDIA card with PyTorch 2.8 or newer, current ComfyUI also logs DynamicVRAM support detected and enabled at startup. If you see Unsupported Pytorch detected instead, your venv picked up an old wheel. No working comfy-aimdo install detected means pip install -r requirements.txt did not finish. Either way, fix it first, because the memory advice later in this guide won’t match what ComfyUI does.

Open http://SERVER-IP:8188 in a browser. ComfyUI opens on a starter workflow. From the Workflow menu, load a basic text-to-image template, then set the checkpoint loader to sd_xl_base_1.0.safetensors. The graph is small and readable: a checkpoint loader, a positive and a negative prompt, an empty latent, a sampler, and a save node. This is the whole pipeline for an image.

ComfyUI node graph for an SDXL text-to-image workflow with the generated image in the save node
The SDXL workflow in ComfyUI, with the result shown in the save node.

With the workflow loaded and the checkpoint set, you are ready to generate.

Generate your first image

Type a prompt into the positive box, leave the negative box for things you want to avoid, and click Run. Our test prompt was “a photorealistic red fox sitting in a snowy pine forest at golden hour, sharp focus, detailed fur, cinematic lighting” at 1024×1024, 30 steps, the euler sampler. The result:

SDXL generated image of a red fox in a snowy pine forest, created with ComfyUI on Linux
SDXL, 1024×1024, 30 steps on the RTX 4090.

The very first run is slow because the checkpoint has to load from disk into VRAM, which took about 40 seconds here. Every image after that reuses the loaded model. Warm SDXL runs at these settings landed around 5.5 seconds each and peaked at roughly 9.5 GB of VRAM.

Run Flux.1 for higher quality

Flux is where local generation got good. Point the checkpoint loader at flux1-schnell-fp8.safetensors, drop the sampler to 4 steps, and set the guidance to 1.0. Schnell is tuned for four steps, so it stays fast despite being the larger model. The same prompt through Flux schnell:

Flux.1 schnell generated image of a red fox in snow, more photorealistic than the SDXL version
Flux.1 schnell, same prompt, 4 steps. Sharper detail and more natural light.

The lighting, depth of field, and fur detail are a clear step up from SDXL, and it got there in four steps instead of thirty. The tradeoff is memory. Flux peaked near 19.7 GB, roughly twice SDXL, which is why the VRAM table above matters when you pick a card.

What to expect on real hardware

Here are the warm numbers from our RTX 4090, taken from ComfyUI’s own per-prompt timing on the 0.34.0 run, so a current build may report slightly different VRAM peaks. Generation time tracks step count and resolution, and VRAM tracks model size:

ModelResolutionStepsTime per imagePeak VRAM
SDXL base1024×102430~5.5 s~9.5 GB
Flux.1 schnell (fp8)1024×10244~3.0 s~19.7 GB

The console prints that timing after every run, which is the honest way to benchmark your own setup:

ComfyUI console showing SDXL and Flux prompt execution times on an RTX 4090
ComfyUI reports execution time per prompt.

Both models fit inside the 4090’s 24 GB with room left, even Flux at its 19.7 GB peak. Cards with less VRAM behave differently, and that is where most old advice goes wrong.

Smaller cards: leave the default mode alone

Older guides, this one included, told 8 GB and 12 GB owners to start ComfyUI with --lowvram. Drop that flag. Current ComfyUI turns on DynamicVRAM by default on NVIDIA cards: it keeps what fits on the GPU, streams the rest of the weights from system RAM as the sampler needs them, and tracks real memory pressure instead of guessing a model’s size up front. A model that doesn’t fit gets slower. It rarely fails outright. The flag’s own help text in cli_args.py says what happens if you add it anyway: “Doesn’t do anything if dynamic vram is enabled.” Run python3 main.py --help in your checkout and the --lowvram entry says the same.

So start with plain python3 main.py --listen on every card, and reach for these only when a run actually fails or the desktop stutters:

  • Lower the work first. Generate at 768px instead of 1024px, or set the batch size back to 1. That cuts the working memory the sampler needs on top of the weights.
  • --reserve-vram 1.5 keeps 1.5 GB free for the desktop, a browser or another app on the same GPU. Use it on a workstation where the display shares the card.
  • --novram is the last resort. It switches DynamicVRAM off and keeps almost nothing on the card. Our GPU buyer guide measured FLUX at about 3 GB of VRAM this way, 15 to 22% slower than the default on 12 GB and 16 GB cards. The weights then live in system RAM, so on a host with 16 GB or less it can fail before the GPU does any work.
  • --disable-dynamic-vram brings back the old estimate-based loader. Only then does --lowvram do anything, and all it does now is move the text encoders to the CPU.

--highvram and --gpu-only also turn DynamicVRAM off, and they pin every weight on the card. They only make sense on a 24 GB or larger GPU running models that fit with room to spare.

Keep it running

Running main.py in a terminal dies when you log out. On a box you actually use, put it behind a systemd service so it starts on boot and restarts on failure. Create the unit:

sudo vim /etc/systemd/system/comfyui.service

Point it at the venv Python and your ComfyUI directory. Replace the user and paths with yours:

[Unit]
Description=ComfyUI
After=network-online.target
Wants=network-online.target

[Service]
User=youruser
WorkingDirectory=/home/youruser/ComfyUI
ExecStart=/home/youruser/ComfyUI/venv/bin/python3 main.py --listen
Restart=on-failure

[Install]
WantedBy=multi-user.target

Enable and start it:

sudo systemctl daemon-reload
sudo systemctl enable --now comfyui

ComfyUI now survives reboots and logouts. From here the interesting work is adding models. ControlNet for pose and depth control, LoRAs for specific styles, and upscalers all drop into their folders under models and show up in the node menus. The install is the boring part, and it is done.

If you are building a local AI stack beyond image generation, the same GPU happily runs text models too. Our guides on running a local LLM with llama.cpp and Ollama on Ubuntu pick up where this one leaves off.

Keep reading

Open Source LLM Comparison Table (2026) AI Open Source LLM Comparison Table (2026) Ollama Models Cheat Sheet: Best Models by VRAM, Tested (PDF) AI Ollama Models Cheat Sheet: Best Models by VRAM, Tested (PDF) OpenCode CLI Cheat Sheet: Commands, Sessions and Fixes (PDF) AI OpenCode CLI Cheat Sheet: Commands, Sessions and Fixes (PDF) Install InvokeAI 7 on Linux with NVIDIA: Tested VRAM per Model AI Install InvokeAI 7 on Linux with NVIDIA: Tested VRAM per Model Install openSUSE with Claude Code: Agama MCP Server Tested AI Install openSUSE with Claude Code: Agama MCP Server Tested GPT-6.2 Astra and Sol: Pricing, API Access and What Changed AI GPT-6.2 Astra and Sol: Pricing, API Access and What Changed

Leave a Comment

Press ESC to close