HOW-TO · SET

How to create a custom Modelfile for Ollama

intermediate15 minBy Fredoline Eruo
Target environment
Ubuntu 24.04 · Ollama 0.4.xWindows 11 · Ollama 0.4.xmacOS 15 · Ollama 0.4.x
PREREQUISITES

Ollama installed, a base model already pulled (e.g., `ollama list` shows a model), and a text editor available.

What this does

A Modelfile is a configuration text file that defines model parameters, system prompts, template overrides, and runtime behavior. This guide creates a custom Modelfile, imports it into Ollama, and runs the customized model.

Steps

  1. Create a new directory and Modelfile. The Modelfile uses a declarative syntax to override default behavior.

    mkdir -p ~/ollama-models/myassistant
    cd ~/ollama-models/myassistant
    nano Modelfile
    

    Expected output: An empty text editor buffer opens for the new file.

  2. Write the Modelfile content. This example sets a system prompt, adjusts temperature, and specifies the base model.

    cat << 'EOF' > Modelfile
    FROM llama3.2:1b
    PARAMETER temperature 0.7
    PARAMETER top_p 0.9
    SYSTEM """
    You are a helpful assistant. Answer concisely.
    """
    EOF
    

    Expected output: File Modelfile created with the content above. Verify with cat Modelfile.

  3. Create the custom model using ollama create. This imports the Modelfile and builds a named model variant.

    ollama create myassistant -f Modelfile
    

    Expected output: success message confirming the model was created and registered.

  4. Run the custom model to verify behavior. The system prompt and parameters defined in the Modelfile govern the inference session.

    ollama run myassistant
    

    Expected output: Interactive prompt appears. Responses reflect the defined system prompt and temperature setting.

Verification

ollama list | grep myassistant
# Expected: myassistant   <id>   <size>   <date>

Common failures

  • ollama create fails with parse error — Modelfile syntax error. Check for missing colons, incorrect keywords, or unquoted multi-line strings.
  • Model runs with wrong parameters — Cached default parameters may persist. Delete and recreate with ollama rm myassistant && ollama create myassistant -f Modelfile.
  • FROM model not found — The base model has not been pulled. Run ollama pull llama3.2:1b first.
  • Parameter value out of range — Some parameters have specific bounds (e.g., temperature must be between 0 and 2). Consult Ollama documentation for valid ranges.
  • System prompt not applied — Template overrides may conflict with system prompt. Simplify the Modelfile to isolate the issue.

Related guides

RELATED GUIDES