Skip to content

How-ToGPU

How to Set Ollama Environment Variables on Windows 11

How to set Ollama's environment variables properly on Windows 11 with Settings or setx, the variables that matter on a home AI PC (OLLAMA_MODELS, OLLAMA_HOST, OLLAMA_KEEP_ALIVE, context length, KV cache, parallel requests, GPU selection) and how to check Ollama has picked them up.

By , Systems & Technical Editor

8 min read

How to Set Ollama Environment Variables on Windows 11

The steps and variable descriptions come from Ollama's official FAQ, Windows and GPU documentation, plus Microsoft's documentation for the setx command, all read on 26 November 2026. Ollama changes regularly, so check its FAQ if a setting behaves differently on your version.

Ollama is one of the easiest ways to run large language models on your own PC, but almost everything beyond the defaults is controlled in one way: environment variables. Want your models on a bigger SSD? That's an environment variable. Want other devices on your network to use your PC's graphics card? Another one. Want models to stay loaded in VRAM instead of unloading after a few minutes? Same again.

The catch on Windows is that Ollama runs as a tray app in the background, so typing a variable into a terminal often appears to do nothing. This guide shows the reliable way to set them, the variables most worth knowing about, and how to confirm Ollama has picked them up.

How Ollama reads settings on Windows

According to Ollama's FAQ, the Ollama server is configured with environment variables, and on Windows it inherits your user and system environment variables. Two things follow from that:

  • Ollama only reads the variables when it starts. If you change one while Ollama is running, nothing happens until you quit and relaunch it.

  • Setting a variable for one terminal window isn't enough. The tray app doesn't see variables you set temporarily in a PowerShell or Command Prompt session. You need to save them to your Windows account.

Ollama's Windows documentation says the installer doesn't need administrator rights and installs into your home directory, so for most people a user variable (rather than a system-wide one) is the right choice.

This is the method Ollama's own FAQ describes.

  1. Quit Ollama. Click the Ollama icon in the taskbar and choose Quit. Closing a terminal window isn't enough.

  2. Open the environment variables window. Open Settings (or Control Panel on Windows 10), search for environment variables and choose Edit environment variables for your account.

  3. Add a variable. Under your user variables, click New. Enter the name, such as OLLAMA_MODELS, and the value, such as D:\AI\ollama-models.

  4. Save. Click OK to close each window.

  5. Restart Ollama. Launch Ollama again from the Start menu.

To change a variable later, select it and click Edit. To go back to Ollama's default behaviour, delete the variable and restart Ollama.

Method 2: Use setx from a terminal

If you'd rather type than click, Windows' built-in setx command saves a variable to your user environment. Microsoft's documentation explains that setx creates or modifies environment variables in the user or system environment, and that the /m switch sets a variable system-wide instead.

For example, in PowerShell or Command Prompt:

setx OLLAMA_MODELS "D:\AI\ollama-models"
setx OLLAMA_KEEP_ALIVE "30m"

Two details from Microsoft's documentation matter here:

  • Variables set with setx are only available in future command windows, not the one you're typing in. Open a new terminal before testing.

  • There's a 1,024-character limit on values set with setx, and anything longer is cut off. That won't affect Ollama's variables, but it's a good reason not to use setx to edit your PATH.

As with Method 1, quit Ollama and start it again afterwards.

The Ollama variables worth knowing

Ollama's FAQ documents a range of server settings. These are the ones most likely to matter on a home PC with a graphics card.

Variable

What it does

