SafeITExperts

SafeITExperts

Your expert guide to cybersecurity and digital privacy. Security hardening for all platforms : Windows, macOS, Linux, and Android. Solutions aligned standards : NIST and ANSSI for comprehensive digital protection.


Ollama Cleanup Linux

Publié par Marc sur 28 Avril 2026, 06:45am

Catégories : #Ollama, #IT-Audit, #System-Security, #LLM-security

Audit methodology for a custom Ollama deployment: Action → Proof → Validation. Complete cleanup from Linux to macOS and Windows.

Audit methodology for a custom Ollama deployment: Action → Proof → Validation. Complete cleanup from Linux to macOS and Windows.

Complete Ollama Cleanup on Linux | SafeITExperts

Complete Ollama Cleanup on Linux

Audit methodology for a custom deployment | Signature: Action → Proof → Validation

Introduction

This SafeITExperts guide starts from a simple observation: Ollama can be deployed via:

  • manual compilation
  • an official script
  • a package manager (apt, zypper, pacman, nix, snap, flatpak…)

Each method scatters files in its own way. Native uninstall tools only remove what they themselves installed.

📌 Observation
User data, cross‑caches and environment variables remain in place.

This is precisely where the SafeITExperts methodology comes in.

Illustration of a Linux system with residual files and Ollama services before cleanup
Residues and ramifications left by a classic uninstall.
The fundamental question We are not looking for “how to make Ollama disappear?”, but rather “how to know, technically, that Ollama is truly gone and the system is clean?”. At SafeITExperts, we never assume a command succeeded. We validate it.

So this guide doesn't just list commands. It rests on a sanitization philosophy, an Action → Proof → Validation loop, and a pedagogy that teaches you to track down software ramifications. Structured in operational postures, it takes you from securing to final certification, whatever your operating system.

📋 Roadmap: Audit Matrix

PostureObjectiveRiskExpected ProofCrit.
Pre‑activeSecure the environmentAuto‑restartUnit not foundMed.
ReactiveEliminate footprintDisk saturation✅ Files removedHigh
PreventiveSanitize sessionVariable conflictsEmpty grepMed.
Pro‑activeZero residueBlind spotTriple validation Low

⚖️ Maintainer Approach vs SafeITExperts

To grasp the unique value of this methodology, here is what sets it apart from classic uninstall guides.

CriterionMaintainer Approach (Classic)SafeITExperts Approach (Audit)
Primary ObjectiveRemove the software from the system.Sanitize the system and validate cleanliness.
FocusPhysical cleanup (files, binaries, services).Physical + logical + environment sanitization.
ProcessSequential list of removal commands.Iterative loop:
Action → Proof → Validation.
ValidationOften implicit or absent.Explicitly integrated at each step with technical proofs.
User Configuration HandlingOften ignored or optional.Critical (e.g., cleaning of ANTHROPIC_*, OLLAMA_API_KEY).
Philosophy“Make the software disappear”.“Confirm the disappearance” of the software and its effects.
Concrete example An OLLAMA_API_KEY variable added in .zshenv survives the official uninstall. Later, another AI tool could pick it up and cause inexplicable errors. The SafeITExperts purge eliminates this risk at the root.

1. Pre‑active Posture: Secure

Neutralize any activity or automatic service restart.

Bash sudo systemctl stop ollama
sudo systemctl disable ollama
sudo rm -f /etc/systemd/system/ollama.service
sudo systemctl daemon-reload
Educational note Stopping the service and removing the systemd unit are critical. Trying to delete binaries while the process is active can create “deleted” files still held in RAM, preventing real disk space reclamation.
🔍 Proof of success:
Run systemctl status ollama
Expected result: "Unit ollama.service could not be found."
Validation: Automatic restart is impossible. The intervention can proceed without risk.

2. Reactive Posture: Physical Cleanup

Eliminate binaries and massive data. Adapt the paths according to your installation method (Snap, Flatpak, manual, etc.).

