# 如何在 Linux 终端中安装 LM Studio CLI

1. 打开一个新终端以运行 LM Studio CLI，或使用 `tmux`
2. 获取 [LM Studio](https://lmstudio.ai/download) 或运行下面命令（约 1GB 下载大小）

{% code overflow="wrap" %}

```bash
wget https://lmstudio.ai/download/latest/linux/x64?format=AppImage -O 'LM_Studio.AppImage'
chmod u+x ./LM_Studio.AppImage
```

{% endcode %}

<figure><img src="/files/eb3e409842b110929f8126ab83e9a093b5df5360" alt=""><figcaption></figcaption></figure>

2. 通过以下方式运行 LM Studio

```bash
./LM_Studio.AppImage
```

你可能会看到如下信息：

<figure><img src="/files/7bed5e065cd8034a25b6df3c0ad081e35f6600fa" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```
[802435:0215/073628.027773:FATAL:sandbox/linux/suid/client/setuid_sandbox_host.cc:166] 找到 SUID 沙箱辅助二进制文件，但未正确配置。与其在没有沙箱的情况下运行，我现在终止。
```

{% endcode %}

如果是这样，请改为执行下面操作：

```bash
./LM_Studio.AppImage --no-sandbox
```

3. 然后你可能会看到下面这些，尤其是在没有桌面的云实例中：

<figure><img src="/files/2d1c99c01bb9c6f4d3957ff8200e96fd0835d011" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```
[807101:0215/073740.801969:ERROR:ui/ozone/platform/x11/ozone_platform_x11.cc:249] 缺少 X 服务器或 $DISPLAY
[807101:0215/073740.802000:ERROR:ui/aura/env.cc:257] 平台初始化失败。正在退出。
段错误（已生成核心转储）
```

{% endcode %}

如果是这样，请在终端内安装一个“假”桌面模拟器：

```bash
sudo apt-get install xvfb
```

4. 然后使用 `xvfb` 并启动 LM Studio：

```bash
xvfb-run --auto-servernum ./LM_Studio.AppImage --no-sandbox
```

<figure><img src="/files/7ccb4b56cfc87f643f8884bf2a05b82706bed803" alt=""><figcaption></figcaption></figure>

5. 然后在另一个终端获取 LM Studio 的 LMS / CLI，或在按 CTRL+B+D 后执行 `tmux`

```bash
~/.lmstudio/bin/lms bootstrap
```

<figure><img src="/files/832ae4fc3871dbb6ee86f29f7c0fb09ae3eb6f81" alt=""><figcaption></figcaption></figure>

6. 打开一个新终端或 `tmux`  然后运行：

```bash
lms
```

<figure><img src="/files/90c828915e5057817c7b4ff896aa93fa355aec05" alt="" width="375"><figcaption></figcaption></figure>

如果你看到 `-bash: lms: command not found` 请运行 `lms` 在新的终端窗口中！

7. 现在下载一个模型，例如 [Qwen3-Coder-Next](/docs/zh/mo-xing/qwen3-coder-next.md) 如下。如果下载卡住，请参见 [Hugging Face Hub，XET 调试](/docs/zh/ji-chu/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

{% code overflow="wrap" %}

```bash
pip install -U huggingface_hub
hf download unsloth/Qwen3-Coder-Next-GGUF \
    --local-dir unsloth/Qwen3-Coder-Next-GGUF \
    --include "*UD-Q4_K_XL*"
```

{% endcode %}

8. 然后我们通过以下命令导入模型：

{% code overflow="wrap" %}

```bash
lms import \
    unsloth/Qwen3-Coder-Next-GGUF/Qwen3-Coder-Next-UD-Q4_K_XL.gguf \
    --symbolic-link --user-repo "unsloth/Qwen3-Coder-Next-GGUF" -y
```

{% endcode %}

你可能会看到 `EEXIST: 文件已存在，符号链接 'unsloth/Qwen3-Coder-Next-GGUF/UD-Q6_K_XL/Qwen3-Coder-Next-UD-Q6_K_XL-00001-of-00003.gguf' -> '~/.lmstudio/models/unsloth/Qwen3-Coder-Next-GGUF/Qwen3-Coder-Next-UD-Q6_K_XL-00001-of-00003.gguf'` 这只是表示你已经在 LM Studio 中加载了该模型。

你也可以通过以下命令检查所有 LM Studio 模型：

```bash
ls ~/.lmstudio/models
```

8. 你也可以通过以下方式获取模型 `lms get` 通过下面：

```bash
lms get https://huggingface.co/unsloth/Qwen3-Coder-Next-GGUF@Q4_K_XL
```

<figure><img src="/files/ad385f93bf8727956ef9ea3b388dce9b9fc8c72f" alt=""><figcaption></figcaption></figure>

然后你会看到：

```
正在完成下载...
下载完成。你可以使用以下命令加载模型： 
lms load qwen3-coder-next
```

<figure><img src="/files/006a82db7be12602a19c4f28cb5658dbbf65a0d3" alt=""><figcaption></figcaption></figure>

然后加载 `lms load qwen3-coder-next`:

<figure><img src="/files/078edfa424a9315d5032a39e13d76e10e8a6f023" alt=""><figcaption></figcaption></figure>

9. 然后启动 LM Studio 的服务器：

```bash
lms server start --port 8001 --bind 127.0.0.1
```

你会看到 `成功！服务器现在在端口 8001 上运行`

9. 然后在一个新终端中，通过兼容 OpenAI 的端点使用该模型：

```python
from openai import OpenAI
import json
openai_client = OpenAI(
    base_url = "http://127.0.0.1:8001/v1",
    api_key = "null",
)
model_name = next(iter(openai_client.models.list())).id
print(model_name)
completion = openai_client.chat.completions.create(
    model = model_name,
    messages = [{"role": "user", "content": "What is 2+2?"},],
)
print(completion.choices[0].message.content)
```

<figure><img src="/files/273f215a09d970341129272407e530125a6962b0" alt=""><figcaption></figcaption></figure>

就这样完成了！


---

# Agent Instructions: 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-chu/inference-and-deployment/lm-studio/how-to-install-lm-studio-cli-in-linux-terminal.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.
