我写这篇笔记的起因很朴素:C 盘被模型文件吃掉快 60G,想清理的时候才发现,"卸载 Ollama"这件事压根没有想象中那么简单。
在设置里点了卸载,回头敲一句 ollama list,模型还在。手动删了模型目录,手一抖又执行了 ollama serve,服务居然还能起来。折腾半天才想明白,Ollama 不是那种"装在一个文件夹里、删了就没"的软件,它在系统里散着好几层东西,任何一层没清干净,你都会怀疑自己是不是卸载失败了。
下面是我自己走了一遍的完整流程,Windows、Linux 都覆盖到了,最后再讲重装以后最该先做的一件事。
一、动手之前,先看清 Ollama 留了几摊东西
很多人卸载翻车,是从第一步就删错了地方。Ollama 的安装实际上分成了四块,弄清楚这四块,后面每一步清理才有意义。
程序本体。Windows 上是安装包装出来的程序目录,Linux 上是 /usr/local/bin/ollama 这么一个二进制文件。它是真正跑推理的服务端,启动后在本机监听 127.0.0.1:11434。
命令行工具和 PATH。Windows 安装包会顺手把 Ollama 的路径写进环境变量。程序本体即使删了,PATH 里那条指向还在,你在终端敲 ollama 照样有反应,只不过是个报错的"死命令"。不了解这一层的人,常常误以为卸载失败。
后台服务。Windows 靠托盘程序和开机启动项,Linux 走 systemd。服务没停,进程就在,文件句柄还被占着。
模型仓库和缓存。这是占空间的大头,默认位置有两个:
- Windows:C:\Users<你的用户名>.ollama\models
- Linux 用官方脚本安装时:/usr/share/ollama/.ollama/models
这个目录下面分 blobs 和 manifests 两层。blobs 里是哈希命名的分片文件,模型的实际数据都在这里;manifests 存的是索引信息,体积很小。所以千万别跑到 blobs 里按模型名找文件,磁盘上根本看不出对应关系,很容易误删别的模型。
如果你之前用环境变量 OLLAMA_MODELS 把模型挪过位置,那上面的默认路径就不作数了,得按你设过的路径来。顺手看一眼当前到底用了哪个目录,不亏。
二、各平台彻底卸载
原则是先停服务、再删模型、然后卸程序、最后清残留,顺序别颠倒。
Windows
先退掉托盘里的 Ollama,再用任务管理器确认没有 ollama.exe 残留进程。剩下的步骤:
- 在"设置 → 应用 → 已安装的应用"里找到 Ollama,点卸载;用 winget 装的也可以直接 winget uninstall Ollama.Ollama。
- 删掉模型目录:C:\Users<你的用户名>.ollama。顺手看一眼 %LOCALAPPDATA%\Ollama,有些版本会把日志和运行时文件放这儿,程序本体默认装在 %LOCALAPPDATA%\Programs\Ollama,卸载器失效时应手动检查,一并清掉。
- 打开"环境变量"窗口,检查有没有 Ollama 相关的条目(比如你之前加过的 OLLAMA_MODELS、OLLAMA_HOST),不需要就删掉,免得下次重装读到旧配置。
- 新开一个终端敲 ollama --version,提示命令不存在,才算清干净。
Linux
用官方脚本安装的情况,按顺序执行:
# 停服务并取消开机自启
sudo systemctl stop ollama
sudo systemctl disable ollama
# 删除服务定义文件
sudo rm /etc/systemd/system/ollama.service
sudo systemctl daemon-reload
# 删除二进制文件(位置可能是 /usr/local/bin 或 /usr/bin)
sudo rm $(which ollama)
# 删除模型和 Ollama 专用用户、用户组
sudo rm -r /usr/share/ollama
sudo userdel ollama
sudo groupdel ollama
# 如果你不是用官方脚本安装,而是以普通用户身份直接运行 Ollama,模型可能在 ~/.ollama/models
rm -rf ~/.ollama
Docker
如果你是通过容器跑的,就简单得多:
docker stop ollama
docker rm ollama
docker image rm ollama/ollama
# 如果建过命名卷,一并删掉
docker volume rm ollama
三、重新部署
环境清干净了,接着装。装之前先算一笔硬件的账,免得模型一下载就卡在"能不能跑得动"上。
装之前先看清硬件
模型大小和你的内存、显存直接挂钩。往大了选不是勇气,是折磨:
普通笔记本上先拿 7B 级别的中文模型练手,跑顺了再往上加。
安装(Windows / Linux)
- Windows:官网下 OllamaSetup.exe,双击一路 Install,装完托盘会出现小羊驼图标。也可以在 PowerShell 里跑 irm https://ollama.com/install.ps1 | iex。
- Linux:一行脚本搞定,它会自动注册 systemd 服务:
curl -fsSL https://ollama.com/install.sh | sh
装完在终端执行 ollama --version,能打印出版本号就说明服务已经就位。
ollama --version
ollama version is 0.5.4
systemctl status ollama
● ollama.service - Ollama Service
Loaded: loaded (/etc/systemd/system/ollama.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2026-10-31 14:01:29 CST; 31min ago
Main PID: 1551 (ollama)
Tasks: 9
Memory: 4.4G
CGroup: /system.slice/ollama.service
└─1551 /usr/local/bin/ollama serve
Oct 31 14:05:54 dockerRegistry ollama[1551]: llm_load_print_meta: FIM REP token = 151663 '<|repo_name|>'
Oct 31 14:05:54 dockerRegistry ollama[1551]: llm_load_print_meta: FIM SEP token = 151664 '<|file_sep|>'
........
重装后的第一件事:先把模型位置钉死
这一步很多人跳过,然后过两周又被 C 盘塞满。Ollama 的模型路径完全由环境变量 OLLAMA_MODELS 决定,服务启动那一刻读一次。所以别再等下载完才想着迁移,装完立刻设。
先建一个不含中文和空格的目录,比如 D:\ollama\models,然后:
- Windows:在"环境变量"里新建 OLLAMA_MODELS,值填目标目录;之后彻底退出 Ollama 再启动,甚至注销重登一次,确保后台进程读到新值。
- Linux:在 ~/.zshrc 或 ~/.bashrc 里加 export OLLAMA_MODELS=~/ollama/models。如果你用的是 systemd 服务,光在 shell 里 export 没用,得改服务配置里的 Environment 项:
sudo systemctl edit ollama.service
# 在 [Service] 段落下加一行:
# Environment="OLLAMA_MODELS=/mnt/data/ollama/models"
sudo systemctl daemon-reload # 非必需
sudo systemctl restart ollama
想确认改成了没,敲 ollama list 看模型列表,路径改对后 ollama list 应该是空的,这是正常的,重新 pull 即可;若仍能看到旧模型,说明服务还在用旧路径。或者直接去目标目录看有没有生成 blobs、manifests 两层结构。
拉第一个模型
选个轻快的起步,比如:
ollama run deepseek-r1:7b
# 量机型可换 deepseek-r1:1.5b
第一次执行会自动下载,下完直接进对话界面。只想下载不想马上聊,用 ollama pull deepseek-r1:7b。想退出对话,输入 /exit。
想验证接口通不通,可以用一条 curl:
curl http://localhost:11434/api/generate -d '{
"model": "deepseek-r1:7b",
"prompt": "用一句话解释什么是递归",
"stream": false
}'
{"model":"deepseek-r1:7b","created_at":"2026-10-31T07:32:42.178431852Z","response":"<think>嗯,我现在要理解一下什么是递归。首先,我看到“递归”这个词由“递”和“归”组成。字面意思可能是指逐步回来的意思吧?那在编程里面,递归应该是什么样的呢?......<think>\n\n递归是程序中一种函数或过程调用自身的方式,用于解决可分解为相似子问题的问题。它通过将问题逐步缩小规模,直到达到基本情况(终止条件),再逐步返回结果,从而避免重复计算并提高代码的可读性。","done":true,"done_reason":"stop","context":[151644,....,1773],"total_duration":157202417280,"load_duration":3168462007,"prompt_eval_count":9,"prompt_eval_duration":1761000000,"eval_count":586,"eval_duration":152237000000}
# 注意 response 里 <think> 段是 R1 这类推理模型的思考过程,属于正常输出,最终答案在它之后。
能正常返回 JSON,就说明本地服务完全可用,接下来各类支持 OpenAI 兼容接口的客户端、编辑器插件都能接上来了。
四、几个值得提前知道的环境变量
Ollama 没有独立的配置文件,所有关键设置都走环境变量,改完重启服务才生效。除了 OLLAMA_MODELS,还有几个会经常用到:
- OLLAMA_HOST:监听地址,默认只对本机开放。想让局域网其他设备调用,设成 0.0.0.0:11434;想换端口,也在这里带上,比如 0.0.0.0:8080。
- OLLAMA_ORIGINS:浏览器端跨域调用时用来放开来源,测试阶段可以设成 *。
- OLLAMA_KEEP_ALIVE:模型加载后驻留内存的时间,默认 5 分钟。频繁用的话调大些,比如 24h,能省掉反复加载的等待。
- OLLAMA_MAX_LOADED_MODELS 和 OLLAMA_NUM_PARALLEL:同时加载的模型数、并发请求数,机器内存充足时可以适当放开。
五、几个常见的坑
- 改完变量没生效。基本都是忘了重启服务。环境变量在进程启动时读一次,之后改系统变量不影响已经跑着的进程。
- 下载模型卡住或者超时。先确认服务在运行、网络通;实在慢的话,换个时间段,或通过 HTTPS_PROXY 走代理加速(注意不要设 HTTP_PROXY,官方 FAQ 明确提示它可能中断客户端连接)。Ollama 没有"镜像加速变量"这类东西,别去找不存在的开关。
- Linux 上 export 了变量但服务还是用旧路径。因为服务不是从你的 shell 启动的,必须在 systemd 的 Environment 里改。
- 删了模型空间没回来。检查是不是有两份模型目录——旧路径和新路径各存了一份,迁移时复制完忘了删旧的。
整个流程走下来,其实就两件事:卸载时记住 Ollama 有四层残留,别只删程序;重装时先把模型位置定好,别等 C 盘报警才想起迁移。环境干净了,后面不管是接本地知识库、写 Agent,还是纯离线聊天,都会省心很多。
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
The reason I'm writing this is so simple: the C drive was eaten by a model file, 60G, and it wasn't as simple as it would have been if I had to clean it up.
In the settings, you click off, and then you knock, and the model is still there. The model catalogue was manually deleted, and then the olama service was executed, and the service was able to get up. It took half a day to figure out that Ollama wasn't the kind of software that was "packed in a folder and deleted without" and that it had layers of stuff in the system, and any layer of it was clean, and you'd wonder if you'd failed.
And here's the whole process that I went through, and Windows and Linux covered it, and finally, the first thing to do after reloading.
First, before we do it, we'll see what Ollama left behind.
Many people unloaded the overturns and deleted the wrong place from the first step. Ollama's installation is actually divided into four pieces, and it makes sense to figure out the four pieces and clean them up every step.
The essence of the procedure. Windows is a packaged program directory, Linux is a binary file. It is a truly deduced service-end that, when activated, listens to this machine 127.0.0.1:11434.
command line tool and PATH. Windows installation packages write the path of Ollama to the environment variable. Even if it was deleted, the one in PATH was still there, and you banged at the terminal and responded to it, it was just a dead order. Those who do not know this are often mistaken for failure to unload.
Backstage service. Windows started with the tray program and on-board, Linux went systemd. The service has not stopped, the process is under way and the document is still under occupation.
Model warehouse and cache. It's the big head of space, with two default positions:
-Windows: C:Users.
- Linux when installed in official scripts:/usr/share/ollama/.ollama/models
Below this directory are the blobs and layers. Blobs is a sub-file named by Hashi, where the actual data of the model are; they store index information in small volumes. So don't go to the blobs to find files by model name. There's no correlation on the disk. It's easy to delete other models.
If you've moved the model with the environment variable, OLAMA MODELS, the default path above will not be counted, but will have to follow the path you set. Take a look at which directory is currently used.
II. COMPLETE LEFT FORMS
The principle is to stop the service, then delete the model, then unload the procedure, and finally clear the residue, in a different order.
Windows
Return Ollama from the tray and confirm with the task manager that there is no residual process of ollama.exe. Remaining steps:
- Found Ollama in "Setting Zoom Application Zoom Installed Application" with point off; also Winget uninstall Ollama.
- Delete the model catalogue: C:\Users. Take a quick look at %LOCALAPDA% Ollama, some versions will leave the log and running time files here. The application body will be installed by default at %LOCALAPDA% \Programs\Ollama, and the offloader will be manually checked and cleaned up when it fails.
- Open the "Environmental Variables" window and check for Ollama entries (e.g. OLLMA MODELS, OLLMA HOST) that you have added earlier, and delete them without needing to reload them to the old configuration.
- A new terminal knocks on olama-version, prompting orders not to exist, to be clean.
Linux
The installation of official scripts is carried out sequentially:
# Stop the service and cancel the launch
sudo systemctl stop ollama
sudo systemctl disable ollama
# Remove Service Definition File
sudo rm /etc/systemd/system/ollama.service
sudo systemctl daemon-reload
# Delete binary files (possibly/usr/ local/ bin or/usr/bin)
sudo rm $(which ollama)
# Delete models and Ollama dedicated users, user groups
sudo rm -r /usr/share/ollama
sudo userdel ollama
sudo groupdel ollama
# If you do not install it in official scripts, you run it directly as an ordinary user, Ollama, the model may be ~/.ollama/models
rm -rf ~/.ollama
Docker
If you run through the container, it's much easier:
docker stop ollama
docker rm ollama
docker image rm ollama/ollama
# If you've built a name sheet, delete it
docker volume rm ollama
III. Redeployment
The environment is clean and then loaded. First, a hardware check is made before the model can run.
Read the hardware before loading.
Model size is directly linked to your memory, VRAM. It's not courage. It's torture.
Take a 7B-grade Chinese model on the plain notebook, run it and then go up.
Installation (Windows / Linux)
- Windows: OllamaSetup.exe, under the official net, double-clicks all the way to Install, where there will be an elliptical icon after the pallet. You can also run in PowerShell, irm https://ollama.com/install.ps1 ix.
-Linux: One line of scripts is done, it automatically registers systemmd services:
curl -fsSL https://ollama.com/install.sh | sh
Once installed at the terminal for the implementation of the olama-version, the print-out number indicates that the service is in place.
ollama --version
ollama version is 0.5.4
systemctl status ollama
● ollama.service - Ollama Service
Loaded: loaded (/etc/systemd/system/ollama.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2026-10-31 14:01:29 CST; 31min ago
Main PID: 1551 (ollama)
Tasks: 9
Memory: 4.4G
CGroup: /system.slice/ollama.service
└─1551 /usr/local/bin/ollama serve
Oct 31 14:05:54 dockerRegistry ollama[1551]: llm_load_print_meta: FIM REP token = 151663 '<|repo_name|>'
Oct 31 14:05:54 dockerRegistry ollama[1551]: llm_load_print_meta: FIM SEP token = 151664 '<|file_sep|>'
........
First thing after reloading: crucify the model.
A lot of people skip this step, and in two weeks they'll be full of C discs. Ollama's model path is determined entirely by the environmental variable OMLAMA MODELS, which is read at the moment when the service starts. So don't wait until the download's finished and think about moving.
Create a directory without Chinese and spaces, such as D:\ollama\models, and then:
- Windows: New OLAMA MODELS in "Environmental Variables" to fill in the target directory; then completely exited Ollama and started or even cancelled re-entry to ensure that the back-office process reads the new values.
- Linux: at ~/.zshrc or ~/.bashrc Riga export OLLAMA MODELS=/ollama/models. If you use a systemd service, an export in a shell is useless and changes the Environment entry in the service configuration:
sudo systemctl edit ollama.service
# Add a line under [Service] paragraph:
# Environment="OLLAMA_MODELS=/mnt/data/ollama/models"
# Not necessary
sudo systemctl restart ollama
If you want to make sure it's changed, knock on the olama list, look at the list of models, change the path to the olama list should be empty, it's normal, just pull back; if you can still see the old model, it means the service is still using the old path. Or go directly to the target directory and see if there are two layers of structures that generate blobs, mirrors.
Pull the first model.
Pick a light start, like:
ollama run deepseek-r1:7b
# The quantum machine type is removable
The first implementation will be automatically downloaded and the next directly into the dialogue interface. All I want to do is download and not talk right away, using ollama pull deepseek-r1:7b. You want to quit the conversation, enter/exit.
If you want to verify the interface, you can use a curl:
curl http://localhost:11434/api/generate -d '{
"model": "deepseek-r1:7b",
"prompt": "An explanation of what is retrograde in one sentence,"
"stream": false
}'
"Model": "deepseek-r1:7b", "created at": "2026-10-31T07:32:42.178485z", "response": "<think" Well, now I have to understand what is going back. First of all, I see that the word “retrogression” consists of both “transmitting” and “attribution”. It's literally a step back, isn't it? What's retrogression like in programming?... <think> \n\n is a function or process in a procedure that uses its own way to solve a problem that can be broken down into similar sub-issues. By scaling down the problem gradually until the basic conditions (terminating conditions) are met, it returns the result gradually, thus avoiding double counting and improving the readability of codes. ", "done": true, "done reason": "stop", "context": [151644,..., 1773], "total duration": 157202417280, "load duration": 3168462007, "prompt eval count": 9, "prompt eval duration": 1761,000,000, "eval count": 586, "eval duration":152237
# Note that the section <think" in respone is the thinking process of R1-like reasoning models, which is normal output, and the final answer is after it.
A normal return to JSON means that local services are fully available, followed by various client and editor plugins supporting the Open AI compatibility interface.
IV. Several environmental variables worth knowing in advance
Ollama does not have a separate configuration file, and all key settings follow the environment variables before restarting the service. In addition to OLAMA MODELS, a few are frequently used:
- OMLAMA HOST: Listening address, default only. Wants other LAN devices to be called in at 0.0.0.0:11434; wants to change ports and bring them here, e.g. 0.0.0.0:8080.
- OLLMA ORIGINS: The browser-end cross-domain call is used to untie the source and the test phase can be set up *.
- OLLMA KEP ALIVE: the time when the memory is stored after the model is loaded, by default 5 minutes. If you use it more frequently, like 24h, you can save the waiting times.
- OLLMA MAX LOADED MODELS and OLLMA NUM PARALLEL: The number of models loaded together and the number of requests issued can be properly released when sufficient memory is available.
V. Several common pits
- Changed variables didn't work. Mostly forget to restart the service. Environmental variables are read once at the start of the process, and subsequent changes to system variables do not affect the processes that are already running.
- Download models stuck or timeout. Confirms that the service is running, networked; if it is slow, change the time period, or take proxy acceleration via HTTPS PROXY (note that HTTP PROXY is not set, official FAQ explicitly suggests that it may interrupt the client connection). Ollama doesn't have anything like mirror acceleration. Don't look for non-existent switches.
- Linux has a variable on it but the service still uses the old path. Because the service is not started from your shell, it has to be changed in the systemd Envirronment.
- Deleted the model space. Check if there are two directories of models - the old path and the new path are stored together, which were copied and deleted.
The whole process came down, but there were two things: remember Ollama, when offloading, there were four layers of residue, not just the program; fix the model when reloading, and don't wait until C alerts to move. The environment is clean, and it's a lot easier to talk to the local knowledge base, write Agent, or just offline.
Auto-fetched and translated by AI Atlas. All rights belong to the original author.