If you used a package manager, start with the appropriate uninstall command:

Examples per distribution sudo apt remove ollama # Debian / Ubuntu sudo zypper rm ollama # openSUSE sudo pacman -Rns ollama # Arch Linux nix profile remove ollama # NixOS snap remove ollama # Snap flatpak uninstall com.ollama.Ollama # Flatpak
📊 Disk space before cleanup:
du -sh ~/.ollama ~/.cache/ollama ~/.cache/huggingface 2>/dev/null
Record the occupancy to measure the freed space after the intervention.
Bash # 1. Verify the real path (Audit precaution) which ollama # 2. Targeted removal sudo rm -f /usr/local/bin/ollama rm -rf ~/.ollama ~/.cache/ollama ~/.cache/huggingface/hub/models--*qwen* sudo rm -rf /var/cache/ollama
⚠️ DANGER: Risk of accidental deletion Using wildcards like rm -rf ~/.cache/*ollama* is risky. If another folder contains the word “ollama” by chance, it will be deleted. Always use explicit paths like ~/.cache/ollama or use the find command with strict regular expressions.

2.1 Cleaning the ollama group and the system user

During a classic uninstall, the ollama group can survive, especially if it still contains members (e.g., the crisis user). The commands below clean up this invisible but troublesome residue.

Bash (Group audit) # Find files still belonging to the ollama group sudo find / -group ollama 2>/dev/null # Remove the 'crisis' user from the ollama group sudo gpasswd -d crisis ollama # Check that the group is empty (should no longer contain any user) getent group ollama # Expected output: ollama:x:424: # Delete the now empty group sudo groupdel ollama
Educational note If groupdel refuses because files still belong to the group, reassign them (e.g., sudo chgrp users /path/file) or delete them before running the command again. This step guarantees a system without an orphan identity.
🔍 Proof of success:
getent group ollama must return an empty line (no entry).
Validation: The group footprint has disappeared. No process can inherit those permissions.
Technical note: The Hugging Face ecosystem Including the models--*qwen* path illustrates a crucial nuance: Ollama interacts with the Hub Model Registry. Some downloaded models do not reside in ~/.ollama but in the centralized Hugging Face cache. Ignoring them means leaving dozens of GB of residues.
🔍 Proof of success:
if [ ! -f /usr/local/bin/ollama ] && [ ! -d ~/.ollama ]; then echo "✅ Physical files removed"; else echo "❌ Check residues"; fi
Validation: Footprints eradicated, disk space freed. Confirm with df -h the space recovery.

3. Preventive Posture: Sanitize the Shell

Purge orphan environment variables to avoid ghost pollution.

Zsh / Bash # For Zsh
sed -i '/ANTHROPIC_/d' ~/.zshrc ~/.zshenv
unset ANTHROPIC_*
exec zsh

# For Bash
sed -i '/ANTHROPIC_/d' ~/.bashrc ~/.profile
unset ANTHROPIC_BASE_URL
exec bash
Educational note Cleaning cross‑variables (e.g., Anthropic) prevents future AI installations from using obsolete configurations. This principle also applies to any Ollama‑specific variable such as OLLAMA_API_KEY or OLLAMA_HOST that may have been manually added to your shell files.
🔍 Proof of success:
grep -iE "ANTHROPIC_|OLLAMA_" ~/.zshrc ~/.bashrc ~/.zshenv ~/.bash_profile ~/.profile || echo "✅ No orphan variable detected"
Validation: No risk of automatic injection at startup.

4. Pro‑active Posture: Final Audit

Global validation and certification of system cleanliness.

Audit Script which ollama || echo "✅ Binary clean"
env | grep -iE "anthropic|ollama" || echo "✅ Env clean"
systemctl | grep ollama || echo "✅ Services clean"
🔍 Final validation:
Displaying the three statements certifies total sanitization.

🪟 Windows Adaptation (PowerShell)

The audit methodology is universal. Here is its adaptation to a Windows environment, following the same Action → Proof → Validation loop.

1. Pre‑active Posture (Windows)

Stop and disable the Ollama service.

PowerShell (Admin) Stop-Service -Name "Ollama" Set-Service -Name "Ollama" -StartupType Disabled
🔍 Proof: Get-Service -Name "Ollama" must display Stopped and Disabled. Trying Start-Service -Name "Ollama" must fail.

2. Reactive Posture (Windows)

Delete the application and user data.

PowerShell Remove-Item -Path "C:\Program Files\Ollama" -Recurse -Force Remove-Item -Path "$env:USERPROFILE\AppData\Roaming\Ollama" -Recurse -Force Remove-Item -Path "$env:USERPROFILE\AppData\Local\Ollama" -Recurse -Force
Note: If the application was installed in Program Files (x86), adjust the path.
🔍 Proof: Test-Path "C:\Program Files\Ollama" must return False. Do the same for the AppData paths.

3. Preventive Posture (Windows)

Clean orphan environment variables.

PowerShell [Environment]::SetEnvironmentVariable("OLLAMA_HOST", $null, "User") [Environment]::SetEnvironmentVariable("OLLAMA_API_KEY", $null, "User")
🔍 Proof: Open a new terminal and run $env:OLLAMA_HOST; the output must be empty. Also check in the registry HKCU:\Environment.

4. Pro‑active Posture (Windows)

Global search and registry inspection.

PowerShell Get-ChildItem -Path C:\ -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*ollama*" }
🔍 Proof: No results. The system must run without any Ollama‑related errors.

🍎 macOS Adaptation (Terminal)

On macOS, the logic remains identical; only the paths and service management commands change.

1. Pre‑active Posture (macOS)

Unload the launchd agent.

Bash sudo launchctl unload /Library/LaunchDaemons/com.ollama.server.plist
🔍 Proof: launchctl list | grep ollama must return nothing.

2. Reactive Posture (macOS)

Remove the application and its basic data.

Bash rm -rf "/Applications/Ollama.app" rm -rf "~/Library/Application Support/Ollama" rm -rf ~/Library/Caches/ollama rm -rf ~/Library/Preferences/com.ollama.Ollama.plist rm -rf ~/.ollama
🔍 Proof: ls "/Applications/Ollama.app" must return No such file or directory. Check the other paths similarly.

3. Preventive Posture (macOS)

Purge orphan environment variables (same as Linux).

Bash sed -i '/OLLAMA_/d' ~/.zshrc ~/.zshenv exec zsh
🔍 Proof: grep "OLLAMA_" ~/.zshrc must remain empty.

4. Pro‑active Posture (macOS)

Use Spotlight for an exhaustive search.

Bash mdfind ollama
🔍 Proof: No occurrences found. The system is healthy.

🧹 Exhaustive Cleanup (official 2026 documentation)

The official Ollama documentation for macOS recommends removing additional residues that the basic procedure may leave. These commands clean the binary installed outside the App, WebKit caches, saved state, and the ~/.ollama folder. Difference from the previous step: the first method removes the application and main preferences; this one targets system nooks and guarantees complete disintegration.

Bash (Advanced cleanup) sudo rm /usr/local/bin/ollama rm -rf "~/Library/Saved Application State/com.electron.ollama.savedState" rm -rf ~/Library/Caches/com.electron.ollama/ rm -rf ~/Library/WebKit/com.electron.ollama
Why these paths?
  • /usr/local/bin/ollama – binary installed manually or via a script.
  • Saved Application State – windows and states restored by macOS.
  • WebKit/com.electron.ollama – caches of the Electron interface.
🔍 Proof of success:
ls /usr/local/bin/ollama ~/Library/Caches/com.electron.ollama 2>&1 | grep "No such"
Validation: All references are resolved. Run mdfind ollama again to confirm nothing remains.

🛠️ Towards a Runbook Culture

An expert never types the same commands twice. They script, test, and document.

1. Script the procedure

Turn this entire guide into a versioned shell script (Git). Each step must produce an explicit return code to automate validation.

2. Test in pre‑production

Run the script on a staging machine or a disposable VM before any production intervention. Validate the absence of regressions.

3. Document & sign

Integrate the runbook into your internal documentation, add test results and the validation signature. That’s how a simple tutorial becomes a certified change engineering process.

⚠️ The Traps of Improper Uninstall

Hidden Files

LLM models weigh gigabytes. A forgotten ~/.ollama folder = disk saturated for no apparent reason.

Zombie Services

A .service file without a binary creates a crash loop, polluting CPU and system logs.

Env Pollution

Orphan variables in the .bashrc cause inexplicable bugs upon reinstallation.

🚨 Security Risk: Exposed Ollama Servers

Even after a partial uninstall, a residual Ollama service exposed on the network can be exploited. Security researchers (Indusface, Jitendar Singh) have documented cases where unprotected instances allowed malicious model execution, data theft, or access to the local infrastructure. Ensure no ollama serve process is listening on a public interface. Use netstat -tlnp | grep ollama to verify. Simply deleting files is not enough if the service was exposed – the validation phase must include this network check.

Read Indusface analysis ↗ | Mitigating Risks (Medium) ↗

🛡️ The Validation Triptych

Physical Cleanup

Target: Binaries, Configs, Data and Caches.

Logical Cleanup

Target: systemd services, Active processes and Variables.

Proof by Audit

Target: The positive failure (command not found).

Intervention Summary & Conclusion

PostureActionProofVerdict
Pre‑activeStop ServiceUnit not foundSecured
Reactiverm -rfNo such fileSpace recovered
Preventivesed / unsetEmpty grepConflicts avoided
Pro‑activeCross‑auditTriple ✅Certified Clean
Linux terminal showing the final audit result: Binary clean, Env clean, Services clean, disk space freed
Certified final audit: all three proofs of success obtained.
🏁 Conclusion: A Gold Standard

Ultimately, a clean uninstall is not a one‑time deletion action, but a continuous validation process aimed at restoring the initial, pure state of a system. The methodology described here, with its rigorous Action → Proof → Validation loop, should not be seen as an option, but as the gold standard for any responsible system administration, applicable not only to Ollama but to any software on any platform.

📚 SafeITExperts Recommended Reading

ReferenceDescriptionLink
Linux File System 2026Analysis of best practices for auditing and migrating your file systems securely.Read ↗
IT Problem: Solve Without BreakingMethodology to diagnose and solve a problem without making it worse.Read ↗
OS Security Panorama 2026: Linux, Windows, macOS, BSDComparison of security postures of major operating systems in 2026.Read ↗
Linux Secure by Default? Verify in 2026Guide to assess whether your Linux distribution meets current security standards.Read ↗
Fork Bomb Linux: Security & Hardening Guide 2026Understand and protect against fork bombs, with hardening measures.Read ↗

🔍 Verified Sources

DomainOfficial ReferenceVerifiable URL
Linux UninstallOfficial Ollama Documentation – Linuxdocs.ollama.com/linux ↗
macOS UninstallOfficial Ollama Documentation – macOSdocs.ollama.com/macos ↗
Windows UninstallOfficial Ollama Documentation – Windowsdocs.ollama.com/windows ↗
LLM SecurityExposed Ollama Servers – IndusfaceIndusface Blog ↗
Risk MitigationNavigating the Local LLM Landscape – Jitendar Singh (Medium)Medium ↗

About the Author

Marc is the lead editor of SafeITExperts, a bilingual FR/EN technical blog dedicated to cybersecurity, Linux, and digital sovereignty.

Pour être informé des derniers articles, inscrivez vous :
Commenter cet article

Archives

Nous sommes sociaux !

Facebook X Bluesky Mastodon GitHub Reddit RSS

Articles récents