RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /How-to
  5. /How to set Ollama environment variables
HOW-TO · SET

How to set Ollama environment variables

intermediate·10 min·By Eruo Fredoline
Target environment
Ubuntu 24.04 · Ollama 0.4.xWindows 11 · Ollama 0.4.xmacOS 15 · Ollama 0.4.x
PREREQUISITES

Ollama installed, system administrator or root access, and familiarity with shell environment configuration.

What this does

Environment variables control Ollama's runtime behavior, including model storage paths, GPU usage, logging verbosity, and API binding. This guide configures common variables persistently so they survive service restarts and reboots.

Steps

  1. Identify the relevant environment variable. Common variables include OLLAMA_HOST, OLLAMA_MODELS, OLLAMA_NUM_PARALLEL, OLLAMA_MAX_LOADED_MODELS, and OLLAMA_LOG_LEVEL.

  2. Create a systemd drop-in override for persistent service configuration on Linux. This ensures variables persist across reboots and service restarts.

    sudo systemctl edit ollama
    

    Expected output: An editor opens with an empty override file.

  3. Add the desired environment variables inside the override block. This example sets a custom model directory, parallel request limit, and log level.

    [Service]
    Environment="OLLAMA_MODELS=/mnt/storage/ollama-models"
    Environment="OLLAMA_NUM_PARALLEL=2"
    Environment="OLLAMA_LOG_LEVEL=info"
    

    Save and exit the editor.

  4. Reload the systemd configuration and restart the service.

    sudo systemctl daemon-reload
    sudo systemctl restart ollama
    

    Expected output: No error output; service restarts with the new variables applied.

  5. On macOS, use a launchd environment configuration file instead.

    sudo launchctl config system OLLAMA_MODELS /Volumes/External/ollama-models
    sudo launchctl kickstart -k ai.ollama.ollama
    

    Expected output: Configuration applied; service restarts.

Verification

systemctl show ollama --property Environment
# Expected: Environment="OLLAMA_MODELS=/mnt/storage/ollama-models" "OLLAMA_NUM_PARALLEL=2" "OLLAMA_LOG_LEVEL=info"

Common failures

  • Variables not applied after restart — Override file syntax error. Run systemctl cat ollama to inspect actual loaded configuration.
  • Model storage path change breaks existing models — Changing OLLAMA_MODELS does not migrate files. Move files manually and update the variable to point to the new location.
  • Too many parallel requests causes GPU OOM — Reduce OLLAMA_NUM_PARALLEL or OLLAMA_MAX_LOADED_MODELS to lower memory pressure.
  • daemon-reload fails on WSL2 — WSL2 does not support full systemd. Use sudo service ollama restart instead on WSL2.
  • Wrong environment on Windows — On Windows, set variables via System Properties > Environment Variables or PowerShell [Environment]::SetEnvironmentVariable(...).

Related guides

  • How to configure Ollama port and networking
  • How to create a custom Modelfile for Ollama
  • Course Ollama Deep Dive
RELATED GUIDES
SET
How to configure Ollama port and networking
SET
How to create a custom Modelfile for Ollama
← All how-to guidesCourses →