DEV Community

Hamed0406
Hamed0406

Posted on

133

How to change place of saving models on ollama

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (3)

Collapse
 
claudian_tenegri_ded748b6 profile image
Claudian Tenegri

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?

Move-Item -Path "$env:USERPROFILE\.ollama\models\*" -Destination "D:\your_new_path\" -Force
Enter fullscreen mode Exit fullscreen mode

Next, it is required to close Ollama (don't restart it manually), go again in powershell and execute

ollama list
Enter fullscreen mode Exit fullscreen mode

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 :)

Collapse
 
maxim_bandel_55e7b361b888 profile image
Maxim Bandel

didn't work "(

Collapse
 
carlos_correa_ed6570d2335 profile image
Carlos Correa • Edited

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay