Skip to content

computerworxdev/Ollama_Unload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Ollama Unload

Version 0.1

unload_ollama_models.zsh is a small Z shell utility for macOS that checks for Ollama models currently loaded in memory, lists them, unloads them with ollama stop, and then runs purge to help recover inactive memory.

What The Script Does

When you run the script, it:

  1. Verifies that the ollama CLI is available.
  2. Verifies that sudo is available.
  3. Runs ollama ps to detect currently loaded Ollama models.
  4. Lists the models found in memory.
  5. Stops each loaded model with ollama stop <model>.
  6. Runs sudo purge at the end to help reclaim inactive memory.

If no Ollama models are loaded, the script still continues to the purge step.

If one or more models fail to stop, the script exits with an error before the purge step runs.

Requirements

  • macOS
  • Z shell (zsh)
  • Ollama installed and available in your PATH
  • Permission to use sudo

Usage

Make the script executable if needed:

chmod +x unload_ollama_models.zsh

Run it from the project directory:

sudo ./unload_ollama_models.zsh

Important Note About sudo

Running with sudo is mandatory for the final purge operation.

The script ends by running:

sudo purge

Because purge requires elevated privileges, you must run the workflow with sudo access available. The recommended way is to start the script with:

sudo ./unload_ollama_models.zsh

Example Flow

Typical behavior looks like this:

  • The script prints a section for checking loaded Ollama models.
  • It lists every model currently loaded in memory.
  • It attempts to stop each loaded model one by one.
  • If all stops succeed, it runs the final memory purge.
  • It prints a success message after purge completes.

Error Cases

The script stops with an error if:

  • ollama is not installed or not in PATH
  • sudo is not available
  • ollama ps fails
  • Any loaded model cannot be stopped
  • sudo purge fails

Project Files

  • unload_ollama_models.zsh - main script
  • README.md - project documentation
  • LICENSE - license file

About

remove loaded Ollama models from memory

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages