在 Linux 上安装和管理 Ollama

安装(​)

安装 Ollama,运行以下命令:

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

手动安装(​)

如果从旧版升级,原文要求先使用 sudo rm -rf /usr/lib/ollama 移除旧库。

下载并解压软件包:

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

启动 Ollama:

ollama serve

在另一个终端确认 Ollama 正在运行:

ollama -v

AMD GPU 安装(​)

如果使用 AMD GPU,还需下载并解压额外的 ROCm 软件包:

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

ARM64 安装(​)

下载并解压 ARM64 专用软件包:

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

添加为开机启动服务(推荐)(​)

创建 Ollama 用户与用户组:

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

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

[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

然后启用服务:

sudo systemctl daemon-reload
sudo systemctl enable ollama

安装 CUDA 驱动(可选)(​)

下载并安装 CUDA。(Download and install)

运行以下命令检查驱动是否安装,正常情况下会输出 GPU 详情:

nvidia-smi

安装 AMD ROCm 驱动(可选)(​)

下载并安装 ROCm v7。(Download and Install)

启动 Ollama(​)

启动 Ollama 并检查运行状态:

sudo systemctl start ollama
sudo systemctl status ollama

虽然 AMD 已将 amdgpu 驱动贡献到官方 Linux 内核,但内核中的版本较旧,可能不支持全部 ROCm 功能。原文推荐从 AMD 官方 Linux 驱动下载页面安装最新驱动,以获得更好的 Radeon GPU 支持。(https://www.amd.com/en/support/download/linux-drivers.html)

自定义配置(​)

自定义安装时,可以运行下列命令编辑 systemd 服务文件或环境变量:

sudo systemctl edit ollama

也可以手动创建 /etc/systemd/system/ollama.service.d/override.conf 覆盖文件:

[Service]
Environment="OLLAMA_DEBUG=1"

更新(​)

重新运行安装脚本更新 Ollama:

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

也可以重新下载软件包:

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

安装指定版本(​)

运行安装脚本时,通过 OLLAMA_VERSION 环境变量安装指定版本,包括预发布版。版本号可在 releases 页面查询。(releases page)

例如:

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

查看日志(​)

查看作为开机服务运行的 Ollama 日志:

journalctl -e -u ollama

卸载(​)

移除 Ollama 服务:

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

从 lib 目录移除 Ollama 库,可能位于 /usr/local/lib、/usr/lib 或 /lib:

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

从 bin 目录移除 Ollama 二进制,可能位于 /usr/local/bin、/usr/bin 或 /bin:

sudo rm $(which ollama)

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

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

来源:在 Linux 上安装和管理 Ollama。Ollama 文档贡献者。下载与删除命令为原文内容,未执行。 本文依据本批次转载授权译为中文,原始代码与示例输出保留。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容