How to change place of saving models on ollama

Hamed0406 - Jul 30 - - Dev Community

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:

  1. 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.
  1. 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.
  1. Restart Ollama:
  • Quit Ollama if it's running.
  • Restart Ollama to ensure it recognizes the new environment variable.
  1. 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

  1. 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.
  1. Reload and Restart:
  • Run systemctl daemon-reload.
  • Restart Ollama with systemctl restart ollama.

macOS

  1. 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

. . . . . . . . .
Terabox Video Player