Skip to content

Instantly share code, notes, and snippets.

@heartonbit
Created December 16, 2024 16:00
Show Gist options
  • Save heartonbit/6d9bc80c0d095ac378a6f05676a080ae to your computer and use it in GitHub Desktop.
Save heartonbit/6d9bc80c0d095ac378a6f05676a080ae to your computer and use it in GitHub Desktop.
ollama uninstallation bash script
#!/bin/bash
# Define colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}πŸ€– Ollama Uninstallation Script${NC}"
echo -e "${BLUE}-------------------------${NC}"
# Check if script is run with sudo
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}❌ This script requires root privileges.${NC}"
echo -e "${YELLOW}Please run with sudo: sudo $0${NC}"
exit 1
fi
# Check if Docker is running Ollama
if docker ps -a | grep -q ollama; then
echo -e "${YELLOW}🐳 Found Docker container for Ollama. Stopping and removing...${NC}"
if ! docker stop ollama 2>/dev/null; then
echo -e "${RED}⚠️ Failed to stop Ollama container - it may not exist${NC}"
elif ! docker rm ollama 2>/dev/null; then
echo -e "${RED}⚠️ Failed to remove Ollama container - it may not exist${NC}"
else
echo -e "${GREEN}βœ… Docker cleanup completed.${NC}"
fi
fi
# Check if Ollama is installed locally
if command -v ollama &> /dev/null; then
echo -e "${YELLOW}πŸ” Found local Ollama installation. Removing...${NC}"
# Stop and disable service
echo -e "${YELLOW}⏹️ Stopping Ollama service...${NC}"
systemctl stop ollama
echo -e "${YELLOW}🚫 Disabling Ollama service...${NC}"
systemctl disable ollama
# Remove service file
echo -e "${YELLOW}πŸ—‘οΈ Removing service file...${NC}"
rm -f /etc/systemd/system/ollama.service
# Delete binary
echo -e "${YELLOW}πŸ—‘οΈ Removing Ollama binary...${NC}"
rm -f $(which ollama)
# Cleanup remaining files and user/group
echo -e "${YELLOW}🧹 Cleaning up remaining files and user/group...${NC}"
rm -rf /usr/share/ollama
userdel ollama
groupdel ollama
echo -e "${GREEN}βœ… Local Ollama installation removed.${NC}"
else
echo -e "${RED}❌ No local Ollama installation found.${NC}"
fi
echo -e "${BLUE}-------------------------${NC}"
echo -e "${GREEN}✨ Ollama uninstallation completed!${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment