Ollama is configured almost entirely through environment variables. Want to reach Ollama from another PC on your network? Move models to a bigger drive? Keep models loaded longer, run more requests in parallel, or raise the default context length? Each of those is one environment variable.
The tricky part is that every operating system sets them differently, and the Ollama app only picks them up after a restart.
This guide lists the Ollama environment variables that matter, with their defaults, and shows exactly how to set them on Windows, macOS, Linux and Docker, with fixes for when a setting doesn’t seem to apply. It follows the official Ollama FAQ as of November 2026.
- Network access:
OLLAMA_HOST=0.0.0.0:11434(default is 127.0.0.1:11434). - Move models:
OLLAMA_MODELS=/path/to/models. - Keep models loaded:
OLLAMA_KEEP_ALIVE=30m(default 5m; negative keeps them loaded). - Bigger context:
OLLAMA_CONTEXT_LENGTH=8192(default 4096). - Windows: quit Ollama, edit “environment variables for your account”, restart.
- macOS:
launchctl setenv NAME value, then restart the app. Linux:systemctl edit ollama.service.
Ollama Environment Variables Cheat Sheet
| Variable | What it does | Default |
|---|---|---|
OLLAMA_HOST |
Address and port the server listens on | 127.0.0.1:11434 |
OLLAMA_MODELS |
Where models are stored | See the models section |
OLLAMA_KEEP_ALIVE |
How long a model stays loaded after use | 5m |
OLLAMA_CONTEXT_LENGTH |
Default context window in tokens | 4096 |
OLLAMA_NUM_PARALLEL |
Parallel requests per model | 1 |
OLLAMA_MAX_LOADED_MODELS |
Models loaded at the same time | 3 per GPU (3 on CPU) |
OLLAMA_MAX_QUEUE |
Queued requests before Ollama returns 503 | 512 |
OLLAMA_FLASH_ATTENTION |
1 forces Flash Attention on, 0 turns it off | Automatic where supported |
OLLAMA_KV_CACHE_TYPE |
K/V cache precision: f16, q8_0 or q4_0 | f16 |
OLLAMA_ORIGINS |
Extra allowed browser origins (CORS) | Local origins only |
OLLAMA_NO_CLOUD |
1 disables Ollama’s cloud features | Cloud enabled |
OLLAMA_DEBUG |
Extra debug logging | Off |
HTTPS_PROXY |
Proxy for model downloads | None |
CUDA_VISIBLE_DEVICES |
Which NVIDIA GPUs Ollama can see | All |
Good to know: these variables configure the Ollama server, not the ollama command you type. When you use the desktop app on Windows or macOS, the app starts the server for you, so the variables must be visible to the app. When Ollama runs as a Linux service or in Docker, they must be set on the service or container. Settings passed in an API request, such as keep_alive or num_ctx, override the server-wide defaults for that request only.
Set Them on Windows
Ollama on Windows inherits your user and system environment variables.
- Quit Ollama from the taskbar icon (right-click > Quit).
- Open Settings (Windows 11) or Control Panel (Windows 10) and search for “environment variables”.
- Click “Edit environment variables for your account”.
- Click New, enter the name (for example
OLLAMA_MODELS) and value (for exampleD:\ollama\models). - Click OK to save.
- Start Ollama again from the Start menu.
Prefer the command line? setx OLLAMA_HOST "0.0.0.0:11434" in PowerShell or Command Prompt sets a user variable; restart Ollama afterwards. New terminals see the change, existing ones don’t.
Set Them on macOS
- Run launchctl for each variable:
launchctl setenv OLLAMA_HOST "0.0.0.0:11434" - Restart the Ollama app (quit from the menu bar and open it again).
Note that launchctl setenv doesn’t survive a reboot on its own, so you may need to run it again after restarting your Mac. If you run ollama serve yourself in Terminal, you can simply prefix the command, for example OLLAMA_CONTEXT_LENGTH=8192 ollama serve.
Set Them on Linux
The standard installer runs Ollama as a systemd service, so set variables on the service, not in your shell.
- Open an override file:
sudo systemctl edit ollama.service - Add one line per variable under
[Service]:[Service] Environment="OLLAMA_HOST=0.0.0.0:11434" Environment="OLLAMA_KEEP_ALIVE=30m" - Save, then reload and restart:
sudo systemctl daemon-reload sudo systemctl restart ollama
Check that it took effect with systemctl show ollama --property=Environment.
Set Them in Docker
Pass variables with -e:
docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 \
-e OLLAMA_KEEP_ALIVE=30m -e OLLAMA_CONTEXT_LENGTH=8192 \
--name ollama ollama/ollama
In Docker Compose, add them under environment:. Full container setup is in our Ollama Docker guide.
Expose Ollama on Your Network
By default Ollama only listens on 127.0.0.1, so other devices can’t reach it. To use it from another PC, a phone app or a server like Open WebUI on another machine:
- Set
OLLAMA_HOST=0.0.0.0:11434using the steps for your OS. - Restart Ollama.
- Allow port 11434 through your firewall if needed.
- Connect from the other device to
http://YOUR-PC-IP:11434.
Ollama has no built-in login, so only do this on a network you trust. If you put it behind Nginx, ngrok or Cloudflare Tunnel, the FAQ notes the Host header should be set to localhost:11434. For browser apps or extensions calling Ollama directly, add their origin to OLLAMA_ORIGINS, for example chrome-extension://*.
Building on the API? See our Ollama API guide.
Move the Models Folder
| OS | Default models folder |
|---|---|
| macOS | ~/.ollama/models |
| Linux | /usr/share/ollama/.ollama/models |
| Windows | C:\Users\%username%\.ollama\models |
- Quit Ollama.
- Copy the existing models folder to the new location if you want to keep downloaded models.
- Set
OLLAMA_MODELSto the new folder. - Linux only: give the service user access with
sudo chown -R ollama:ollama /new/path. - Restart Ollama and run
ollama listto check your models are there.
Memory and Performance Settings
- OLLAMA_CONTEXT_LENGTH raises the default context for every model. Bigger context uses more memory. Per-request, you can set
num_ctxinstead; see Ollama context length. - OLLAMA_KEEP_ALIVE avoids slow reloads between requests. The API’s
keep_aliveoverrides it. Details in Ollama keep_alive. - OLLAMA_NUM_PARALLEL lets one model answer several requests at once, but memory scales with parallel requests times context length.
- OLLAMA_KV_CACHE_TYPE=q8_0 uses roughly half the K/V cache memory of f16 (q4_0 about a quarter), which helps long contexts fit. It needs Flash Attention.
- OLLAMA_MAX_LOADED_MODELS caps how many models stay in memory together.
- Check where a model is running with
ollama ps: the PROCESSOR column shows GPU, CPU or a split. If it’s on CPU, see Ollama not using GPU.
Use a Proxy
If model downloads must go through a corporate proxy, set HTTPS_PROXY (for example https://proxy.example.com) and install the proxy’s certificate as a system certificate. The FAQ warns against setting HTTP_PROXY, as it can interrupt client connections to the server.
Ready-Made Recipes
| Goal | Variables |
|---|---|
| Home server for the whole house | OLLAMA_HOST=0.0.0.0:11434, OLLAMA_KEEP_ALIVE=1h |
| Models on a second drive | OLLAMA_MODELS=D:\ollama\models |
| Long documents and RAG | OLLAMA_CONTEXT_LENGTH=16384, OLLAMA_KV_CACHE_TYPE=q8_0 |
| Several users at once | OLLAMA_NUM_PARALLEL=4 (watch memory) |
| Fully offline, no cloud | OLLAMA_NO_CLOUD=1 |
| Use only the second GPU | CUDA_VISIBLE_DEVICES=1 |
Pairing Ollama with a chat UI? Our Open WebUI RAG guide uses the context and keep-alive settings above.
How to Check Your Settings Took Effect
- Read the server log. When Ollama starts, it prints its server configuration, including the OLLAMA_ variables it picked up.
- Find the log: on macOS it’s
~/.ollama/logs/server.log; on Linux runjournalctl -u ollama; on Windows open%LOCALAPPDATA%\Ollamaand look atserver.log. - Test the host setting from another device with
curl http://YOUR-PC-IP:11434. It should reply “Ollama is running”. - Test the models path with
ollama list, and pull a small model to confirm new files land in the new folder. - Test keep-alive and context with
ollama ps, which shows loaded models, their size, processor and when they’ll unload.
If the log doesn’t show your value, the variable didn’t reach the Ollama process. That almost always means it was set in the wrong place (your shell instead of the service or app) or Ollama wasn’t fully restarted.
Troubleshooting
| Problem | Likely cause | Fix |
|---|---|---|
| Setting has no effect | Ollama wasn’t restarted | Fully quit and restart the app or service |
| Works in terminal but not the app | Variable set only in your shell | Use the OS method above (launchctl, systemd, Windows settings) |
| Linux service ignores ~/.bashrc | systemd doesn’t read shell files | Use systemctl edit ollama.service |
| Models “disappeared” | OLLAMA_MODELS points to an empty folder | Copy models over or fix the path |
| Permission denied on new folder (Linux) | ollama user can’t write | sudo chown -R ollama:ollama /path |
| Other devices can’t connect | Still bound to 127.0.0.1, or firewall | Set OLLAMA_HOST=0.0.0.0 and open port 11434 |
| Browser extension blocked | CORS | Add its origin to OLLAMA_ORIGINS |
| Out of memory after raising context | Context or parallel too high | Lower them or use OLLAMA_KV_CACHE_TYPE=q8_0 |
After big changes, it’s worth checking you’re on a current version: how to update Ollama.
FAQ
How do I make Ollama listen on all interfaces?
Set OLLAMA_HOST to 0.0.0.0:11434 and restart Ollama.
How do I change where Ollama stores models?
Set OLLAMA_MODELS to the new folder, move your existing models there if you want them, and restart Ollama.
What is the default context length in Ollama?
4096 tokens. Change it globally with OLLAMA_CONTEXT_LENGTH or per request with num_ctx.
Why doesn’t my environment variable work on Linux?
The Ollama service runs under systemd, which ignores your shell profile. Add it with systemctl edit ollama.service, then reload and restart.
How do I keep a model loaded forever?
Set OLLAMA_KEEP_ALIVE to a negative value such as -1.
Is it safe to set OLLAMA_HOST to 0.0.0.0?
Only on a trusted network. Ollama has no built-in authentication, so anyone who can reach the port can use it.
Do I need to restart Ollama after changing variables?
Yes. Ollama reads them only when it starts.



