> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/zh/ji-cheng/connections/ollama.md).

# 如何将 Ollama 连接到 Unsloth

Ollama 让你可以在自己的硬件上运行本地 LLM，并且 [Unsloth](https://github.com/unslothai/unsloth) 让你可以轻松地将这些模型直接连接到一个开源的 UI 聊天界面并运行它们。在本指南中，你将学习如何安装 Ollama、运行原生 Ollama 模型或来自 Hugging Face 的 GGUF 模型、将 Ollama 连接到 Unsloth，并开始与本地 AI 模型聊天。

无论你想使用像 [Qwen](/docs/zh/mo-xing/qwen3.6.md)这样的模型，导入一个 GGUF 文件，还是通过兼容 OpenAI 的端点暴露你的本地 Ollama 服务器，这篇教程都涵盖了从安装到首次聊天的完整设置流程。

### 设置

{% stepper %}
{% step %}

#### 安装或准备 Ollama

{% tabs %}
{% tab title="macOS" %}
使用安装脚本安装 Ollama：

```bash
curl -fsSL https://ollama.com/install.sh | sh
```

你也可以从以下位置手动下载 Ollama： [ollama.com/download](https://ollama.com/download).
{% endtab %}

{% tab title="Windows" %}
通过 PowerShell 安装 Ollama：

```powershell
irm https://ollama.com/install.ps1 | iex
```

你也可以从以下位置手动下载 Ollama： [ollama.com/download](https://ollama.com/download/OllamaSetup.exe).
{% endtab %}

{% tab title="Linux" %}
使用安装脚本安装 Ollama：

```bash
curl -fsSL https://ollama.com/install.sh | sh
```

你也可以从以下位置手动下载 Ollama： [ollama.com/download](https://docs.ollama.com/linux#manual-install).
{% endtab %}

{% tab title="Docker" %}
官方的 Ollama Docker 镜像是 `ollama/ollama` ，位于 Docker Hub。

```bash
docker run -d \
  -v ollama:/root/.ollama \
  -p 11434:11434 \
  --name ollama \
  ollama/ollama
```

{% endtab %}
{% endtabs %}

Ollama 通常运行在：

```
http://localhost:11434
```

{% endstep %}

{% step %}

#### 运行模型

你可以通过两种常见方式选择模型：

* 在以下位置搜索原生 Ollama 模型： [ollama.com/search](https://ollama.com/search)，然后复制模型名称。
* 使用 Hugging Face 上的 GGUF 模型，然后从以下位置复制 Ollama 命令： **使用此模型**.

对于 Ollama 模型，先拉取再运行：

```bash
ollama pull qwen3.6:35b-a3b
ollama run qwen3.6:35b-a3b
```

如果 Ollama 应用或服务尚未运行，请先启动它：

```bash
ollama serve
```

#### 从 Hugging Face 选择一个 GGUF

如果你使用的是 Hugging Face 上的 GGUF 模型，获取命令最简单的方法是从模型页面复制。

打开你想使用的模型，点击 **使用此模型**，然后在 **Ollama** 本地应用列表中进行选择。从下拉菜单中选择你想要的量化方式，然后复制生成的命令。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FRSR0qWpzSRJgeSIghoWO%2Fexport-1779051800964-small.gif?alt=media&amp;token=8e557e60-2e11-420e-a7f4-dd80533bd86b" alt=""><figcaption></figcaption></figure>

例如，使用 Ollama：

```bash
ollama run hf.co/unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_XL
```

这有助于避免仓库名称或量化标签出错。
{% endstep %}

{% step %}

#### 将 Ollama 连接到 Unsloth

打开 **设置 → 连接**，然后点击 **添加连接**.

选择 **Ollama**，然后输入你的连接信息：

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FIKDXfJZmRQVA742rXAHA%2Fimage.png?alt=media&amp;token=6c7105a0-9f6e-435b-bafb-1502e22331bd" alt="" width="563"><figcaption></figcaption></figure>

使用 Unsloth 表单中显示的 Ollama URL。在大多数本地设置中，这个地址是：

```
http://localhost:11434
```

如果 Unsloth 要求填写兼容 OpenAI 的基础 URL，请使用：

```
http://localhost:11434/v1
```

Ollama 通常不需要 API 密钥。除非你使用的代理需要它，否则请将 API 密钥字段留空。

点击 **加载模型** 以获取正在 Ollama 中运行的模型，或者手动输入 **模型 ID** ，例如 `qwen3.6`.
{% endstep %}

{% step %}

#### 准备聊天

在你点击 **添加连接**之后，你启用的模型现在会显示在 **已连接** 在 **选择模型** 下拉菜单中。
{% endstep %}
{% endstepper %}

#### 常见的 Ollama 命令

在设置你想暴露给 Unsloth 的模型时使用这些命令：

| 命令                            | 作用            |
| ----------------------------- | ------------- |
| `ollama run qwen3.6:35b-a3b`  | 运行模型并打开交互式聊天  |
| `ollama pull qwen3.6:35b-a3b` | 下载模型而不启动聊天    |
| `ollama ls`                   | 列出已下载的模型      |
| `ollama ps`                   | 列出当前正在运行的模型   |
| `ollama stop qwen3.6:35b-a3b` | 停止正在运行的模型     |
| `ollama rm qwen3.6:35b-a3b`   | 移除已下载的模型      |
| `ollama serve`                | 启动 Ollama 服务器 |

如果你正在将本地 GGUF 导入到 Ollama 中，请创建一个 `Modelfile`，然后运行：

```bash
ollama create -f Modelfile
```

如果检测不到 Ollama，请确保 Ollama 应用或服务正在运行。然后在 Unsloth 中再次点击 **加载模型** 。

完整命令列表请参见 [Ollama CLI 参考](https://docs.ollama.com/cli).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/zh/ji-cheng/connections/ollama.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
