Ollama keeps up to three models loaded by default and unloads the least recently used one when a new model needs the memory. If you switch between a chat model and an embeddings model all day, that churn costs you a reload on every switch. Setting OLLAMA_MAX_LOADED_MODELS raises the ceiling so both stay in memory.
Before you start
- Ollama installed, with two models already pulled, for example qwen3:8b and nomic-embed-text.
- Enough RAM or VRAM for both models at once; two 8B Q4 models need roughly 10 GB plus overhead.
- A terminal, and on Linux, the way you start Ollama (systemd service or a terminal session).
See what is loaded now
List the models currently in memory:
ollama ps
Load a second model in another terminal with ollama run nomic-embed-text, then run ollama ps again to see both entries and how long each has been loaded.
Set the variable
On Linux, stop the service, set the variable, and restart it:
systemctl --user stop ollama
OLLAMA_MAX_LOADED_MODELS=2 systemctl --user start ollama
On macOS or Windows, set OLLAMA_MAX_LOADED_MODELS=2 in the environment before starting Ollama from a terminal, or in the system environment settings. The variable only takes effect when Ollama starts, so a running server must be restarted.
Verify both stay loaded
Load both models, wait a few minutes, then run ollama ps again. Both should still be listed. If one is missing, the machine did not have enough memory for both and Ollama unloaded one; lower the number or pick smaller models.
Worked example
Worked example: with OLLAMA_MAX_LOADED_MODELS=2, run ollama run qwen3:8b in one terminal and ollama run nomic-embed-text in another, then send a chat prompt to the first. The second prompt should answer at once, without the several-second reload pause you would see if the model had been unloaded.
Expected result
UNTESTED in this guide: no server was restarted while writing it. The expected result is that ollama ps shows both models loaded after the change, and switching between them answers without a reload delay.
Limitations
Raising the limit does not create memory: if both models do not fit, Ollama still unloads one, and on a tight machine it may split a model between GPU and CPU and slow it down. Keep the value at 2 unless you have measured the free memory.
