How to beginner · 3 min read

How to run Gemma locally

Quick answer
Run Gemma locally by installing the ollama CLI, pulling the gemma model with ollama pull gemma, and then running it via ollama run gemma. This enables local inference without internet dependency.

PREREQUISITES

  • macOS or Linux machine
  • Ollama CLI installed (https://ollama.com/docs/installation)
  • Terminal access
  • Python 3.8+ (optional for scripting)

Setup Ollama CLI

Install the ollama CLI to manage and run local AI models like Gemma. Visit Ollama installation guide for platform-specific instructions.

On macOS, you can install via Homebrew:

bash
brew install ollama
output
==> Downloading ollama...
==> Installing ollama...
==> Installation successful

Step by step to run Gemma locally

After installing ollama, pull the gemma model and run it locally using the CLI.

bash
ollama pull gemma
ollama run gemma --prompt "Hello, Gemma!"
output
Pulling gemma model...
Model gemma downloaded successfully.
Gemma: Hello, Gemma! How can I assist you today?

Using Gemma in Python scripts

You can invoke the local gemma model from Python by calling the ollama CLI via subprocess. This allows integration into your Python projects.

python
import subprocess

prompt = "Write a short poem about spring."
result = subprocess.run(['ollama', 'run', 'gemma', '--prompt', prompt], capture_output=True, text=True)
print(result.stdout.strip())
output
Gemma: Spring whispers softly, blooms awake anew, colors dance in breeze.

Common variations

  • Use ollama run gemma --interactive for an interactive chat session.
  • Specify different prompts or input files with --prompt or --file.
  • Run asynchronously in Python using asyncio.create_subprocess_exec.

Troubleshooting

  • If ollama command is not found, ensure it is installed and added to your PATH.
  • If pulling gemma fails, check your internet connection and Ollama account status.
  • For permission errors, run the terminal as administrator or check file system permissions.

Key Takeaways

  • Install Ollama CLI to manage and run Gemma locally without cloud dependency.
  • Use ollama pull gemma to download the model and ollama run gemma to execute it.
  • Invoke Gemma from Python scripts via subprocess for easy integration.
  • Interactive and asynchronous usage options enhance flexibility.
  • Check PATH and permissions if you encounter command or access errors.
Verified 2026-04 · gemma
Verify ↗