Skip to content
Go back

Running Gemma 4 Locally with Ollama

By SumGuy 7 min read
Running Gemma 4 Locally with Ollama

Google finally shipped an open model that doesn’t feel like a compromise. Gemma 4 is here, and if you’ve got a spare 8GB of VRAM and Ollama installed, you’re about thirty seconds away from having a genuinely competent AI assistant running entirely on your own hardware. No API calls, no phone-home telemetry, no waiting for rate limits to cool down at 2 AM.

This is the sweet spot you’ve been waiting for.

What Is Gemma 4, Anyway?

Gemma is Google’s family of open-source models, and Gemma 4 is their latest iteration. Unlike their previous releases, which always felt like they were playing catch-up, Gemma 4 actually trades blows with Llama 4 and Qwen 3 on most benchmarks. The 12B variant is the Goldilocks zone: smart enough to handle reasoning and coding, small enough to fit comfortably on gaming hardware.

Gemma 4 is natively multimodal, which means you can feed it images and get analysis back. No separate vision model required—the same model handles text and images (and short video clips) in one go.

The kicker? It’s genuinely open. No weird licensing gotchas. No “research use only” asterisks. You run it however you want.

Hardware: What Do You Actually Need?

Here’s the breakdown, and I’ll be straight with you—these are the numbers that matter:

The numbers assume you’re using 4-bit quantization (Q4_K_M in GGUF parlance), which is the default. Full precision will eat more VRAM—we’re not going there today.

CPU inference is possible but glacially slow. You want GPU acceleration here. If you don’t have one, Ollama can still run it on CPU, but you’ll be waiting 3–5 seconds per token. Not fun for actual work.

Getting Gemma 4 Running: Three Commands

Install Ollama if you haven’t already (it’s at ollama.com). Then:

Terminal window
ollama pull gemma4:12b

That pulls the 12B variant. Ollama’s naming is straightforward: smaller models get smaller tags. If you want the dense flagship, use gemma4:31b; the MoE one is gemma4:26b. Vision works out of the box—Gemma 4 is multimodal, so there’s no separate vision tag to pull.

Once it’s downloaded (this’ll take a few minutes depending on your bandwidth), run it:

Terminal window
ollama run gemma4:12b

You’re now in an interactive session. Type prompts, get responses. It’s that simple.

The Comparison: How Does It Stack Up?

I ran the same prompt through Gemma 4 26B, Llama 4, and Qwen 3. Here’s what I found:

Coding: Gemma 4 26B keeps pace with the bigger models on most tasks. For Python and TypeScript, it’s solid. C++ gets a little fuzzy, but nothing catastrophic. Qwen 3 still edges it out slightly on math-heavy logic problems.

Instruction following: Gemma 4 is absurdly good at parsing weird requests and getting the intent right. It respects constraints better than the others—if you tell it to keep an answer under 100 words, it actually does.

Reasoning: Here’s where the heavier models still have the edge. Gemma 4 26B is competent but won’t win shootouts on chain-of-thought problems. It’s still better than most models in its weight class though.

Speed: The 26B is a mixture-of-experts model—only about 4B params fire per token—so it generates responses fast. You’ll notice it in real use—tighter feedback loop.

The real story: Gemma 4 26B is the model you actually run and use. The big 70B-plus models are the ones you dream about but can’t afford the VRAM for. Gemma wins on practicality.

Actually Using It: Three Paths

Path 1: Interactive CLI (What We Just Did)

Terminal window
ollama run gemma4:12b
>>> Write me a Python function that validates email addresses without regex.

Instant responses, no setup. Good for quick questions and learning.

Path 2: Open WebUI (The Comfortable Option)

Open WebUI is a Ollama-compatible web interface. Install it, point it at your local Ollama server, and you get a ChatGPT-like interface.

Terminal window
docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway \
ghcr.io/open-webui/open-webui:latest

Visit http://localhost:3000, select gemma4:12b, and you’ve got a web UI. Conversation history, message editing, everything you’d expect. This is how I actually use it day-to-day.

Path 3: API Calls (The Programmatic Route)

Ollama exposes a REST API on port 11434. You can curl it:

Terminal window
curl http://localhost:11434/api/generate -d '{
"model": "gemma4:12b",
"prompt": "Explain Docker volumes in one paragraph",
"stream": false
}'

The stream: false flag waits for the full response. If you want it token-by-token (useful for real-time UIs), set stream: true and parse the JSONL output.

Multimodal: Feeding It Images

Since Gemma 4 is multimodal out of the box, you can pass base64-encoded images to the same model:

Terminal window
curl http://localhost:11434/api/generate -d '{
"model": "gemma4:12b",
"prompt": "What is in this image?",
"images": ["iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="],
"stream": false
}'

That’s a 1x1 PNG encoded as base64. In practice, you’d read your actual image, run it through base64, and pass it. The model will describe what it sees. It’s not perfect—don’t expect it to OCR a spreadsheet—but for general image understanding, it works.

Customizing It: Modelfile Magic

You can customize Gemma 4’s behavior with a Modelfile. Create a file called Modelfile (no extension):

Modelfile
FROM gemma4:12b
SYSTEM You are a helpful coding assistant specializing in Python and Go. Be direct and concise. Avoid fluff.
PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER num_ctx 32768

That last line bumps the context window well past Ollama’s modest 4096-token default—Gemma 4 supports up to 256K, so set num_ctx to whatever your VRAM can stomach. Now build it:

Terminal window
ollama create my-gemma4 -f Modelfile
ollama run my-gemma4

You’ve now got a custom version with a tailored system prompt and higher context length. Useful for specialized tasks.

What to Expect: Real-World Feel

Gemma 4 27B will give you responses that feel natural and informed. It won’t hallucinate wildly. It handles edge cases better than you’d expect from a 27B model. When it doesn’t know something, it actually says so instead of confidently making stuff up.

For personal projects, coding help, writing, and research—it’s legitimately competent. You’re not making do with a compromise. You’re getting genuine AI capability running entirely on your own hardware, no phone home, no API bills, no waiting for the provider’s servers to cool down.

That’s worth the modest VRAM investment.

One Last Thing

Ollama has a health-check endpoint at http://localhost:11434/api/tags that lists what models you’ve got loaded. Useful for scripting and monitoring. And if you want to serve it on your network instead of just localhost, use:

Terminal window
OLLAMA_HOST=0.0.0.0:11434 ollama serve

Now any machine on your network can hit your local LLM. Welcome to your own private AI infrastructure.

Pull Gemma 4, run it tonight, and remember: this used to require a six-figure server budget. Now it just requires patience for the download.


Share this post on:

Send a Webmention

Written about this post on your own site? Send a webmention and it'll show up above once verified.


Previous Post
De-Googling: Self-Hosted Replacements for Google Apps
Next Post
1-Bit LLMs: The Quantization Endgame

Discussion

Powered by Garrul . Sign in with GitHub or Google, or post anonymously.

Related Posts