Thanks the solution provided in https://www.zhihu.com/en/answer/3561622168 and https://aleksandarhaber.com/how-to-find-where-ollama-stores-downloaded-llm-models-on-linux-systems/.
Show the model save location
First make sure that plocate search tool is installed. We can install this tools as follows.
sudo apt install plocate
sudo updatedb
Then, search of ollama
plocate ollama | grep -w models
The output looks like this:
/usr/share/ollama/.ollama/models
/usr/share/ollama/.ollama/models/blobs
/usr/share/ollama/.ollama/models/manifests
Change the path for saving the model
- Create the path for saving the model
The path
/nvmedata/ollama/modelscan be changed to any other path you like.sudo mkdir /nvmedata/ollama/models - Change the owner and group of the target path to root
sudo chown -R root:root /nvmedata/ollama/models - Change its file permissions to 755
sudo chmod -R 755 /nvmedata/ollama/models - Add the corresponding environment variables [Service] below Environment, including
OLLAMA_HOSTandOLLAMA_MODELSbysudo nano /etc/systemd/system/ollama.serviceEnvironment="OLLAMA_MODELS=/nvmedata/ollama/models" Environment="OLLAMA_HOST=0.0.0.0:11434"
By setting this up, all models pulled by the ollama pull command in the future will be saved in /nvmedata/ollama/models, while models run by the ollama run command can be accessed at 0.0.0.0:11434. The modified ollama.service content is as follows:
[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/..."
Environment="OLLAMA_MODELS=/nvmedata/ollama/models"
Environment="OLLAMA_HOST=0.0.0.0:11434"
[Install]
WantedBy=default.target
- Finally, use the following two commands with sudo to make the settings take effect and restart ollama:
sudo systemctl daemon-reload sudo systemctl restart ollama
PREVIOUSUpdate cuda and cudnn for pop os