Ollama Environment Variables on Windows: Complete Manual
On Windows, Ollama does not rely on a complex YAML or JSON configuration file. Instead, the runtime behavior of the Ollama background daemon is governed entirely by Windows Environment Variables. Here is the definitive reference for every supported variable, default values, and how to apply them permanently.
Master Variable Reference Table
| Variable Name | Default Value | Accepted Values | Purpose & Practical Impact |
|---|---|---|---|
OLLAMA_HOST |
127.0.0.1:11434 |
0.0.0.0:11434 or :11434 |
Controls IP binding. Set to 0.0.0.0 to allow other PCs or phones on your local LAN to access Ollama. |
OLLAMA_MODELS |
%USERPROFILE%\.ollama\models |
Any valid folder (e.g. D:\OllamaModels) |
Relocates all model manifests and GGUF blob storage to another drive partition or SSD. |
OLLAMA_KEEP_ALIVE |
5m (5 minutes) |
0, 10m, 24h, -1 (indefinite) |
Controls how long a model remains loaded in GPU VRAM after your last query. 0 unloads instantly to free VRAM for gaming. |
OLLAMA_NUM_PARALLEL |
1 (or auto-scales) |
1, 2, 4, 8 |
Number of concurrent user requests the server can process simultaneously. Each worker multiplies KV cache VRAM footprint. |
OLLAMA_FLASH_ATTENTION |
0 (disabled) |
1 (enabled) |
Enables Flash Attention kernels in llama.cpp, accelerating prompt processing and saving VRAM during long contexts. |
OLLAMA_ORIGINS |
Local origins | * or comma-separated URLs |
Cross-Origin Resource Sharing (CORS) whitelist. Required when connecting external Web UIs or browser extensions. |
OLLAMA_DEBUG |
0 (disabled) |
1 (verbose logging) |
Prints extensive hardware detection, layer offloading, and HTTP transaction details to server.log. |
OLLAMA_MAX_LOADED_MODELS |
1 (or auto) |
Integer (e.g. 2, 3) |
Maximum number of distinct models kept simultaneously in memory. Useful on 24GB+ GPUs running both LLM and embedding models. |
CUDA_VISIBLE_DEVICES |
All detected GPUs | 0, 1, 0,1 |
NVIDIA hardware filter. Instructs Ollama to only use specific discrete GPUs on multi-GPU setups. |
How to Set Environment Variables Permanently on Windows
There are two reliable ways to apply these variables on Windows 10 and Windows 11:
Method 1: Fast One-Liner in PowerShell (Recommended)
To set a persistent User-level variable that survives system reboots, execute [Environment]::SetEnvironmentVariable():
# 1. Allow LAN access:
[Environment]::SetEnvironmentVariable('OLLAMA_HOST', '0.0.0.0', 'User')
# 2. Enable Flash Attention:
[Environment]::SetEnvironmentVariable('OLLAMA_FLASH_ATTENTION', '1', 'User')
# 3. Unload models from VRAM immediately after use (great for gamers):
[Environment]::SetEnvironmentVariable('OLLAMA_KEEP_ALIVE', '0', 'User')
# 4. Allow Open WebUI CORS connections:
[Environment]::SetEnvironmentVariable('OLLAMA_ORIGINS', '*', 'User')
Method 2: Windows Graphical Interface (GUI)
- Press Win + R, type
sysdm.cpl, and press Enter (opens System Properties). - Click on the Advanced tab, then click the Environment Variables... button at the bottom.
- Under User variables for <YourUsername>, click New....
- Enter the Variable name (e.g.
OLLAMA_KEEP_ALIVE) and Variable value (e.g.24h). - Click OK on all dialog boxes, then restart Ollama.
How to Inspect Active Ollama Variables
To verify which environment variables are currently recognized by Windows, run:
Get-ChildItem env:OLLAMA_* | Format-Table -AutoSize
How to Remove an Environment Variable
To revert any variable back to its factory default, pass $null as the value:
[Environment]::SetEnvironmentVariable('OLLAMA_FLASH_ATTENTION', $null, 'User')
Frequently Asked Questions
Why does OLLAMA_HOST=0.0.0.0 cause Windows Firewall prompts?
By default, Windows Firewall allows localhost (127.0.0.1) network sockets without prompts. Binding to 0.0.0.0 opens port 11434 to external network packets, which triggers Windows Defender Firewall to request permission. You should allow access on Private Networks.
Can I set OLLAMA_KEEP_ALIVE=-1 to keep models loaded forever?
Yes. Setting OLLAMA_KEEP_ALIVE=-1 prevents Ollama from ever evicting the model from VRAM until you explicitly unload it or shut down the machine, eliminating all cold-start latencies.