November 2, 2024

How to Completely Uninstall Ollama and Erase LLM Models on Linux Systems?

In this Large Language Model (LLM) tutorial, we explain how to uninstall Ollama and how to erase LLM Models on Linux Systems. In particular, in this tutorial, we explain how to do these steps for Linux Ubuntu systems. However, everything explained in this tutorial can be used for other Linux distributions. The main question is why we would like to uninstall Ollama. Well, sometimes this is necessary if for some reason Ollama stops working properly, or if we want to install a newer version or perform a clean install. The challenge with uninstalling Ollama as well as similar Linux programs is that files and packages are scattered around various Linux folders. Furthermore, by uninstalling Ollama, we will not automatically erase all the model folders that can be extremely large (sometimes hundreds of GB). The YouTube tutorial accompanying this video tutorial is given below.

Before we start with explanations, let us first plocate tool. This tool will be used to search for files and folders on our system. Open a terminal and type:

sudo apt install plocate
sudo updatedb

Then, let us start with identifying all the folders that contain Ollama:

sudo plocate ollama

This command will list all the folders and files on our system containing Ollama in their name. We can observe several folders:

/usr/local/bin/ollamaThis is the installation folder of Ollama. this can be confirmed by typing which ollama

/usr/share/ollama – Contains Ollama model files and folders

/home/aleksandar/.olama – This folder contains some configuration and history files

/etc/systemd/system/ – This folder contains some Ollama service files

To uninstall Ollama, execute the following set of commands. First, remove the Ollama service

sudo systemctl stop ollama
sudo systemctl disable ollama
sudo rm /etc/systemd/system/ollama.service

Next, we need to remove the Ollama binary and installation files. We do it like this:

sudo rm $(which ollama)

The next step is very important. In the next step, we remove the model files that can occupy a significant space on our local disk. We erase the model folders like this:

sudo rm -r /usr/share/ollama

There is a chance that your model folders are not stored in this folder. Just in case, perform search with

sudo updatedb
sudo plocate ollama

You can identify the model folder as a folder that contains bolbs and manifests subfolders.

Next, we need to remove service and user groups

sudo userdel ollama
sudo groupdel ollama

After this, erase the folder .olama in the home folder, as well other folders that the find command “sudo plocate ollama” finds.

rm -rf /home/aleksandar/.ollama