How to Run Gemma 4 Locally with Ollama and LM Studio (e2b on 8 GB, 12B on 12–16 GB)

Cover image for How to Run Gemma 4 Locally with Ollama and LM Studio (e2b on 8 GB, 12B on 12–16 GB): Screenshot: Google: Run Gemma with Ollama - Gemma Docs

Key facts

Sources checked Nov 19, 2026

  • Gemma 4 is Google DeepMind’s open model family for local use: text and image in, text out, with reasoning modes and native tool calling. Official install paths are documented for Ollama and LM Studio.
  • Ollama tags, with download sizes from Google’s Gemma docs: gemma4:e2b 7.2 GB (128K context), gemma4:e4b 9.6 GB (128K), gemma4:12b 7.6 GB (256K), gemma4:26b 18 GB (256K, MoE with about 4B active), gemma4:31b 20 GB (256K, dense). gemma4:latest is an alias for e4b.
  • On an 8 GB GPU, start with gemma4:e2b. The e4b download is 9.6 GB in Google’s table, which already does not fit in 8 GB of VRAM. The 12B tag is listed at 7.6 GB, so it may load but will be tight once you add context. This guide follows official docs and has not been timed on an RTX 5060 Ti 8 GB.
  • Ollama’s library page shows size ranges (for example e2b 4.6–7.5 GB, e4b 6.6–9.5 GB) because more than one quant is published. When the two pages disagree, size the file you actually pulled (ollama list) and leave room for the KV cache.

Requirements Start with gemma4:e2b on 8 GB VRAM. e4b is listed at 9.6 GB and will not fit in 8 GB. Not hardware-tested on an RTX 5060 Ti 8 GB. Commands from official Gemma and Ollama docs.

Gemma 4 is one of the more complete open families you can run at home: small edge MoEs, a 12B workstation model, a 26B MoE and a 31B dense model, all with official Ollama and LM Studio instructions. This guide gets you from install to a first chat and a local API.

Params2.3B–30.7B (family)
LicenseGemma Terms of Use
VRAM8–24 GB+ depending on tag
Context128K–256K

Pick a size that fits

Google’s Ollama page publishes this table:

Tag Download (Gemma docs) Context What it is
gemma4:e2b 7.2 GB 128K Edge model, ~2.3B effective parameters (5.1B with embeddings)
gemma4:e4b 9.6 GB 128K Edge model, ~4.5B effective (8B with embeddings). Default latest
gemma4:12b 7.6 GB 256K Dense workstation model
gemma4:26b 18 GB 256K MoE, 25.2B total / 3.8B active
gemma4:31b 20 GB 256K Dense, 30.7B

Parameter counts and architecture notes are from the Ollama model page readme. E2B and E4B also have official audio input in the model card; Ollama’s Gemma docs say Ollama publishes Gemma 4 as text and image only, and that you should use Transformers or llama.cpp for audio.

On Apple Silicon, -mlx tags such as gemma4:12b-mlx use the MLX runtime.

Bar chart of official Gemma 4 Ollama download sizes: e2b 7.2 GB, e4b 9.6 GB, 12b 7.6 GB, 26b 18 GB, 31b 20 GB.
Gemma 4 download sizes from Google’s Ollama documentation. An 8 GB line is marked for reference; chart by aimodels.blog.

Install and run with Ollama

Download Ollama from ollama.com/download, then check it:

ollama --version

For an 8 GB-class machine, start with the edge model:

ollama run gemma4:e2b "Explain quantization in one paragraph."

To fetch without chatting, use ollama pull gemma4:e2b. On a 12–16 GB GPU, gemma4:12b is the tag Google uses in its own examples:

ollama run gemma4:12b "Explain quantum computing simply"

Images go on the command line as a file path:

ollama run gemma4:12b ./image.png "What is in this image?"

Ollama serves on port 11434. A minimal OpenAI-compatible call, from the Gemma docs:

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:11434/v1/",
    api_key="ollama",
)

response = client.chat.completions.create(
    model="gemma4:e2b",
    messages=[{"role": "user", "content": "Say this is a test"}],
)
print(response.choices[0].message.content)

Context is not automatic. Ollama sizes context from available VRAM, and the Gemma docs warn that it defaults to 4K under 24 GiB VRAM. Raise it when you need it:

OLLAMA_CONTEXT_LENGTH=64000 ollama serve

Or pass "options": {"num_ctx": 64000} on the request. Agents and coding tools will want much more than 4K. Our Ollama settings guide covers the other knobs.

LM Studio

Download the app from lmstudio.ai/download. In the UI, press Cmd+Shift+M (macOS) or Ctrl+Shift+M (Windows/Linux), search for “Gemma”, and take the variant it recommends for your hardware.

From the terminal, Google’s documented commands are:

lms get google/gemma-4-12b
lms ls
lms load <model_key>

lms load accepts --gpu=max|auto|0.0-1.0 and --context-length. Then start the server:

lms server start

The OpenAI-compatible API is http://localhost:1234/v1. Point the same Python client at that base URL, with api_key="lm-studio" and model="google/gemma-4-12b" (or the key lms ls printed). See also our LM Studio setup guide.

Settings and gotchas

The Ollama readme’s recommended sampling for Gemma 4 is temperature 1.0, top_p 0.95, top_k 64. That is hotter than many local defaults. If answers look rambling, change one variable at a time rather than copying settings from a different family.

Thinking is controlled in the chat template. The readme says you enable thinking by putting a <|think|> token at the start of the system prompt, and you should not feed previous thought blocks back into the history — only the final answer. Ollama is supposed to handle the template for you; if you build raw prompts, follow that rule.

For multimodal prompts, put the image before the text. The model also supports a visual token budget (70, 140, 280, 560, 1120) for how many tokens an image uses. Use a lower budget for captioning, a higher one for OCR.

Vendor benchmark tables (MMLU Pro, AIME 2026, LiveCodeBench, GPQA Diamond, and others) are on the Ollama model page. They are Google’s reported instruction-tuned results, not our runs.

Watch: a local-setup deep dive

Kubesimplify’s Gemma 4 deep dive: running it locally with Ollama, vLLM and llama.cpp (May 2026).

Bottom line

On 8 GB, pull gemma4:e2b and raise context only as far as VRAM allows. On 12–16 GB, gemma4:12b is the official example tag. Leave e4b, 26B and 31B for machines that can hold them. Use Ollama or LM Studio’s documented commands, keep Gemma 4’s sampling defaults in mind, and do not trust the 128K or 256K window until you have set num_ctx yourself.

Sources: Run Gemma with Ollama, Run Gemma with LM Studio, Ollama library: gemma4. This guide was not hardware-tested on an RTX 5060 Ti 8 GB. Facts checked November 19, 2026.

Cover image: screenshot of Google: Run Gemma with Ollama – Gemma Docs