How to Install and Run Gemma 4 on Ubuntu 26.04 and 24.04

Share

To run Gemma 4 on Ubuntu 26.04 or 24.04, install Ollama and choose a model size from the table below. If you already have Ollama and your machine can run E4B, use ollama run gemma4 to download it and start chatting. Canonical’s Gemma 4 snap is the shorter setup if you want built-in terminal and browser chat.

Before you begin

Check memory with free -h and free disk space with df -h. Getting a GPU ready? Use our NVIDIA CUDA and AMD ROCm guide to verify GPU detection and driver support.

Gemma 4 size and hardware picker
Ollama tag Model Download Max context Where to start
gemma4:e2b Effective 2B 4.6 GB 128K 8 GB RAM CPU laptop
gemma4:e4b Effective 4B, also latest 6.6 GB 128K 16 GB RAM or 8 GB VRAM. On 8 GB RAM, start with E2B.
gemma4:12b 12B Unified 8.0 GB 256K 16 GB RAM or 12 GB VRAM
gemma4:26b 26B A4B mixture of experts 19 GB 256K 24 GB VRAM or 32 GB RAM. Expect partial CPU offload on 16 GB VRAM.
gemma4:31b 31B dense flagship 20 GB 256K 24 GB+ VRAM or 32 GB+ RAM with a short context

Downloads take disk space. The RAM and VRAM figures are practical starting points for short contexts. Ubuntu, the inference runtime and the context cache all need headroom. The 26B model activates about 3.8B parameters per token, which helps generation speed. Its full set of weights still needs to fit across GPU and system memory.

Ollama also lists Google’s quantization-aware trained (QAT) variants: gemma4:e2b-it-qat (4.3 GB), gemma4:e4b-it-qat (6.1 GB), gemma4:12b-it-qat (7.2 GB), gemma4:26b-a4b-it-qat (16 GB), gemma4:31b-it-qat (19 GB). Leave headroom even with a smaller download.

Install and run Gemma 4 with Ollama

Step 1. Install or update Ollama

On a fresh Ubuntu system, run the official Linux installer and check the installed version. If you already have Ollama, update through the method you used to install it.

Ubuntu terminal
curl -fsSL https://ollama.com/install.sh | sh
ollama --version

If the CLI cannot reach the server, check systemctl status ollama. Our Ollama on Ubuntu guide covers systemd, manual installation and Docker.

Step 2. Pick your model and check CPU or GPU placement

The first run downloads E4B, then opens the chat prompt. Ask it to explain the difference between RAM and disk space in two sentences.

Ubuntu terminal
ollama run gemma4

Use a specific tag to choose another size. On an 8 GB RAM laptop, substitute gemma4:e2b. For 12B, run the command below. All five tags in the picker work here.

Ubuntu terminal
ollama run gemma4:12b

While the model is loaded, open a second terminal and check where it is running.

Ubuntu terminal
ollama ps

Read PROCESSOR for CPU, GPU or a split and CONTEXT for the current allocation. Use /bye at the chat prompt to return to the shell.

Ollama’s interactive chat enables thinking for Gemma 4. Use /set think for a reasoning trace or /set nothink for a quicker answer. API requests can set "think": true or "think": false.

Step 3. Analyze a local image and open a chat UI

Save a PNG as image.png in your current folder. A JPG works too when you update the path. Inside the Gemma 4 chat prompt, enter the image path and a question.

Ollama chat prompt
./image.png Describe the main subject and one visible detail.

For the same test over HTTP, run this in Bash. GNU base64 -w 0 image.png keeps the encoded image on one line so it fits in a JSON string. The request reads the payload from standard input and uses "stream": false for one JSON reply.

Ubuntu terminal
(
  image_b64=$(base64 -w 0 image.png) || exit 1
  printf '{"model":"gemma4","messages":[{"role":"user","content":"Describe the main subject and one visible detail.","images":["%s"]}],"stream":false,"think":false}\n' "$image_b64" |
    curl -sS --fail-with-body http://127.0.0.1:11434/api/chat \
      -H 'Content-Type: application/json' --data-binary @-
)

Look for the answer in message.content. Compare the reported detail with the original image.

Open WebUI. In Admin Settings → Connections, add http://127.0.0.1:11434 as the Ollama URL when the two backends share the host network. Then choose your Gemma 4 tag in the model picker. For bridge networking, follow the connection steps in our Open WebUI guide.

LM Studio. For a standalone desktop app, open Discover, search for Gemma 4 and choose a local GGUF that fits. Download it, load it in Chat and attach the image. See LM Studio on Ubuntu for setup.

Run E4B with the Ubuntu Inference Snap

Step 4. Install the Gemma 4 snap and start chatting

Canonical’s strictly confined snap packages the runtime and downloads model components. Check that snap version reports snapd 2.68 or newer. The snap picks an engine and model based on your hardware. This walkthrough follows the E4B route.

Ubuntu terminal
sudo snap install gemma4
gemma4 status
gemma4 chat

Check the model and engine in gemma4 status. For browser chat on the same machine, open http://127.0.0.1:8337. Other sizes are available on compatible engines. Our Ubuntu Inference Snaps guide covers engine selection, SSH forwarding and Inference Manager.

Fix memory and GPU problems

Gemma 4 runs out of memory or starts swapping

Close other GPU-heavy apps and try a short context. At the Ollama chat prompt, set a 4,096-token context for the next request.

Ollama chat prompt
/set parameter num_ctx 4096

For an API request, add "options": {"num_ctx": 4096} at the top level. The 128K and 256K values are model ceilings. Longer contexts need more memory. If a short context still fails, try a smaller model or QAT tag.

Ollama shows CPU or mixed placement

Run a prompt first, then check ollama ps. If weights and context exceed free VRAM, Ollama can move some work to the CPU. Shorten the context or choose a smaller tag. If a small tag still shows 100% CPU, check your GPU drivers and review journalctl -u ollama -n 50 --no-pager for detection errors.

Local chat works but the browser interface cannot connect

Ollama listens on 127.0.0.1:11434 by default. A bridged container has its own loopback address, so use the appropriate connection setup for Open WebUI. To disable Ollama’s cloud models and web search, set OLLAMA_NO_CLOUD=1 in its service environment and restart the service.

Update or remove Gemma 4

Pull the same tag to check for new weights. Use ollama list to check the exact name before removing a tag. Shared files stay on disk while another installed tag uses them.

Ubuntu terminal
ollama pull gemma4:12b
Ubuntu terminal
ollama rm gemma4:12b

Snap updates automatically. To check immediately, use sudo snap refresh gemma4. Save any settings or data you need before removing the snap. The purge skips creation of a new automatic snapshot.

Ubuntu terminal
sudo snap remove --purge gemma4

Frequently asked questions

Do I need a dedicated GPU to run Gemma 4?

No. Start with E2B on an 8 GB RAM machine, keep the context short and expect slower replies on a CPU.

Can I use Gemma 4 offline?

Yes. Download a local Ollama tag or finish installing the snap while online. The model can then answer local prompts offline.

Does Gemma 4 generate images?

No. It accepts images as input and answers with text. You can ask it to describe a photo or read a chart.

Helpful Resources

LocalLLaMA on Reddit Community discussion about running models locally
Ollama Gemma 4 tags Download sizes and quantized model variants
Google’s Gemma 4 model card Architecture, capabilities and context windows

Try another model family with Llama or DeepSeek.