If Ollama is run as a systemd service, environment variables should be set using systemctl:
Edit the systemd service by calling systemctl edit ollama.service. This will open an editor.
For each environment variable, add a line Environment under section [Service]:
[Service] Environment="OLLAMA_HOST=0.0.0.0" Save and exit.
Reload systemd and restart Ollama:
systemctl daemon-reload systemctl restart ollama
curl http://localhost:11434/api/chat -d '{ "model": "phi3", "messages": [ { "role": "system", "content": "以海盗的口吻简单作答。" }, { "role": "user", "content": "天空为什么是蓝色的?" } ], "stream": false }'
systemctl stop ollama.service
set OLLAMA_HOST=0.0.0.0 ollama serve