TechBuzzPro

Configure Ollama for GPU Privacy, Context Size & Storage

· 5 min read · Windows & PC

In this article
  1. What You'll Need
  2. Step‑by‑Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Yes, you can configure Ollama to run locally on your GPU, keep all data private, control the context window, and decide where each model is stored.

What You'll Need

  • A computer with a compatible NVIDIA or AMD GPU and up‑to‑date drivers.
  • Operating system: Linux, macOS, or Windows (64‑bit).
  • Administrative or sudo rights to install software.
  • Internet connection for the initial model download (once downloaded, no further network traffic is required).
  • Enough disk space for the models you intend to use (each model can be several gigabytes).
  • Basic familiarity with a terminal or command prompt.

Step‑by‑Step

  1. Install Ollama. Open a terminal and run the official installer:
    curl -fsSL https://ollama.com/install.sh | sh
    On Windows, download the .exe from the official site and run the installer. Verify the installation with ollama --version.
  2. Confirm GPU availability. Ollama automatically detects CUDA‑enabled NVIDIA GPUs or AMD GPUs with ROCm. Run:
    ollama list
    If the output shows GPU: enabled, you are ready. If not, update your drivers and ensure the nvidia‑container‑toolkit (for NVIDIA) or the appropriate ROCm packages are installed.
  3. Set privacy‑first environment variables. Create a file called .env in your home directory (or edit your shell profile) and add:
    OLLAMA_NO_TELEMETRY=1
    OLLAMA_HOST=127.0.0.1:11434
    The first line disables anonymous usage reporting. The second forces the server to bind only to the loopback address, preventing external access.
  4. Choose a custom model storage folder. By default Ollama stores models under ~/.ollama/models. To relocate them, set the OLLAMA_MODEL_PATH variable:
    export OLLAMA_MODEL_PATH=/mnt/data/ollama_models
    Create the directory first and ensure the user running Ollama has read/write permissions.
  5. Adjust the context size. The context window determines how many tokens the model can consider at once. Set OLLAMA_MAX_CONTEXT to the desired token count (e.g., 8192):
    export OLLAMA_MAX_CONTEXT=8192
    Higher values increase memory usage; keep it within the limits of your GPU VRAM (rough rule: 1 GB VRAM ≈ 2000 tokens).
  6. Restart the Ollama service. After changing environment variables, restart:
    ollama stop && ollama start
    On Windows use the Services manager or run ollama.exe stop then ollama.exe start.
  7. Pull a model to the new storage location. Example with Llama 3.1:
    ollama pull llama3.1
    The model will be downloaded into the path defined by OLLAMA_MODEL_PATH. Verify with ollama list – the model path should reflect your custom directory.
  8. Run a test query. Use the CLI or an API client:
    ollama run llama3.1 "Explain quantum entanglement in two sentences."
    If the response appears quickly and no external IP addresses are shown in network monitors, your privacy configuration is working.
  9. Persist the environment variables. Add the export lines to your shell profile (~/.bashrc, ~/.zshrc, or Windows System Environment Variables) so they survive reboots.
  10. Optional: Enable GPU memory pre‑allocation. For large context windows, pre‑allocate VRAM to avoid fragmentation:
    export OLLAMA_GPU_ALLOC=1
    Restart Ollama again after setting this flag.

Common Mistakes

  • Setting OLLAMA_MAX_CONTEXT higher than the GPU can handle, which leads to out‑of‑memory crashes.
  • Forgetting to bind the server to 127.0.0.1; leaving the default 0.0.0.0 can expose the API to the local network.
  • Placing OLLAMA_MODEL_PATH on a filesystem that does not support sparse files; this can waste disk space and slow loading.
  • Running the installer as a non‑admin user without sudo; the service will fail to start.
  • Disabling telemetry but not clearing existing logs; old logs may still contain usage data.

Tips

  • Use a dedicated SSD for OLLAMA_MODEL_PATH to reduce load latency.
  • Monitor VRAM with nvidia‑smi (or rocm-smi) while testing different context sizes.
  • Keep a small “baseline” model locally (e.g., tiny‑llama) for quick sanity checks before pulling larger models.
  • If you run multiple Ollama instances, assign each a unique OLLAMA_HOST port to avoid clashes.
  • Regularly prune unused models with ollama prune to reclaim disk space.

Troubleshooting

Problem: Ollama fails to start after setting environment variables.

  1. Run ollama status to view the error log.
  2. Check that the variables are exported in the same shell session where you run ollama start.
  3. Ensure the custom model directory exists and is writable.
  4. If the log mentions CUDA error: unknown error, reinstall or update the NVIDIA driver.

Problem: Out‑of‑memory error when using a large context size.

  1. Reduce OLLAMA_MAX_CONTEXT in increments of 512 tokens.
  2. Verify VRAM usage with nvidia‑smi. If usage is near 90 %, lower the context size.
  3. Consider swapping to a smaller model that requires less VRAM per token.

Problem: Model files are still being downloaded to the default folder.

  1. Confirm that OLLAMA_MODEL_PATH points to an absolute path (no tilde expansion).
  2. Restart the service after changing the variable; a running daemon will ignore later changes.
  3. Run ollama list --verbose to see the actual storage location for each model.

Problem: API is reachable from another device on the LAN.

  1. Double‑check OLLAMA_HOST. It must be exactly 127.0.0.1:11434 (or localhost:11434).
  2. If you use a reverse proxy, ensure it binds only to localhost.
  3. Run netstat -tulnp | grep 11434 (Linux) to verify the listening address.

Frequently Asked Questions

Can I run Ollama on a CPU‑only machine?

Yes, but performance will be much slower and the context size may need to be reduced to stay within RAM limits.

Is any data ever sent to Ollama’s cloud servers?

No. When you bind the service to 127.0.0.1 and disable telemetry, all inference runs stay on your hardware.

How do I know which context size a model supports?

Model documentation usually lists the maximum token window. If unsure, start with 2048 tokens and increase until you hit a memory error.

Do I need to set OLLAMA_MAX_CONTEXT for every model?

The variable is global; it applies to all loaded models. Changing it after a model is loaded requires a restart to take effect.

Can I store models on an external USB drive?

Yes, as long as the drive is formatted with a filesystem that supports large files and you give the Ollama process read/write permissions.

What happens to existing models after I change OLLAMA_MODEL_PATH?

They remain in the original folder. You can move them manually to the new directory and run ollama list --refresh to have Ollama recognize the new location.