Ollama environment variables and service configuration
Ollama has no traditional configuration file; service behavior is almost entirely controlled by environment variables: listen address, model path, context, concurrency, proxy, and debugging.
This chapter first explains how to set variables on three platforms, then clarifies each core variable across three layers: network entry, request scheduling, and model running.
Where configuration variables sit in the service
First build a map: the dozen or so environment variables aren't on the same level—they act on different stages of the service process.
To see the complete list of variables supported by the current version, just run ollama serve --help.
Methods for setting environment variables on three platforms
For the same variable, the setting entry points differ completely across the three platforms—this is where beginners most often get stuck.
macOS:launchctl
When Ollama runs as an application, environment variables must be injected via launchctl and take effect after restarting the app:
Example
Inject variables one by one
launchctl setenv OLLAMA_HOST
"0.0.0.0:11434"
Then quit and reopen the Ollama app
Linux: systemd service override
Example
Open the service override editor
sudo
systemctl edit ollama.service
Add the following in the editor (note it must be under the [Service] section):
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Reload and restart the service
sudo
systemctl daemon-reload
sudo
systemctl restart ollama
Windows: system environment variables
Search for "environment variables" in the Start menu, select "Edit environment variables for your account", create or edit the variable and save.
Key step: first quit Ollama in the tray; after saving, restart it from the Start menu so the new variables take effect in the new process.
There's also a JSON config file server.json (located in ~/.ollama/) for a few switch-type settings—for example, to disable cloud features write {"disable_ollama_cloud": true}. The vast majority of configuration is still governed by environment variables.
Network entry: HOST, ORIGINS, and proxy
OLLAMA_HOST: let the LAN access your models
By default it listens only on 127.0.0.1, usable only locally; to let other LAN devices call it, change to listen on all network interfaces:
Example
Listen on all network interfaces (accessible on the LAN)
OLLAMA_HOST
=0.0.0.0:
11434
ollama serve
Verify from another device (replace with your actual IP)
curl http:
//
192.168.1.100:
11434
/
api
/
version
Opening to the LAN means exposing an unauthenticated model service to all devices on the same segment—fine for a home network, but in a company network you must pair it with firewall rules or a reverse proxy (detailed in the private deployment chapter).
OLLAMA_ORIGINS: cross-origin allowance
Ollama only accepts cross-origin requests from 127.0.0.1 and 0.0.0.0 by default; when a web page or browser extension connects directly to the local API, you need to explicitly allow it:
Example
Allow all browser extensions
OLLAMA_ORIGINS
=chrome-extension:
//*
,moz-extension:
//*
,safari-web-extension:
//*
ollama serve
Proxy: only HTTPS_PROXY
Model downloads go outbound over HTTPS; in a restricted network just point HTTPS_PROXY to a proxy.
Set only HTTPS_PROXY, not HTTP_PROXY: Ollama doesn't use HTTP to pull models, and setting an extra HTTP proxy may actually break the client–server connection. In Docker, pass -e HTTPS_PROXY=... when starting the container; if the proxy uses a self-signed certificate, install the CA certificate into the system (or bake it into the image).
Model running: path, context, and residency
OLLAMA_MODELS: store models on another drive
Models are stored in the user directory by default; paths on the three platforms are as follows:
| Platform | Default model path |
|---|---|
| macOS | ~/.ollama/models |
| Linux | /usr/share/ollama/.ollama/models |
| Windows | C:\Users |
Point OLLAMA_MODELS to a new directory to migrate everything; once downloaded model files are moved over, they can be used directly.
Example
Linux example: migrate to a large-capacity data disk
OLLAMA_MODELS
=
/
data
/
ollama-models ollama serve
Note: a standard Linux install runs the service as the ollama user
The new directory needs its ownership transferred, otherwise the service has no read/write permission
sudo
chown
-R
ollama:ollama
/
data
/
ollama-models
OLLAMA_CONTEXT_LENGTH: global context
Sets the default context length for all models; takes effect when not specified individually at the model or request level:
Example
Global default 8K
OLLAMA_CONTEXT_LENGTH
=
8192
ollama serve
Priority from high to low: API request options.num_ctx, PARAMETER num_ctx in Modelfile, this environment variable, and the VRAM-based auto-tiered default.
OLLAMA_KEEP_ALIVE: global residency duration
Uniformly adjusts how long a model stays resident after loading; the value format matches the API's keep_alive parameter:
Example
Common values: 300 (seconds) / "10m" / "24h" / -1 permanent / 0 unload after use
OLLAMA_KEEP_ALIVE
=30m ollama serve
A keep_alive passed individually in an API request takes precedence over this global value, enabling a tiered strategy like "10 minutes globally, key models permanent".
Request scheduling: the concurrency trio
Ollama supports two levels of concurrency: multiple models resident simultaneously, and a single model processing multiple requests in parallel—each controlled by one variable.
| Variables | Default value | Purpose |
|---|---|---|
| OLLAMA_NUM_PARALLEL | 1 | The number of requests a single model handles simultaneously; required memory scales as this value × context length |
| OLLAMA_MAX_LOADED_MODELS | 3 × number of GPUs (3 for CPU inference) | Maximum total number of models that can be loaded simultaneously, provided VRAM/RAM can accommodate them |
| OLLAMA_MAX_QUEUE | 512 | Maximum number of queued requests when the service is busy; requests beyond this return 503 directly |
The scheduling logic is worth understanding: when VRAM is sufficient, models process requests in parallel; when VRAM is insufficient, new requests queue up, and waiting models are unloaded when idle to free up space.
NUM_PARALLEL is the most error-prone variable: setting it to 4 means the context cache is multiplied by 4, instantly quadrupling VRAM usage, which may push the model off the GPU. Planning methods for multi-user shared instances are expanded in the private deployment chapter.
Debugging and logs: OLLAMA_DEBUG
The first step in troubleshooting is always to enable debugging and check the logs.
Example
Enable debug logging
OLLAMA_DEBUG
=
1
ollama serve
How to enable debugging for the Windows GUI application: first exit the app from the tray, then run in PowerShell:
Example
$env
:OLLAMA_DEBUG
=
"1"
&
"ollama app.exe"
Summary of log locations across the four environments:
| Environment | Log location |
|---|---|
| macOS | ~/.ollama/logs/server.log |
| Linux(systemd) | journalctl -u ollama --no-pager --follow --pager-end |
| Windows | %LOCALAPPDATA%\Ollama\server.log |
| Docker | docker logs |
Quick reference for other useful variables
Most of the remaining variables are tied to specific scenarios; full chapter-by-chapter explanations are expanded in the corresponding topic sections, with an index established here first.
| Variables | Example value | Purpose |
|---|---|---|
| OLLAMA_FLASH_ATTENTION | 1 / 0 | Force enable / disable Flash Attention, significantly saving VRAM with long contexts (detailed in the GPU chapter) |
| OLLAMA_KV_CACHE_TYPE | q8_0 / q4_0 | KV cache quantization type, requires Flash Attention (detailed in the GPU chapter) |
| OLLAMA_VULKAN | 0 | Disable the Vulkan backend (switch for when Vulkan misbehaves) |
| OLLAMA_LLM_LIBRARY | cpu_avx2 | Force a specific inference library, bypassing auto-detection |
| OLLAMA_TMPDIR | /data/tmp | Change the temporary directory location (when the system /tmp is mounted noexec) |
| OLLAMA_NO_CLOUD | 1 | Disable cloud models and online search, pure local mode |