Skip to content

安装

要安装 Ollama,请运行以下命令:

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

手动安装

注意

如果您是从之前的版本升级,应先使用 sudo rm -rf /usr/lib/ollama 删除旧的库文件。

下载并解压软件包:

shell
curl -fsSL https://ollama.com/download/ollama-linux-amd64.tar.zst \
    | sudo tar x -C /usr

启动 Ollama:

shell
ollama serve

在另一个终端中,验证 Ollama 是否正在运行:

shell
ollama -v

AMD GPU 安装

如果您拥有 AMD GPU,还请下载并解压额外的 ROCm 软件包:

shell
curl -fsSL https://ollama.com/download/ollama-linux-amd64-rocm.tar.zst \
    | sudo tar x -C /usr

ARM64 安装

下载并解压适用于 ARM64 的特定软件包:

shell
curl -fsSL https://ollama.com/download/ollama-linux-arm64.tar.zst \
    | sudo tar x -C /usr

将 Ollama 添加为启动服务(推荐)

为 Ollama 创建用户和组:

shell
sudo useradd -r -s /bin/false -U -m -d /usr/share/ollama ollama
sudo usermod -a -G ollama $(whoami)

/etc/systemd/system/ollama.service 中创建服务文件:

ini
[Unit]
Description=Ollama Service
After=network-online.target

[Service]
ExecStart=/usr/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=$PATH"

[Install]
WantedBy=multi-user.target

然后启动服务:

shell
sudo systemctl daemon-reload
sudo systemctl enable ollama

安装 CUDA 驱动(可选)

下载并安装 CUDA。

通过运行以下命令验证驱动是否已安装,该命令应打印出您的 GPU 详情:

shell
nvidia-smi

安装 AMD ROCm 驱动(可选)

下载并安装 ROCm v7。

启动 Ollama

启动 Ollama 并验证其运行状态:

shell
sudo systemctl start ollama
sudo systemctl status ollama

注意

虽然 AMD 已将 amdgpu 驱动提交到官方 Linux 内核源码中,但版本较旧且可能不支持所有 ROCm 功能。我们建议您从 https://www.amd.com/en/support/linux-drivers 安装最新的驱动程序,以获得对您的 Radeon GPU 的最佳支持。

自定义

要自定义 Ollama 的安装,您可以通过运行以下命令编辑 systemd 服务文件或环境变量:

shell
sudo systemctl edit ollama

或者,手动在 /etc/systemd/system/ollama.service.d/override.conf 中创建覆盖文件:

ini
[Service]
Environment="OLLAMA_DEBUG=1"

更新

通过再次运行安装脚本来更新 Ollama:

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

或者通过重新下载 Ollama:

shell
curl -fsSL https://ollama.com/download/ollama-linux-amd64.tar.zst \
    | sudo tar x -C /usr

安装特定版本

使用安装脚本中的 OLLAMA_VERSION 环境变量来安装特定版本的 Ollama,包括预发布版本。您可以在 releases 页面 中找到版本号。

例如:

shell
curl -fsSL https://ollama.com/install.sh | OLLAMA_VERSION=0.5.7 sh

查看日志

要查看作为启动服务运行的 Ollama 的日志,请运行:

shell
journalctl -e -u ollama

卸载

移除 ollama 服务:

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

从您的 lib 目录(例如 /usr/local/lib/usr/lib/lib)中移除 ollama 库文件:

shell
sudo rm -r $(which ollama | tr 'bin' 'lib')

从您的 bin 目录(例如 /usr/local/bin/usr/bin/bin)中移除 ollama 二进制文件:

shell
sudo rm $(which ollama)

移除下载的模型以及 Ollama 服务用户和组:

shell
sudo userdel ollama
sudo groupdel ollama
sudo rm -r /usr/share/ollama