> 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="/files/3af3b19749b2e4b60e520f97a658389147ab5794" 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="/files/8d38b7fc5bc42905c03e80ee2740c93ee1b5de0d" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
