如何在 Ubuntu 24.04 中使用 Ollama LLM 本地安装 DeepSeek
How to Install DeepSeek Locally with Ollama LLM in Ubuntu 24.04
1、安装 Python 和 Git
在安装任何东西之前,最好先更新系统以确保所有现有软件包都是最新的。
sudo apt update && sudo apt upgrade -y
Ubuntu 可能预装了 Python,但务必确保安装正确的版本(Python 3.8 或更高版本)。
sudo apt install python3 python3 --version pip 是 Python 的软件包管理器,需要安装 DeepSeek 和 Ollama 的依赖项。 sudo apt install python3-pip pip3 --version sudo apt install git git --version
2、为 DeepSeek 安装 Ollama
现在 Python 和 Git 已安装完毕,可以安装 Ollama 来管理 DeepSeek。
curl -fsSL https://ollama.com/install.sh | sh ollama --version
接下来,启动并启用 Ollama,使其在系统启动时自动启动。
sudo systemctl start ollama
sudo systemctl enable ollama
现在 Ollama 已安装完毕,我们可以继续安装 DeepSeek。
3、下载并运行 DeepSeek 模型
现在 Ollama 已安装完毕,您可以下载 DeepSeek 模型。
ollama run deepseek-r1:7b
下载完成后,您可以通过运行以下命令来验证模型是否可用:
ollama list
4、在 Web UI 中运行 DeepSeek
虽然 Ollama 允许您通过命令行与 DeepSeek 交互,但您可能更喜欢更用户友好的 Web 界面。为此,我们将使用 Ollama Web UI,这是一个用于与 Ollama 模型交互的简单 Web 界面。
首先,创建一个虚拟环境,将您的 Python 依赖项与系统范围的 Python 安装隔离开来。
sudo apt install python3-venv python3 -m venv ~/open-webui-venv source ~/open-webui-venv/bin/activate PIP设置阿里云镜像源,以加速包的安装。 pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ Writing to /root/.config/pip/pip.conf 现在您的虚拟环境已激活,您可以使用 pip 安装 Open WebUI。 pip install open-webui 安装后,使用以下命令启动服务器。 open-webui serve 打开您的 Web 浏览器并导航到 http://localhost:8080 – 您应该会看到 Ollama Web UI 界面。
www.zhangfangzhou.cn
5、在系统启动时启用 Open-WebUI
要使 Open-WebUI 在启动时启动,您可以创建一个 systemd 服务,在系统启动时自动启动 Open-WebUI 服务器。
vim nano /etc/systemd/system/open-webui.service [Unit] Description=Open WebUI Service After=network.target [Service] User=your_username WorkingDirectory=/home/your_username/open-webui-venv ExecStart=/home/your_username/open-webui-venv/bin/open-webui serve Restart=always Environment="PATH=/home/your_username/open-webui-venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" [Install] WantedBy=multi-user.target Replace your_username with your actual username.
现在重新加载 systemd 守护程序以识别新服务:
sudo systemctl daemon-reload
最后,启用并启动服务以在启动时启动:
sudo systemctl enable open-webui.service
sudo systemctl start open-webui.service
检查服务的状态以确保其正常运行:
sudo systemctl status open-webui.service
6、更新 open-webui 包,可以使用以下命令:
pip install --upgrade open-webui
7、open-webui无法链接ollama 报错ERROR:apps.ollama.main:Connection error: Cannot connect
修改启动配置
默认ollama绑定在127.0.0.1的11434端口,修改/etc/systemd/system/ollama.service,在[Service]下添加如下内容,使ollama绑定到0.0.0.0的11434端口
Environment="OLLAMA_HOST=0.0.0.0"
sudo systemctl daemon-reload
sudo systemctl restart ollama
www.zhangfangzhou.cn
8、部署完成后,发下每次登录都会先出现白屏,需要取消api.openai.com
INFO [open_webui.routers.openai] get_all_models()
ERROR [open_webui.routers.openai] Connection error: Cannot connect to host api.openai.com:443 ssl:default [None]
INFO [open_webui.routers.ollama] get_all_models()
登录 http://10.53.122.243:8080/admin/settings
取消 管理OpenAI API连接
9、错误提示
/home/$user/AnythingLLMDesktop/start
su@su:~$ /home/su/AnythingLLMDesktop/start
[10216:0227/083834.604266:FATAL:setuid_sandbox_host.cc(158)] The SUID sandbox helper binary was found, but is not configured correctly. Rather than run without sandboxing I'm aborting now. You need to make sure that /home/su/AnythingLLMDesktop/anythingllm-desktop/chrome-sandbox is owned by root and has mode 4755.
Trace/breakpoint trap (core dumped) www.zhangfangzhou.cn
解决办法
sudo chmod 4755 /home/su/AnythingLLMDesktop/anythingllm-desktop/chrome-sandbox
www.zhangfangzhou.cn