DEV Community

drake
drake

Posted on

linux修改Ollama默认模型保存路径

  • 0、给目标目录添加读写权限

比如:/data/ollama/models 该文件普通用户可能没有权限修改;需给当前用户赋予权限:

sudo chown -R ec2-user:ec2-user /data/ollama/models
Enter fullscreen mode Exit fullscreen mode
  • 1、修改启动配置文件/etc/systemd/system/ollama.service,将目标目录添加到此
sudo vim /etc/systemd/system/ollama.service
Enter fullscreen mode Exit fullscreen mode

新增这一行Environment="OLLAMA_MODELS=/data/ollama/models"

其中/data/ollama/models该目录是你要配置的目标模型存放目录

Image description

修改后:

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

[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=/home/ec2-user/.local/bin:/home/ec2-user/miniconda3/condabin:/usr/local/jdk11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
Environment="OLLAMA_MODELS=/data/ollama/models"
[Install]
WantedBy=default.target
Enter fullscreen mode Exit fullscreen mode
  • 2、加载配置
sudo systemctl daemon-reload
Enter fullscreen mode Exit fullscreen mode
  • 3、重启Ollama服务
 sudo systemctl restart ollama
Enter fullscreen mode Exit fullscreen mode
  • 4、测试修改是否成功 拉一个模型看看是否是存放到了修改后的目录
ollama pull phi4
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay