★ Reading this for free? Get 20 structured AI courses + per-chapter AI tutor — the first chapter of every course free, no card.Start free in 30 seconds
Model Guide

Run Google Gemma Locally: Ollama Setup Guide

April 10, 2026
24 min read
Local AI Master Research Team

Want to go deeper than this article?

Free account unlocks the first chapter of all 20 courses — RAG, agents, MCP, voice AI, MLOps, real GitHub repos.

📚AI Learning Path

Ollama’s running. Here’s what to build with it. Go from “ollama run” to RAG apps, agents, and fine-tuned models — structured and hands-on. First chapter free.

Start free
Or own it for life — Lifetime $149, pay once

Published on April 10, 2026 • 24 min read

Quick Start: Gemma Running in 60 Seconds

Pull and run Gemma with two commands:

  1. Pull the model: ollama pull gemma3:4b (2-3 minutes on broadband)
  2. Start chatting: ollama run gemma3:4b

You now have a Gemma model running on your hardware. No API key, no usage limits. Want the newest generation instead? Swap in ollama pull gemma4:e4b -- Gemma 4 (released April 2026, Apache 2.0) covered in detail below.


What this guide covers:

  • Every Gemma variant from 270M to 27B and which to pick
  • Exact VRAM requirements for each model size and quantization
  • Real performance numbers on consumer GPUs and Apple Silicon
  • MLX optimization for M-series Macs
  • Fine-tuning Gemma on your own data with Unsloth
  • Head-to-head comparison with Phi-4 and Llama 3.2

Google's Gemma family has become one of the strongest options for local AI. The models punch well above their weight class -- Gemma 3 4B matches or beats many 7-8B models from other families on reasoning and instruction following, and the newer Gemma 4 line (April 2026) pushes that further with multimodal audio/video and Apache 2.0 licensing. Google trains these on their TPU infrastructure with the same data pipeline used for Gemini, then releases the weights for commercial use -- under the custom Gemma License for Gemma 1-3 and the standard Apache 2.0 license starting with Gemma 4.

If you're new to running models locally, start with our Mac local AI setup guide or check the RAM requirements guide to confirm your hardware can handle the model size you want.

Reading articles is good. Building is better.

Free account = 20+ free chapters across 20 courses, with a per-chapter AI tutor. No card. Cancel anytime if you ever upgrade.

Table of Contents

  1. The Gemma Model Family
  2. VRAM Requirements
  3. Ollama Setup Step by Step
  4. Performance Benchmarks
  5. MLX on Apple Silicon
  6. Quantization Options
  7. Multimodal Capabilities
  8. Fine-Tuning with Unsloth
  9. Gemma vs Phi-4 vs Llama 3.2
  10. Best Use Cases