Default (per Ollama's FAQ)

OLLAMA_MODELS

Folder where downloaded models are stored

C:\Users\<username>\.ollama\models

OLLAMA_HOST

Address and port the server listens on

127.0.0.1, port 11434

OLLAMA_KEEP_ALIVE

How long models stay loaded after use

5 minutes

OLLAMA_CONTEXT_LENGTH

Default context window

4,096 tokens

OLLAMA_NUM_PARALLEL

Parallel requests per model

1 on most back ends

OLLAMA_MAX_LOADED_MODELS

Models loaded at once, if they fit

3 x number of GPUs, or 3 on CPU

OLLAMA_MAX_QUEUE

Requests queued before Ollama rejects more

512

OLLAMA_FLASH_ATTENTION

Force Flash Attention on (1) or off (0)

Automatic when supported

OLLAMA_KV_CACHE_TYPE

Precision of the context (K/V) cache

f16

OLLAMA_ORIGINS

Extra web origins allowed to call the API

127.0.0.1 and 0.0.0.0

OLLAMA_NO_CLOUD

Set to 1 to disable Ollama's cloud features

Not set

CUDA_VISIBLE_DEVICES

Which NVIDIA GPUs Ollama can use

All detected GPUs

Storage: OLLAMA_MODELS

Models can be large. Ollama's Windows documentation warns that model files can be tens to hundreds of gigabytes, and that if your home drive doesn't have enough space you can store them elsewhere. Point OLLAMA_MODELS at a folder on a roomier SSD. Ollama also notes that if you've changed this location, uninstalling Ollama won't remove those models, so you'll need to delete them yourself if you want the space back. Our guide to moving Ollama models to another drive covers moving an existing library, and our best SSDs for local AI models guide helps if you need a new drive.

Network access: OLLAMA_HOST

By default, Ollama only accepts connections from the PC it's running on. Ollama's FAQ says it binds to 127.0.0.1 on port 11434, and that you change the bind address with OLLAMA_HOST. Setting it to 0.0.0.0:11434 makes it listen on all network interfaces, which lets a laptop or phone on your home network use your desktop's GPU. Only do this on a network you trust. Our guide to sharing Ollama on your local network explains the firewall side.

Keeping models in VRAM: OLLAMA_KEEP_ALIVE

Ollama keeps a model in memory for five minutes after its last request, then unloads it. The FAQ says OLLAMA_KEEP_ALIVE accepts a duration such as 10m or 24h, a number of seconds, a negative number to keep models loaded indefinitely, or 0 to unload straight after each response. Apps can override it per request with the keep_alive API parameter. Keeping a model loaded avoids the wait while it reloads, but holds on to VRAM that games or other apps might want. Our guide to keeping Ollama models loaded goes into more detail.

Context and memory: OLLAMA_CONTEXT_LENGTH, OLLAMA_FLASH_ATTENTION and OLLAMA_KV_CACHE_TYPE

Ollama's FAQ says the default context window is 4,096 tokens and that OLLAMA_CONTEXT_LENGTH overrides it, for example 8192. A longer context uses more memory, as our explainer on LLM context length and VRAM shows.

Two variables help claw that memory back:

  • OLLAMA_FLASH_ATTENTION. Ollama says it uses Flash Attention automatically when the back end and devices support it. Set it to 1 to force it on or 0 to turn it off.

  • OLLAMA_KV_CACHE_TYPE. The FAQ says the cache can be quantised to reduce memory use when Flash Attention is enabled. q8_0 uses about half the memory of the default f16 with a very small loss of precision, and q4_0 uses about a quarter, with a loss that may be more noticeable at long context lengths. This is a global setting that applies to every model.

We cover these in our guides to setting Ollama's context length and KV cache quantisation in Ollama.

Running several things at once: OLLAMA_NUM_PARALLEL and OLLAMA_MAX_LOADED_MODELS

According to Ollama's FAQ, OLLAMA_MAX_LOADED_MODELS caps how many models can be loaded together, provided they fit in memory, and OLLAMA_NUM_PARALLEL sets how many requests each model handles at the same time. The FAQ warns that parallel requests increase the context size: a 2K context with four parallel requests becomes an 8K context with the extra memory that needs. On a GPU, new models must fit completely in VRAM to load alongside others. Our guides to running multiple models in Ollama and handling parallel requests explain the trade-offs.

Browser extensions: OLLAMA_ORIGINS

If a browser extension can't talk to Ollama, OLLAMA_ORIGINS is usually the fix. The FAQ says you can allow all Chrome, Firefox and Safari extensions with chrome-extension://*,moz-extension://*,safari-web-extension://*, or list specific ones. See our Page Assist guide for an example.

Choosing GPUs: CUDA_VISIBLE_DEVICES

On a PC with more than one NVIDIA graphics card, Ollama's GPU documentation says CUDA_VISIBLE_DEVICES limits which cards it uses. Numeric IDs work, but Ollama notes the order can vary, so it recommends the GPU's UUID, which nvidia-smi -L lists. An invalid ID such as -1 forces Ollama to use the CPU. For AMD cards, the equivalent is ROCR_VISIBLE_DEVICES. Our guide to choosing which GPU Ollama uses walks through it.

Cloud features: OLLAMA_NO_CLOUD

Ollama's FAQ says you can run in local-only mode by setting OLLAMA_NO_CLOUD=1, which turns off its cloud models and web search. After a restart, Ollama's logs should show Ollama cloud disabled: true.

How to check your settings worked

After restarting Ollama, check that it has picked up your changes:

  1. Look at the variable. Open a new PowerShell window and type $env:OLLAMA_MODELS (or the variable you set). If nothing comes back, the variable wasn't saved to your account.

  2. Check the server log. Ollama's Windows documentation says logs are in %LOCALAPPDATA%\Ollama, with the most recent server log in server.log. Press Win + R, type explorer %LOCALAPPDATA%\Ollama and open it. Our guide to finding Ollama's logs explains what to look for.

  3. Test the behaviour. For OLLAMA_MODELS, download a small model and check it appears in the new folder. For OLLAMA_KEEP_ALIVE, run a model and use ollama ps, which the FAQ says shows loaded models, how they're split between GPU and CPU and when they'll unload.

Our guide to checking whether Ollama is using your GPU covers ollama ps in more depth.

Common problems

  • Nothing changed. Ollama was probably still running. Quit it from the tray, not just a terminal, and relaunch it from the Start menu.

  • It works in one terminal but not the app. You set the variable with $env: or set, which only lasts for that window. Microsoft's documentation notes that set changes variables for the current console window only. Use Settings or setx instead.

  • Models vanished after changing OLLAMA_MODELS. They haven't been deleted. Ollama is looking in the new folder. Move the old files across or change the variable back.

  • Out-of-memory errors after raising context or parallel settings. Lower OLLAMA_CONTEXT_LENGTH or OLLAMA_NUM_PARALLEL, or try a quantised K/V cache. Our guide to fixing CUDA out-of-memory errors has more fixes.

Our verdict

Setting Ollama's environment variables in Windows Settings, or with setx, then fully restarting Ollama is the reliable way to change how it behaves. Start with OLLAMA_MODELS if your system drive is short of space and OLLAMA_KEEP_ALIVE if you're tired of waiting for models to reload. Only open OLLAMA_HOST to your network if you trust it, and raise context length and parallel requests in small steps so you don't run out of VRAM.

The bottom line

Setting Ollama's environment variables in Windows Settings, or with setx, then fully restarting Ollama is the reliable way to change how it behaves. Start with OLLAMA_MODELS if your system drive is short of space and OLLAMA_KEEP_ALIVE if you're tired of waiting for models to reload. Only open OLLAMA_HOST to your network if you trust it, and raise context length and parallel requests in small steps so you don't run out of VRAM.

Sources

  1. 01Ollama, FAQ
  2. 02Ollama, Windows documentation
  3. 03Ollama, Hardware support (GPU)
  4. 04Microsoft Learn, setx command

About the author

Marcus Thorne

Systems & Technical Editor

Marcus writes Forge PC's step-by-step build, troubleshooting and system optimisation guides. His background spans Windows kernel and power-state diagnostics, UEFI/BIOS configuration, NVMe storage arrays, ATX 3.1 power delivery and running local AI and LLM workloads on consumer graphics cards.

More from Marcus Thorne

Read next

Best Graphics Card for Video Editing in 2026

Best Picks

Best Graphics Card for Video Editing in 2026

For video editing, look at VRAM, hardware encoders and decoders, AV1 support and power. The RTX 5070 Ti is our best overall pick with 16GB and two NVENC encoders; the RTX 5060 Ti 16GB is the value choice at 180W; the RTX 5080 adds a second decoder; the 32GB RTX 5090 suits 8K and heavy projects; AMD's RX 9070 XT is the best Radeon option.

Hannah Vance6 min

Best SFF-Ready Graphics Cards for Small Form Factor PCs in 2026

Best Picks

Best SFF-Ready Graphics Cards for Small Form Factor PCs in 2026

NVIDIA's SFF-Ready label marks RTX 70-class and faster cards no taller than 151mm including the power cable bend, no longer than 304mm and no thicker than 2.5 slots. Our picks: MSI RTX 5070 Ti Ventus 3X OC overall, ASUS RTX 5070 Prime OC for value, and the two-slot RTX 5080 Founders Edition for slim high-end builds. Check case clearance and PSU first.

Hannah Vance7 min

Best Free Video Converters for Windows in 2026

Best Picks

Best Free Video Converters for Windows in 2026

HandBrake is the best free video converter for most Windows users: open source, with device presets, previews, a queue and NVENC and Quick Sync support for MP4, MKV and WebM output. Shutter Encoder is a free all-in-one toolbox with editing codecs, lossless trims, subtitles and burn-ins. FFmpeg is the command-line engine behind both, ideal for scripts and batch jobs.

Hannah Vance7 min

Audacity vs ocenaudio: Which Free Audio Editor Should You Use?

Versus

Audacity vs ocenaudio: Which Free Audio Editor Should You Use?

Audacity is the better free audio editor for most Windows users: open source, with recording and editing, noise reduction, VST3 plugins and a rebuilt interface in Audacity 4. ocenaudio is free and focused on fast single-file editing, with real-time effect previews, multi-selection, efficient handling of long files and recent voice tools.

Callum Reid7 min