Ollama stores downloaded model data in a model directory that can become very large. A separate model directory lets a Linux systemd service keep those files on a disk with more space.
The Linux installer runs the server as its own service account. Changing an environment variable in your terminal does not change the environment of that running service.
You need sudo access, rsync, and an installed local model to retain during the move. Ollama will be unavailable while its store is copied; keeping the original directory provides a route back if the new location cannot be used.
Steps to set the Ollama model directory:
- Inspect the Ollama service account and environment.
$ systemctl show ollama -p User -p Group -p Environment Environment=PATH=/bin:/sbin:/usr/bin:/usr/sbin:. User=ollama Group=ollama
The standard Linux installation stores models in /usr/share/ollama/.ollama/models. An existing OLLAMA_MODELS value identifies a different source directory; the copy source must match it. The account and group shown here own the destination.
- Check the available space on the destination filesystem.
$ df -h /srv
The destination needs room for the entire model store while the original remains intact. If another disk will provide the storage, it must already be mounted at the chosen location and available when Ollama starts. /srv/ollama-models must be an unused directory.
- Stop Ollama before copying its model store.
Stopping the service interrupts model requests. The original store must remain intact until inference works from the new location and a separate backup is available. Copying files on the same disk does not protect against disk failure.
$ sudo systemctl stop ollama
- Create the destination directory for the Ollama service account.
$ sudo install -d -o ollama -g ollama -m 0755 /srv/ollama-models
- Copy the complete model store with Ollama ownership.
$ sudo rsync -a --chown=ollama:ollama /usr/share/ollama/.ollama/models/ /srv/ollama-models/
The trailing slash copies the store's contents, including manifests and blobs. -a preserves its structure, and –chown gives the service account ownership of the copied files. The original files remain in place.
- Create the systemd drop-in directory for Ollama.
$ sudo install -d -m 0755 /etc/systemd/system/ollama.service.d
- Save the model-directory setting in a dedicated service drop-in.
This file must be new or contain only the model-directory setting being replaced. An existing OLLAMA_MODELS definition belongs in its original drop-in instead of a competing file. The setting applies to the server, so exporting it in the client shell is insufficient.
$ sudo tee /etc/systemd/system/ollama.service.d/models.conf >/dev/null <<'EOF' [Service] Environment="OLLAMA_MODELS=/srv/ollama-models" EOF
- Reload systemd's service definitions.
$ sudo systemctl daemon-reload
- Restart Ollama with the new directory setting.
$ sudo systemctl restart ollama
If startup fails, sudo journalctl -u ollama -n 30 –no-pager shows service errors. Reverting only the OLLAMA_MODELS edit, reloading systemd, and restarting Ollama returns the service to the retained original store. Other service overrides must remain intact.
- Confirm that systemd includes the new model directory.
$ systemctl show ollama -p Environment Environment=PATH=/bin:/sbin:/usr/bin:/usr/sbin:. OLLAMA_MODELS=/srv/ollama-models
- Wait for the restarted API to answer.
$ curl -fsS --retry 5 --retry-connrefused --retry-delay 1 http://127.0.0.1:11434/api/version {"version":"0.40.12"}
The retry options allow a short delay between the service starting and its API accepting connections. A transient connection refusal can precede the JSON response. The returned version can differ.
- List the models retained in the new store.
$ ollama list NAME ID SIZE MODIFIED qwen2.5:0.5b a8b0c5157701 397 MB About an hour agoThe installed model used here is qwen2.5:0.5b. A different installed local model can supply the copy and inference test.
Related: How to list Ollama models - Create a local model name to test writes to the new store.
$ ollama cp qwen2.5:0.5b example/directory-check copied 'qwen2.5:0.5b' to 'example/directory-check'
This local copy shares the existing model blobs instead of downloading another set of weights.
Related: How to copy an Ollama model - Locate the new model reference beneath the destination directory.
$ sudo ls /srv/ollama-models/manifests-v2/ollama.com/example/directory-check/ latest
Current releases use manifests-v2 for these references. The new name appearing beneath /srv/ollama-models shows where the server wrote it; a model list alone cannot establish that path.
- Run inference through the model name created in the new directory.
$ ollama run example/directory-check 'What is 17 plus 25? Answer in one short sentence.' 17 plus 25 equals 42.
A generated answer confirms that the relocated store remains usable. Answer wording can vary.