
Ollama Out of Space? Move Models to Another Drive and Fix Context Length
Also available in Hindi: यह लेख हिंदी में पढ़ें
To change where Ollama stores models, set the OLLAMA_MODELS environment variable to a folder on a bigger drive and restart Ollama. Ollama's docs warn that models can be tens to hundreds of GB, so this is the first fix when your home drive fills up. The second common problem is a context window that is too small for agents and coding tools. Both are covered below.
Where your models are now
- macOS:
~/.ollama/models - Windows:
C:\Users\<you>\.ollama\models - Linux (standard installer):
/usr/share/ollama/.ollama/models
Move models to another drive
Windows. Quit Ollama from the taskbar. Open Settings, search for environment variables, click Edit environment variables for your account and add OLLAMA_MODELS with the new folder, for example D:\ollama-models. Click OK, then start Ollama again from the Start menu or a new terminal. The installer also accepts OllamaSetup.exe /DIR="D:\some\location" if you want the app itself off C:.
macOS. Run launchctl setenv OLLAMA_MODELS "/Volumes/External/ollama-models" and restart the Ollama app.
Linux. Stop the service, copy the old folder to the new location, then give it to the ollama user with sudo chown -R ollama:ollama /path/to/folder. Run sudo systemctl edit ollama.service, add Environment="OLLAMA_MODELS=/path/to/folder" under [Service], then systemctl daemon-reload and systemctl restart ollama. Setting the variable in your own terminal does not change the running service.
Copy your existing models across before you restart if you don't want to download them again. Afterwards, ollama list should still show them. Keep the old folder until a model runs from the new one.
Fix a context window that is too small
Ollama picks a default by GPU memory: 4k tokens under 24 GiB of VRAM, 32k from 24 to 48 GiB, and 256k at 48 GiB or more. Its docs suggest at least 64,000 tokens for agents, coding tools and web search. Raise it with the slider in the app's settings, or start the server with OLLAMA_CONTEXT_LENGTH=64000 ollama serve. In a chat, /set parameter num_ctx 8192 works, and API calls accept num_ctx in options.
A bigger window needs more memory. Run ollama ps: the CONTEXT column shows the window you got, and PROCESSOR should say 100% GPU. A CPU/GPU split means slower answers, so pick a smaller model or a smaller window.
For a front end, see our Open WebUI 0.13 upgrade guide or Continue.dev with local Ollama. Compare runners in best tools to run LLMs locally and on the Ollama tool page.
Sources
- Ollama FAQ: where models are stored, environment variables, context window
- Ollama docs: Windows (changing model and install location)
- Ollama docs: Context length
- How to set the Ollama model directory, Simplified Guide
- Ollama context length and local model sizing, rConfig docs
FAQ
Will moving the folder delete my models?
No, as long as you copy them first. Otherwise Ollama starts with an empty folder and you pull them again.
Why did my change not work on Linux?
The service runs as the ollama user. Set the variable in the systemd service and give that user access to the folder.
What context length should I use?
At least 64k for agents and coding tools, if your GPU has room. Check with ollama ps.
Can I use an external drive?
Yes, if it is connected and mounted whenever Ollama starts.