Saturday, 28 November 2026 | Updating Daily AI insight, written for builders

Ollama Environment Variables: Complete Reference Guide

  • The main table covers the 12 variables explained in Ollama’s FAQ (host binding, model storage, memory, GPU and cloud features); a second table lists the other variables that ollama serve --help documents in Ollama v0.40.19
  • Set variables via launchctl (macOS), systemd (Linux), Windows Environment Variables dialog, or Docker -e flag
  • Common tasks: move models folder with OLLAMA_MODELS, keep models loaded with OLLAMA_KEEP_ALIVE, enable GPU features with OLLAMA_FLASH_ATTENTION and OLLAMA_KV_CACHE_TYPE
  • Verify settings took effect by checking logs or using ollama ps to confirm model processor allocation

Quick Answer

Ollama environment variables configure server behavior like port binding, model storage location, GPU acceleration, and concurrent request handling. Set them before starting the Ollama server on your platform—via launchctl on macOS, systemd on Linux, or the Environment Variables dialog on Windows. After setting, restart Ollama for changes to take effect.

Environment Variables Reference Table

Variable Purpose Example Value Notes
OLLAMA_HOST Bind address and port for the Ollama server 0.0.0.0:11434 Default is 127.0.0.1:11434 (localhost only)
OLLAMA_MODELS Directory where models are stored /data/ollama/models Defaults: ~/.ollama/models (macOS), /usr/share/ollama/.ollama/models (Linux), C:\Users\%username%\.ollama\models (Windows)
OLLAMA_KEEP_ALIVE How long to keep models in memory before unloading 24h or 3600 (seconds) Default is 5 minutes; use -1 to keep loaded indefinitely, 0 to unload immediately
OLLAMA_CONTEXT_LENGTH Default context window size in tokens 8192 Default depends on VRAM: 4k tokens below 24 GiB, 32k for 24-48 GiB, 256k at 48 GiB or more (Ollama context-length docs; the FAQ still says 4096). Per-request override: num_ctx
OLLAMA_NUM_PARALLEL Maximum parallel requests per model 4 Default varies by backend; MLX on Metal uses conservative default, others default to 1
OLLAMA_MAX_LOADED_MODELS Maximum models loaded concurrently 5 Default is 3 × number of GPUs (or 3 for CPU)
OLLAMA_MAX_QUEUE Maximum queued requests before 503 error 1024 Default is 512
OLLAMA_ORIGINS Allowed cross-origin request sources chrome-extension://*,moz-extension://* Built-in list already allows localhost, 127.0.0.1 and 0.0.0.0 (any port) plus app://, file://, tauri://, vscode-webview:// and vscode-file://; add extension origins here, comma-separated with no spaces
OLLAMA_FLASH_ATTENTION Enable Flash Attention optimization 1 or 0 Automatically enabled when supported; set explicitly to force on/off
OLLAMA_KV_CACHE_TYPE K/V cache quantization type q8_0 or q4_0 Default is f16; q8_0 uses about 1/2 the cache memory, q4_0 about 1/4 with more precision loss. Applies to every model and only takes effect when Flash Attention is enabled
OLLAMA_NO_CLOUD Disable Ollama cloud features 1 Set to 1 to run local-only; disables cloud models and web search
OLLAMA_CHANNEL Release channel for the install script; not an ollama serve setting OLLAMA_CHANNEL=preview Installs the latest pre-release when passed to the install script, e.g. curl -fsSL 'https://ollama.com/install.sh?channel=preview' | OLLAMA_CHANNEL=preview sh; if no pre-release exists, the latest stable version is installed

Other Variables Listed by ollama serve --help

Ollama v0.40.19 also documents these server variables. The descriptions and defaults come from envconfig/config.go:

