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.
When you run the script, it:
- Verifies that the
ollamaCLI is available. - Verifies that
sudois available. - Runs
ollama psto detect currently loaded Ollama models. - Lists the models found in memory.
- Stops each loaded model with
ollama stop <model>. - Runs
sudo purgeat 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.
- macOS
- Z shell (
zsh) - Ollama installed and available in your
PATH - Permission to use
sudo
Make the script executable if needed:
chmod +x unload_ollama_models.zshRun it from the project directory:
sudo ./unload_ollama_models.zshRunning with sudo is mandatory for the final purge operation.
The script ends by running:
sudo purgeBecause 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.zshTypical 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.
The script stops with an error if:
ollamais not installed or not inPATHsudois not availableollama psfails- Any loaded model cannot be stopped
sudo purgefails
unload_ollama_models.zsh- main scriptREADME.md- project documentationLICENSE- license file