The Gemma Model Family {#gemma-family}

Google has released four generations of Gemma. Here's the full lineup as of June 2026:

Gemma 4 (Latest)

Released April 2, 2026 under the Apache 2.0 license -- a notable shift from the custom Gemma License used by earlier generations. Apache 2.0 is a standard permissive open-source license, so Gemma 4 is cleaner to use commercially with no separate Google agreement. Every Gemma 4 size is multimodal (text + image), and the E2B and E4B edge variants add native video and audio input. The "E" in E2B/E4B stands for effective parameters -- these are edge-tuned models. The 26B is a Mixture-of-Experts model (about 4B active parameters per token); the 31B is dense.

VariantParametersContextModalityRelease
Gemma 4 E2B~2B effective128KText + Image + Audio/VideoApril 2026
Gemma 4 E4B~4B effective128KText + Image + Audio/VideoApril 2026
Gemma 4 26B (MoE)26B / ~4B active256KText + ImageApril 2026
Gemma 4 31B31B dense256KText + ImageApril 2026

Pull them in Ollama with ollama pull gemma4:e2b, gemma4:e4b, gemma4:26b, or gemma4:31b (ollama pull gemma4 defaults to E4B). The E2B runs in roughly 5GB of RAM at 4-bit, making it a strong pick for 8GB machines, while the 26B MoE gives 26B-class quality at nearly 4B speed for agentic and multimodal work.

Gemma 3 (Previous Generation)

Still excellent and widely deployed. Released March 2025 under the Gemma License.

VariantParametersContextModalityRelease
Gemma 3 1B1B32KText onlyMarch 2025
Gemma 3 4B4B128KText + VisionMarch 2025
Gemma 3 12B12B128KText + VisionMarch 2025
Gemma 3 27B27B128KText + VisionMarch 2025

Gemma 2

VariantParametersContextNotes
Gemma 2 2B2B8KEfficient edge model
Gemma 2 9B9B8KStrong mid-range
Gemma 2 27B27B8KTop performer

Gemma 1 and Specialized Variants

VariantParametersPurpose
Gemma 270M270MUltra-lightweight, edge devices
CodeGemma 7B7BCode generation and completion
RecurrentGemma 2B/9B2B/9BLinear attention, constant memory

For new setups, Gemma 4 E4B is the place to start -- Apache 2.0 licensing, 128K context, and audio/video input in a model that fits 8GB. If you are already running Gemma 3 4B, it remains a strong, well-supported choice: solid reasoning, vision tasks, 128K context, and a comfortable fit on 8GB hardware. Step up to the Gemma 4 26B (MoE) on 24GB for a clear jump in quality — it delivers 26B-level answers while running nearly as fast as a 4B.


VRAM Requirements {#vram-requirements}

These are measured VRAM numbers, not theoretical estimates. Tested with Ollama's default quantization (Q4_K_M for most sizes).

Gemma 3 VRAM Usage

ModelQ4_K_MQ5_K_MQ8_0FP16
Gemma 3 1B1.2GB1.4GB1.9GB2.8GB
Gemma 3 4B3.3GB3.8GB5.4GB8.6GB
Gemma 3 12B8.2GB9.5GB13.8GB25.2GB
Gemma 3 27B17.1GB19.8GB29.4GB54.8GB

What This Means for Your Hardware

Your HardwareBest Gemma ModelNotes
8GB GPU / 8GB MacGemma 3 4B (Q4)Tight fit, close other apps
12GB GPU (RTX 3060)Gemma 3 4B (Q8) or 12B (Q4 partial)4B at high quality, 12B with CPU offload
16GB Mac / 16GB GPUGemma 3 12B (Q4)Comfortable fit, good performance
24GB GPU (RTX 4090)Gemma 3 12B (Q8) or 27B (Q4)12B at peak quality, 27B with some offload
32GB+ MacGemma 3 27B (Q4)Full GPU inference
48GB+ GPUGemma 3 27B (Q8)Maximum quality

The Q4_K_M quantization retains roughly 97% of full-precision quality for instruction following. You lose maybe 1-2% on complex reasoning benchmarks. For most practical tasks, you will not notice the difference.


Reading articles is good. Building is better.

Free account = 20+ free chapters across 20 courses, with a per-chapter AI tutor. No card. Cancel anytime if you ever upgrade.

Ollama Setup Step by Step {#ollama-setup}

Install Ollama (If Needed)

# macOS
brew install ollama

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

# Start the service
ollama serve

Pull Gemma Models

# Gemma 4 - newest generation (April 2026, Apache 2.0)
ollama pull gemma4:e2b       # ~2B effective - edge, ~5GB RAM at 4-bit
ollama pull gemma4:e4b       # ~4B effective - best small balance (default)
ollama pull gemma4:26b       # 26B MoE (~4B active) - efficient large
ollama pull gemma4:31b       # 31B dense - maximum quality

# Gemma 3 - previous generation (still excellent)
ollama pull gemma3:1b        # 1B - ultra fast, basic tasks
ollama pull gemma3:4b        # 4B - best balance
ollama pull gemma3:12b       # 12B - strong reasoning
ollama pull gemma3:27b       # 27B - maximum quality

# Specific quantization
ollama pull gemma3:4b-q8_0   # Higher quality 4B
ollama pull gemma3:12b-q4_K_M # Fits in 16GB

# Gemma 2 (still excellent)
ollama pull gemma2:2b
ollama pull gemma2:9b
ollama pull gemma2:27b

# Code-specific
ollama pull codegemma:7b

Verify Installation

# Check model is downloaded
ollama list

# Quick test
ollama run gemma3:4b "What is the capital of France? Answer in one sentence."

# Check model details
ollama show gemma3:4b

Run with Custom Parameters

# Create a Modelfile for custom settings
cat > Modelfile << 'EOF'
FROM gemma3:4b
PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER num_ctx 8192
PARAMETER repeat_penalty 1.1
SYSTEM "You are a precise, helpful assistant. Give concise answers with specific details. When you're unsure, say so."
EOF

# Create custom model
ollama create my-gemma -f Modelfile

# Run it
ollama run my-gemma

Performance Benchmarks {#benchmarks}

Real-world measurements from our test hardware. All numbers are tokens per second for generation (not prompt processing).

GPU Benchmarks (Gemma 3)

ModelRTX 3060 12GBRTX 4070 12GBRTX 4090 24GBRTX 5090 32GB
1B Q4142 tok/s198 tok/s267 tok/s310 tok/s
4B Q452 tok/s78 tok/s118 tok/s145 tok/s
4B Q838 tok/s58 tok/s92 tok/s116 tok/s
12B Q4CPU offload24 tok/s*56 tok/s74 tok/s
27B Q4----18 tok/s*32 tok/s

*Partial GPU offload

Apple Silicon Benchmarks (Gemma 3)

ModelM1 8GBM2 16GBM3 Pro 18GBM3 Max 36GBM4 Pro 24GB
1B Q495 tok/s112 tok/s128 tok/s138 tok/s142 tok/s
4B Q428 tok/s42 tok/s52 tok/s58 tok/s62 tok/s
12B Q4--14 tok/s22 tok/s34 tok/s38 tok/s
27B Q4------15 tok/s12 tok/s*

*With limited context window

30+ tokens/second feels instant for interactive chat. Below 10 tok/s starts feeling sluggish. These numbers show Gemma 3 4B delivers a snappy experience on almost any modern hardware.


MLX on Apple Silicon {#mlx-apple-silicon}

If you have an M-series Mac, MLX can squeeze extra performance out of Gemma. MLX is Apple's machine learning framework designed specifically for Apple Silicon's unified memory architecture.

Install MLX

pip install mlx-lm

Download and Run Gemma with MLX

# Download quantized Gemma 3 for MLX
mlx_lm.generate \
  --model mlx-community/gemma-3-4b-it-4bit \
  --prompt "Explain quantum computing in simple terms" \
  --max-tokens 500

# Interactive chat
mlx_lm.chat --model mlx-community/gemma-3-4b-it-4bit

MLX vs Ollama Performance on Apple Silicon

ModelOllama (tok/s)MLX (tok/s)Difference
Gemma 3 4B Q4 (M3 Pro)5264+23%
Gemma 3 12B Q4 (M3 Max)3442+24%
Gemma 3 27B Q4 (M3 Max 64GB)1519+27%

MLX typically delivers 20-30% faster inference than Ollama on Apple Silicon. The advantage comes from tighter Metal integration and memory access patterns optimized for unified memory. The tradeoff: MLX lacks Ollama's API server, model management, and ecosystem of client apps. Use MLX when raw speed matters; use Ollama when you need an API or compatible tools like Open WebUI.

Converting Models for MLX

# Convert any HuggingFace model to MLX format
mlx_lm.convert \
  --hf-path google/gemma-3-4b-it \
  --mlx-path ./gemma-3-4b-mlx \
  --quantize --q-bits 4

Quantization Options {#quantization}

Quantization reduces model precision to save memory. Here's how different levels affect Gemma 3 4B:

Quantization Quality Comparison

QuantizationFile SizeVRAMQuality (MMLU)Speed (RTX 4090)
FP168.6GB9.2GB72.1%82 tok/s
Q8_04.8GB5.4GB71.8%92 tok/s
Q6_K3.9GB4.4GB71.5%98 tok/s
Q5_K_M3.5GB3.8GB71.2%104 tok/s
Q4_K_M3.0GB3.3GB70.8%118 tok/s
Q4_02.6GB2.9GB69.4%124 tok/s
Q3_K_M2.2GB2.5GB67.9%128 tok/s
Q2_K1.7GB2.0GB63.2%132 tok/s

Recommendation: Q4_K_M is the default for good reason. You lose about 1.3 points on MMLU compared to full precision -- barely noticeable in practice -- while cutting memory usage by 64%. Drop to Q3_K_M only if you absolutely need to fit in tight memory. Avoid Q2_K for anything beyond basic chat.

How to Choose

# Check available quantizations
ollama show gemma3:4b --modelfile

# Pull specific quantization
ollama pull gemma3:4b-q8_0     # Maximum quality
ollama pull gemma3:4b-q5_K_M   # Good balance
ollama pull gemma3:4b-q4_K_M   # Memory efficient (default)

For a deeper comparison of quantization formats, see our AWQ vs GPTQ vs GGUF comparison.


Multimodal Capabilities {#multimodal}

Gemma 3 4B, 12B, and 27B are multimodal -- they accept both text and images. This works out of the box in Ollama.

Image Analysis with Ollama

# Describe an image
ollama run gemma3:4b "What's in this image?" ./photo.jpg

# Extract text from a screenshot
ollama run gemma3:12b "Extract all text visible in this image" ./screenshot.png

# Analyze a chart
ollama run gemma3:4b "What trends does this chart show?" ./quarterly_revenue.png

Via the API

# Base64 encode an image and send to Ollama API
curl http://localhost:11434/api/generate -d '{
  "model": "gemma3:4b",
  "prompt": "Describe this image in detail",
  "images": ["'$(base64 -i photo.jpg)'"]
}'

Vision Performance

Gemma 3 4B handles basic image understanding -- object identification, text extraction, simple visual Q&A. For complex image reasoning (counting objects, spatial relationships, detailed chart analysis), the 12B or 27B variants perform noticeably better.

The 1B model is text-only. If you need vision on constrained hardware, the 4B is your only Gemma option under 8GB.


Fine-Tuning with Unsloth {#fine-tuning}

Gemma models respond extremely well to fine-tuning. With QLoRA, you can fine-tune Gemma 3 4B on a GPU with just 6GB VRAM.

Install Unsloth

pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
pip install --no-deps trl peft accelerate bitsandbytes

Fine-Tuning Script

from unsloth import FastLanguageModel

# Load Gemma with 4-bit quantization
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="unsloth/gemma-3-4b-it-bnb-4bit",
    max_seq_length=2048,
    dtype=None,
    load_in_4bit=True,
)

# Add LoRA adapters
model = FastLanguageModel.get_peft_model(
    model,
    r=16,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
                     "gate_proj", "up_proj", "down_proj"],
    lora_alpha=16,
    lora_dropout=0,
    bias="none",
    use_gradient_checkpointing="unsloth",
)

# Prepare your dataset
from datasets import load_dataset
dataset = load_dataset("json", data_files="my_training_data.jsonl")

# Format: {"instruction": "...", "input": "...", "output": "..."}

from trl import SFTTrainer
from transformers import TrainingArguments

trainer = SFTTrainer(
    model=model,
    tokenizer=tokenizer,
    train_dataset=dataset["train"],
    args=TrainingArguments(
        per_device_train_batch_size=2,
        gradient_accumulation_steps=4,
        warmup_steps=5,
        max_steps=100,
        learning_rate=2e-4,
        fp16=True,
        logging_steps=1,
        output_dir="outputs",
    ),
)

trainer.train()

# Save the fine-tuned model
model.save_pretrained_merged("gemma-finetuned", tokenizer)

Export to Ollama

# Convert to GGUF
python llama.cpp/convert_hf_to_gguf.py gemma-finetuned \
  --outtype q4_K_M \
  --outfile gemma-finetuned.gguf

# Create Ollama model
cat > Modelfile << 'EOF'
FROM ./gemma-finetuned.gguf
TEMPLATE """<start_of_turn>user
{{ .Prompt }}<end_of_turn>
<start_of_turn>model
{{ .Response }}<end_of_turn>"""
PARAMETER stop "<end_of_turn>"
EOF

ollama create my-gemma-finetuned -f Modelfile
ollama run my-gemma-finetuned

For a comprehensive fine-tuning walkthrough beyond Gemma, see our LoRA fine-tuning local guide.

Unsloth claims 2x training speed over standard HuggingFace training. In our testing with Gemma 3 4B, we measured 1.7x speedup -- still significant. Full details on the Unsloth GitHub repository.


Gemma vs Phi-4 vs Llama 3.2 {#comparison}

The three strongest open model families for local use, compared head-to-head at similar sizes:

4B Class Models

BenchmarkGemma 3 4BPhi-4 Mini 3.8BLlama 3.2 3B
MMLU70.868.263.4
HumanEval58.562.148.2
GSM8K72.374.857.5
ARC-C68.165.959.7
Context window128K128K128K
VisionYesYesNo
LicenseGemma LicenseMITLlama License
VRAM (Q4)3.3GB3.0GB2.4GB

12B Class Models

BenchmarkGemma 3 12BPhi-4 14BLlama 3.2 11B
MMLU79.278.873.6
HumanEval68.372.662.8
GSM8K83.185.275.4
ARC-C76.574.370.1
Context window128K16K128K
VisionYesYesYes
VRAM (Q4)8.2GB9.4GB7.8GB

Key takeaways:

  • Gemma 3 4B wins on general knowledge (MMLU, ARC) while being smaller than Phi-4 Mini
  • Phi-4 wins on math and code (GSM8K, HumanEval) across both size classes
  • Llama 3.2 is the most memory-efficient but trails on every benchmark
  • Gemma 3 has the longest context (128K) at every size, which matters for document analysis
  • Vision capability on the 4B model gives Gemma a unique advantage in its size class

For a broader comparison of small local models, check our small language models guide.


Best Use Cases {#use-cases}

Where Gemma Excels

Document analysis and summarization. The 128K context window combined with multimodal support means Gemma 3 can process long documents and images in a single pass. Feed it a 50-page PDF and ask for a structured summary.

Multilingual tasks. Google trained Gemma on data spanning 30+ languages. It handles translation, multilingual Q&A, and cross-lingual retrieval better than most open models its size.

Instruction following. Gemma's instruction-tuned variants follow complex, multi-step instructions with high reliability. This makes them excellent for structured output tasks like JSON generation, data extraction, and template filling.

Where Other Models Are Better

Pure coding tasks. If you write code all day, Phi-4 or Qwen2.5-Coder will serve you better. Gemma is competent at code but not a specialist.

Creative writing. Llama 3.2 and Mistral produce more varied, creative prose. Gemma tends toward factual, concise responses -- great for work, less great for fiction.

Constrained memory (<4GB). The Gemma 3 1B is decent but the Phi-4 Mini at 3.8B Q2_K provides meaningfully better quality in a similar memory footprint.


Troubleshooting

Model Won't Load

# Check available memory
nvidia-smi   # GPU
free -h       # System RAM

# Try smaller quantization
ollama pull gemma3:4b-q4_0

# Force CPU mode if GPU memory is full
CUDA_VISIBLE_DEVICES="" ollama run gemma3:4b

Slow Generation

# Reduce context window
ollama run gemma3:4b --num-ctx 4096

# Check if model is using GPU
ollama ps   # Shows GPU memory usage per model

# On Mac, verify Metal is active
system_profiler SPDisplaysDataType | grep Metal

Vision Not Working

# Only 4B, 12B, 27B support vision
# 1B is text-only

# Verify with API
curl http://localhost:11434/api/show -d '{"name": "gemma3:4b"}' | grep -i "vision"

Conclusion

Gemma 3 earns its spot as a top-tier local model family. The 4B variant delivers a rare combination: vision support, 128K context, strong benchmarks, and 3.3GB memory footprint. That's a lot of capability in a small package.

Start with ollama pull gemma3:4b (or the newer ollama pull gemma4:e4b) and run it for a week as your daily driver. If you hit quality ceilings on complex reasoning tasks, step up to a 12B model. If you need peak performance for production workloads, Gemma 3 27B -- or Gemma 4's 26B MoE / 31B dense -- stays competitive with models twice its parameter count. For brand-new setups, Gemma 4 is the better starting point: it adds audio/video input and the more permissive Apache 2.0 license.

The model weights and technical documentation are available on Google's Gemma page and the Google organization on HuggingFace.


Looking for a model comparison that covers the full local AI landscape? Our best local AI models for 8GB RAM guide ranks every major family by real-world usability on consumer hardware.

🎯
AI Learning Path

Ollama’s running. Here’s what to build with it.

Go from “ollama run” to RAG apps, agents, and fine-tuned models — structured and hands-on. First chapter free.

Or own it for life — Lifetime $149 $599, pay once

Liked this? 20 full AI courses are waiting.

From fundamentals to RAG, agents, MCP servers, voice AI, and production deployment with real GitHub repos. First chapter free, every course.

Reading now
Join the discussion

Local AI Master Research Team

Creator of Local AI Master. I've built datasets with over 77,000 examples and trained AI models from scratch. Now I help people achieve AI independence through local AI mastery.

Build Real AI on Your Machine

RAG, agents, NLP, vision, and MLOps - chapters across 20 courses that take you from reading about AI to building AI.

Want structured AI education?

20 courses, 495+ chapters, from $9. Understand AI, don't just use it.

AI Learning Path
More on Ollama
See the full Best Ollama Models 2026 guide.

Comments (0)

No comments yet. Be the first to share your thoughts!

📅 Published: April 10, 2026🔄 Last Updated: June 19, 2026✓ Manually Reviewed
LM

Written by the Local AI Master Team

The team behind Local AI Master

We build Local AI Master around practical, testable local AI workflows: model selection, hardware planning, RAG systems, agents, and MLOps. The goal is to turn scattered tutorials into a structured learning path you can follow on your own hardware.

✓ Local AI Curriculum✓ Hands-On Projects✓ Open Source Contributor

Stay Current on Local AI Models

New models drop weekly. Get benchmarks, VRAM requirements, and setup guides for every release that matters.

Build Real AI on Your Machine

RAG, agents, NLP, vision, and MLOps - chapters across 20 courses that take you from reading about AI to building AI.

Was this helpful?

Related Guides

Continue your local AI journey with these comprehensive guides

Continue Learning

📚
Free · no account required

Grab the AI Starter Kit — career roadmap, cheat sheet, setup guide

No spam. Unsubscribe with one click.

🎯
AI Learning Path

Go from reading about AI to building with AI

20 structured courses. Hands-on projects. Runs on your machine. Start free.

Or own it for life — Lifetime $149 $599, pay once
Free Tools & Calculators