Variable What it does Default
OLLAMA_DEBUG Shows additional debug information (OLLAMA_DEBUG=1) Off (INFO-level logs)
OLLAMA_LOAD_TIMEOUT How long a model load may stall before Ollama gives up 5m
OLLAMA_MAX_TRANSFER_STREAMS Maximum parallel transfer streams for safetensors model pulls and pushes 4
OLLAMA_NOPRUNE Stops Ollama from pruning model blobs on startup Off (blobs are pruned)
OLLAMA_SCHED_SPREAD Always schedules a model across all GPUs Off
OLLAMA_LLM_LIBRARY Sets the LLM library and bypasses autodetection Unset (autodetect)
OLLAMA_GPU_OVERHEAD Reserves a portion of VRAM per GPU, in bytes 0
OLLAMA_IGPU_ENABLE Enables integrated GPUs Unset
LLAMA_ARG_FIT Turns llama.cpp automatic fitting of unset memory options on or off on
LLAMA_ARG_FIT_TARGET Free VRAM margin per device that llama.cpp fitting aims for, in MiB Unset

To choose GPUs, use the vendor variables CUDA_VISIBLE_DEVICES (NVIDIA), HIP_VISIBLE_DEVICES or ROCR_VISIBLE_DEVICES (AMD) and GGML_VK_VISIBLE_DEVICES (Vulkan). Behind a proxy, set HTTPS_PROXY for model downloads; the Ollama FAQ warns that setting HTTP_PROXY may interrupt client connections to the server. A few more variables are defined in the same config.go but not listed by ollama serve --help, for example OLLAMA_VULKAN (Vulkan backend, on by default outside macOS) and OLLAMA_NOHISTORY and OLLAMA_EDITOR (used by ollama run).

Setting Environment Variables by Platform

macOS

On macOS, Ollama runs as a background application. Set environment variables using launchctl:

launchctl setenv OLLAMA_HOST "0.0.0.0:11434"
launchctl setenv OLLAMA_MODELS "/Volumes/external/ollama-models"
launchctl setenv OLLAMA_KEEP_ALIVE "24h"

After setting variables, restart the Ollama application from the macOS menu bar. Click the Ollama icon and select Quit, then reopen from Applications.

Linux

On Linux, Ollama typically runs as a systemd service. Edit the service configuration with systemctl edit ollama.service:

sudo systemctl edit ollama.service

Add variables under the [Service] section:

[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Environment="OLLAMA_MODELS=/data/ollama/models"
Environment="OLLAMA_KEEP_ALIVE=24h"

Save (Ctrl+X, then Y, then Enter in nano) and reload systemd:

sudo systemctl daemon-reload
sudo systemctl restart ollama

On Linux, the ollama user must own the models directory. If you specified a custom path, run:

sudo chown -R ollama:ollama /data/ollama/models

Windows

On Windows, Ollama inherits your user and system environment variables. First quit Ollama (click the taskbar icon and exit). Then:

  1. Open Settings (Windows 11) or Control Panel (Windows 10)
  2. Search for “environment variables”
  3. Click “Edit environment variables for your account”
  4. Click “New” and add each variable:
    • Variable name: OLLAMA_HOST
    • Variable value: 0.0.0.0:11434
  5. Repeat for other variables (OLLAMA_MODELS, OLLAMA_KEEP_ALIVE, etc.)
  6. Click OK/Apply and restart Ollama from the Start menu

To verify: open Command Prompt and run echo %OLLAMA_HOST% to confirm the variable is set.

Docker

When running Ollama in Docker, pass environment variables with the -e flag:

docker run -d -e OLLAMA_HOST="0.0.0.0:11434" -e OLLAMA_MODELS="/models" -e OLLAMA_KEEP_ALIVE="24h" -p 11434:11434 ollama/ollama

Ensure the models directory is mounted as a volume to persist models across restarts:

docker run -d -e OLLAMA_MODELS="/models" -v ollama_models:/models -p 11434:11434 ollama/ollama

Common Use Cases

Moving Models to External Storage

By default, models are stored in your home directory, which may fill up quickly with large models. For example, Ollama’s library lists llama4:maverick (Q4_K_M) as a 245 GB download (ollama.com/library/llama4). For memory needs, see VRAM requirements for every major LLM. To move models to an external drive:

macOS:

launchctl setenv OLLAMA_MODELS "/Volumes/external-drive/ollama-models"
# Restart Ollama from menu bar

Linux:

sudo systemctl edit ollama.service
# Add: Environment="OLLAMA_MODELS=/mnt/external/ollama-models"
sudo systemctl daemon-reload
sudo systemctl restart ollama

Windows:

setx OLLAMA_MODELS D:\ollama-models
# Restart Ollama from Start menu

After setting the variable, Ollama will look for models in the new location on next startup. If you want to keep existing models, copy them to the new directory before restarting.

Keeping a Model Loaded for Faster Responses

By default, models unload after 5 minutes of inactivity. For frequent inference, keep a model loaded:

OLLAMA_KEEP_ALIVE="-1" ollama serve

Or set it on your platform (replace ollama serve with the appropriate restart command above). The -1 value means keep the model loaded indefinitely. Alternative values:

  • 24h — keep loaded for 24 hours
  • 3600 — keep loaded for 3600 seconds (1 hour)
  • 0 — unload immediately after each request

At the API level, the keep_alive parameter overrides this setting per-request:

curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2",
  "prompt": "Explain quantum computing",
  "keep_alive": -1
}'

