Created
December 16, 2024 16:00
-
-
Save heartonbit/6d9bc80c0d095ac378a6f05676a080ae to your computer and use it in GitHub Desktop.
ollama uninstallation bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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