Baraklabs

Running Gemma 4 Locally: Open-Source AI on Your Machine

No API limits. No vendor lock-in. Just pure flexibility. 🚀

The Release of Gemma 4 and Open-Source Freedom

On April 2, 2026, Google released Gemma 4 under the Apache License 2.0. Now this is important. Unlike Gemini 3, which runs only on Google’s servers, Gemma 4 is something you can actually download and run on your own machine.

That means no dependency on external APIs, no per-token pricing, and no restrictions on how you use it. You can fine-tune it, deploy it, and even build and sell products on top of it — all with full commercial freedom. And that’s exactly what makes this release stand out.

Model Variants and Multimodal Capabilities

Google has released four variants of Gemma 4. They are quite flexible, supporting context windows up to 256K tokens (128K for edge models), over 140 languages, and multimodal inputs handling text, images, and even audio.

Edge Models

E2B & E4B: Designed for lighter workloads and more efficient environments. Great for hobby or local use.

26B MoE

Mixture-of-Experts: 26B parameters but only activates ~3.8B during inference. Large scale, mid-sized latency.

31B Dense

The Flagship: Acts as the flagship in terms of quality. Ranks #3 on the LM Arena open-source leaderboard.

Benchmarks vs. The Heavyweights

In terms of coding performance, Gemma 4 performs strongly, but it’s not the absolute leader. Compare that to something like Kimmy K 2.5, which ranks very high in ELO score (human preference).

But here’s the catch: Kimmy K 2.5 is a trillion-parameter class model. To run it properly, you’re looking at clusters of high-end GPUs costing tens of thousands of dollars. Gemma 4 runs entirely within your own infrastructure. No external dependencies, no data leaving your system. For real-world applications, that control often matters more than squeezing out a few extra percentage points in benchmarks.

Local Setup Guide: Ollama and OpenCode

Let’s actually run Gemma 4 locally and see what this looks like in practice.

Step 1: Pull the Model via Ollama

After installing Ollama (ollama.com/download), pull your preferred model based on your hardware (e2b/e4b for 12-16GB RAM, 26B/31B for 20GB+ VRAM):

ollama pull gemma4:e2b
ollama list

Step 2: Connect to OpenCode

Install OpenCode globally (works best on Linux or inside WSL on Windows), then launch it with Ollama:

npm i -g opencode-ai
ollama launch opencode

Step 3: Test & Monitor

Try a prompt like "Write a REST API in Go for a todo app". Monitor context size in the background (aim for 16K or 32K in settings):

ollama ps

Cloud Alternatives & OpenRouter

If you don’t have powerful hardware, you can try the cloud version directly in your terminal:

ollama launch opencode --model gemma4:31b-cloud

Because it’s a shared free tier, it can be slow. Alternatively, you can use OpenRouter without running Ollama at all. Inside OpenCode, type /connect, paste your OpenRouter API key, and select a Gemma 4 free model (like 31B free or 26B A4B free). Keep in mind, free models are rate-limited.

Final Thoughts

If you care about privacy and have a good machine with around 24GB RAM or a strong GPU, running locally is the best experience. You’re running a high-quality, multimodal AI model completely under your control — from infrastructure to deployment to monetization. If you're building AI apps, this is something you should definitely try.

Recommended Blogs