GPU and Memory Configuration

Control how Ollama uses your GPU and memory with these variables:

  • OLLAMA_FLASH_ATTENTION: Set to 1 to force Flash Attention on (reduces memory usage at high context sizes), or 0 to disable. Ollama enables it automatically when supported.
  • OLLAMA_KV_CACHE_TYPE: Set to q8_0 (recommended for memory savings) or q4_0 (more aggressive, may impact quality). Default f16 is highest precision. Quantization only takes effect when Flash Attention is enabled, and it applies to every model the server loads.
  • OLLAMA_NUM_PARALLEL: Increase parallel requests if you have excess VRAM. Each parallel slot adds its own context: per the Ollama FAQ, a 2K context with 4 parallel requests results in an 8K context and the extra memory that goes with it.
  • OLLAMA_MAX_LOADED_MODELS: Limit concurrent models. Default is 3 × number of GPUs; lower this if models don’t fit together in VRAM.

To see whether a loaded model is on the GPU, the CPU or split between them, use ollama ps:

ollama ps

Output shows the PROCESSOR column: 100% GPU means fully on GPU, 100% CPU means in system memory, mixed percentages mean split across both.

Network and Security Configuration

Expose Ollama on Your Network

By default, Ollama binds to localhost (127.0.0.1) only. To allow connections from other machines:

OLLAMA_HOST="0.0.0.0:11434" ollama serve

Or set OLLAMA_HOST via your platform’s method and restart Ollama. The server will then listen on all network interfaces on port 11434. Any machine that can reach that port can then use the API, so limit access with a firewall or reverse proxy. See the Ollama port configuration guide and is Ollama safe? for details.

Allow Browser Extensions

Browser extensions (Chrome, Firefox, Safari) cannot access Ollama by default due to CORS restrictions. Allow them with:

OLLAMA_ORIGINS="chrome-extension://*,moz-extension://*,safari-web-extension://*" ollama serve

Or set it via your platform and restart. For specific extensions only, replace * with the extension’s specific origin pattern.

Disable Cloud Features

To run Ollama in local-only mode without cloud model support:

OLLAMA_NO_CLOUD="1" ollama serve

Logs will show “Ollama cloud disabled: true” when active. Alternatively, edit ~/.ollama/server.json:

{
  "disable_ollama_cloud": true
}

Verifying Configuration

