TutorialDec 5, 20263 min read

How to Self-Host an LLM on a GPU Server (Ollama + Open WebUI)

Step by step from a fresh Ubuntu GPU server to your own private ChatGPT-style chat: NVIDIA driver, Ollama on the GPU, Open WebUI in Docker, and access over an SSH tunnel without opening a port.

Short answer: on an Ubuntu server with an NVIDIA card it takes four steps and about 20 minutes: install the driver, install Ollama, pull a model, and start Open WebUI for a chat in the browser. Nothing has to be open to the internet; you reach the chat through an SSH tunnel.

This guide uses an Ubuntu 24.04 GPU server with root access. The commands are the same on our GPU servers and on any other machine with an NVIDIA card.

Which card your model needs is in How Much VRAM Do You Need for an LLM?. In short: 12 GB for 8B models, 24 GB for 32B models.

01Install the NVIDIA Driver

Log in over SSH and run:

bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y ubuntu-drivers-common
sudo ubuntu-drivers install
sudo reboot

Log in again after a minute and check the card:

bash
nvidia-smi

You should see the card's name and its full memory, for example NVIDIA GeForce RTX 3090 ... 24576MiB. You don't need the CUDA toolkit: Ollama ships its own CUDA libraries. More on drivers in the help center.

02Install Ollama

bash
curl -fsSL https://ollama.com/install.sh | sh

The script installs Ollama as a service, finds the NVIDIA card and starts listening on 127.0.0.1:11434, which means only the server itself can reach it.

03Pull and Test a Model

bash
ollama run llama3.1:8b

The first run downloads the model (about 5 GB), then you can chat in the terminal. Type /bye to leave. In a second SSH window, check where it runs:

bash
ollama ps

The PROCESSOR column should say 100% GPU. If it shows a CPU share, the model is too big for the card; pick a smaller one or a smaller quantisation. Bigger models to try, by card:

CardTry
12 GBllama3.1:8b, qwen2.5:7b, qwen2.5-coder:7b
16 GBqwen2.5:14b, phi4:14b
24 GBmistral-small:24b, qwen2.5:32b, qwen2.5-coder:32b

04Add Open WebUI for a Chat in the Browser

Open WebUI is a ChatGPT-style interface for Ollama. Install Docker, then start it on the host network so it reaches Ollama on localhost:

bash
curl -fsSL https://get.docker.com | sh
sudo docker run -d --network=host \
  -v open-webui:/app/backend/data \
  -e OLLAMA_BASE_URL=http://127.0.0.1:11434 \
  --name open-webui --restart always \
  ghcr.io/open-webui/open-webui:main

It listens on port 8080. Close that port to the outside with the firewall, keeping SSH open:

bash
sudo ufw allow OpenSSH
sudo ufw enable

05Open the Chat Through an SSH Tunnel

On your own computer:

bash
ssh -L 8080:127.0.0.1:8080 root@YOUR_SERVER_IP

Leave that window open and visit http://localhost:8080 in your browser. The first account you create becomes the admin. Pick the model at the top and chat. Everything stays between your computer and your server.

Want to use it from your phone or share it with a team? Put it behind a reverse proxy like Caddy with HTTPS and a login, or use a private network like Tailscale or WireGuard. Don't open port 8080 or 11434 to the internet without a login in front.

06Use It From Your Own Code

Ollama speaks an OpenAI-compatible API, so most libraries work with a changed base URL. Through the same kind of tunnel (ssh -L 11434:127.0.0.1:11434 root@YOUR_SERVER_IP):

python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
reply = client.chat.completions.create(
    model="llama3.1:8b",
    messages=[{"role": "user", "content": "Summarise this in one sentence: ..."}],
)
print(reply.choices[0].message.content)

The key can be any text; Ollama does not check it.

07Keep It Running

  • Ollama and Open WebUI start on their own after a restart: Ollama as a service, Open WebUI through --restart always.
  • Update Ollama by running the install command again.
  • Update Open WebUI with sudo docker pull ghcr.io/open-webui/open-webui:main, then remove and start the container again with the same command. Your chats stay in the open-webui volume.
  • Keep a model loaded between requests with OLLAMA_KEEP_ALIVE=-1 in the service (sudo systemctl edit ollama), so the first answer after a pause doesn't wait for loading.

No. The NVIDIA driver is enough; Ollama ships the CUDA libraries it needs.

  • self host llm
  • ollama gpu server
  • open webui server
  • private chatgpt
  • host llm on gpu server
  • ollama nvidia
  • self hosted ai

Keep reading

All articles