To change the default location where Ollama saves its models, you need to set an environment variable called OLLAMA_MODELS to the desired directory. Here's how you can do it on different operating systems:
Windows
Open Environment Variables:
- Press Win + X and select System.
- In the System window, click on Advanced system settings on the left sidebar.
- In the System Properties window, click on the Environment Variables... button.
- Create a New Environment Variable:
- In the Environment Variables window, look for the System variables section and click on New....
- Enter OLLAMA_MODELS for the Variable name.
- Enter the path where you want to save the model files for the Variable value (e.g., D:\OllamaModels).
- Click OK to save the new environment variable.
- Restart Ollama:
- Quit Ollama if it's running.
- Restart Ollama to ensure it recognizes the new environment variable.
- Verify the New Location:
- Download a new model and check if it is saved in the new directory (e.g., D:\OllamaModels\models\blobs).
Linux
- Edit Systemd Service:
- Open a terminal and run systemctl edit ollama.service.
- Add the line Environment="OLLAMA_MODELS=/path/to/new/location" under the [Service] section.
- Save and exit the editor.
- Reload and Restart:
- Run systemctl daemon-reload.
- Restart Ollama with systemctl restart ollama.
macOS
- Set Environment Variable:
- Open a terminal and use the command launchctl setenv OLLAMA_MODELS /path/to/new/location.
- Restart the Ollama application to apply the changes.
If the environment variable approach does not work, another method is to create a symbolic link (symlink) or use a bind mount (on Linux). This involves moving the models directory to the new location and linking it back to the original path, ensuring Ollama can still find the models without needing to be reconfigured.
For detailed steps and troubleshooting, you can refer to the official documentation and community solutions:
GitHub Issue Discussions: GitHub
Step-by-step guide: SkillsFoster
Bind Mount for Linux: Arch Linux Forums
Top comments (3)
Hi,
If i may propose a review, after creating the new variable under System (make sure your new_path_doesn't_has_spaces in name).
Suggest as well, to keep the same folder tree in the new path like is found under %userprofile%.ollama\models
Powershell fan?
Next, it is required to close Ollama (don't restart it manually), go again in powershell and execute
This will not only restart Ollama but also shows the new env path and models present there. I don't thing it's needed at this step to download a new model to see where it is downloaded :)
didn't work "(
Make sure you have ollama stopped, enter 127.0.0.1:11434/ in your browser, if ollama is running it will tell you that, to stop ollama, at least for me who uses windows, just need to go to the taskbar at the bottom right, click in the up arrow and stop ollama from its icon with right click, if you previouly changed the environment variable to the new directory once you open a new shell it should work as intended