After setting environment variables and restarting Ollama, verify they took effect:

  • Check logs: At startup the server logs a server config line listing the environment values it read. On macOS, run cat ~/.ollama/logs/server.log. On Linux, use journalctl -u ollama --no-pager --follow --pager-end. On Windows, open %LOCALAPPDATA%\Ollama and read server.log. In Docker, run docker logs <container-name>.
  • Test model loading: Run ollama ps to see which models are loaded and their processor allocation (GPU vs CPU).
  • Query the API: Use curl http://localhost:11434/api/tags to confirm the server is accessible at your configured host.
  • Check port and binding: On Linux/macOS, run netstat -tuln | grep 11434 or lsof -i :11434. On Windows, use netstat -ano | findstr :11434.

Use Convly Tools

Use the VRAM calculator to estimate how much GPU memory you need before tuning OLLAMA_NUM_PARALLEL or OLLAMA_KV_CACHE_TYPE. Use the self-hosting vs API calculator to decide whether local Ollama or a cloud API makes sense for your workload. For model recommendations optimized for Ollama, see the best local models for Ollama.

Frequently Asked Questions

What’s the difference between OLLAMA_KEEP_ALIVE and keep_alive in API requests?

OLLAMA_KEEP_ALIVE is a server-wide default—it sets how long all models stay in memory when idle. The keep_alive parameter in API requests overrides this for a single request. Use the server-wide setting for general behavior, and API-level overrides when you need a one-off exception (e.g., immediately unloading a model after a single request).

Why should I set OLLAMA_FLASH_ATTENTION and OLLAMA_KV_CACHE_TYPE?

Flash Attention reduces memory usage as the context window grows, and Ollama turns it on automatically when the backend supports it. K/V cache quantization then compresses the cache: according to the Ollama FAQ, q8_0 uses about half the memory of f16 with usually small precision loss, while q4_0 uses about a quarter with more noticeable loss at large context sizes. Quantization only takes effect when Flash Attention is enabled. Consider both when a large model or long context does not fit in your VRAM.

Can I use a custom models directory on Linux?

Yes, set OLLAMA_MODELS to your chosen path. The critical step is ensuring the ollama user owns the directory: sudo chown -R ollama:ollama /path/to/models. Without proper ownership, Ollama cannot read or write models.

How do I know if Ollama is using my GPU?

Run ollama ps and check the PROCESSOR column. 100% GPU means the model is fully on your graphics card. If it shows 100% CPU, Ollama is using system RAM instead. That happens when the model doesn’t fit in VRAM or no supported GPU is detected (see Ollama not using GPU). Use the models database to check a model’s VRAM requirements before loading.

What happens if I set OLLAMA_NUM_PARALLEL too high?

Each parallel slot adds its own context, so memory use grows with the setting (a 2K context with 4 parallel requests becomes an 8K context). If that larger allocation no longer fits in VRAM, more of the model runs from system RAM and responses slow down; check the PROCESSOR column in ollama ps. Requests beyond the parallel limit wait in the queue, and the server returns a 503 error only once the queue exceeds OLLAMA_MAX_QUEUE (default 512). Start with 1 and raise it while watching memory usage.

Can I change these variables without restarting Ollama?

No. Environment variables are read when the server starts. After changing any variable, you must restart Ollama on your platform for changes to take effect. Configuration changes via ~/.ollama/server.json (like disable_ollama_cloud) also require a restart.

References

Official Ollama FAQ (setting variables per platform, defaults for keep-alive, queueing, origins, Flash Attention and K/V cache)

Ollama context length docs (VRAM-based default context)

Ollama troubleshooting docs (log locations)

ollama/ollama envconfig/config.go at v0.40.19 (variable names, descriptions and defaults)

Written by Mustafa Ihsan

Mustafa Ihsan is the founder and editor of Convly.ai. He built and maintains the site's live AI models database, its price-performance index, and its free calculators for VRAM requirements, API costs and self-hosting economics. He writes about model pricing, benchmark results and the hardware needed to run AI models locally, and consistently prefers measured numbers to vendor claims.

Scroll to Top