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