Ollama: Model Management

Models are the core assets of local AI — choosing the right Model and managing versions well is as critical as a chef selecting ingredients.

💡 Tip: The Modelfile's FROM instruction supports an inheritance mechanism — you can create custom Models based on existing ones. The new Model shares the base Model's weight files and only layers on System Prompt, parameter, and template configurations, consuming no additional disk space. This makes creating multiple role-specific Models (e.g., refund specialist, logistics expert) virtually costless.

📋 Prerequisites: You need to master the following first

1. What You Will Learn


2. A Real Story from a SaaS Founder

(1) The Pain Point: Choosing the Wrong Model Wastes Resources

Alice founded the GlobalShop e-commerce platform and initially pulled the llama3.1:70b Model for her SupportBot customer service system. The 40GB+ Model filled up the server disk and Inference was slow. She later discovered that a 3B-parameter small Model could handle 80% of common questions; the 70B was only needed for complex tickets.

(2) The Solution: Tiered Deployment Based on Need

By understanding Model tags and parameter levels, Alice established a tiered strategy: 3B handles common questions (fast), 8B handles moderate complexity, and 70B only handles high-difficulty tickets.

BASH
# Pull different sizes for different tasks
ollama pull llama3.2:3b    # Fast, for simple queries
ollama pull llama3.1:8b    # Balanced
ollama pull llama3.1:70b   # Powerful, for complex cases

3. Model Management Commands Complete Guide

(1) Command Reference Table

Command Purpose Example
ollama list List local Models ollama list
ollama pull Pull a Model ollama pull llama3.2
ollama rm Delete a Model ollama rm llama3.2:3b
ollama show View Model details ollama show llama3.2
ollama cp Copy a Model tag ollama cp llama3.2 my-llama
ollama run Run a Model ollama run llama3.2

(2) Model Lifecycle

100%
stateDiagram-v2
    [*] --> Pulled: ollama pull
    Pulled --> Running: ollama run
    Running --> Idle: Keep alive timeout
    Idle --> Running: ollama run (reload)
    Idle --> Unloaded: Memory pressure
    Unloaded --> Running: ollama run (reload)
    Pulled --> Copied: ollama cp
    Copied --> Running: ollama run copy
    Pulled --> Deleted: ollama rm
    Deleted --> [*]

▶ Example 1: Basic Management Operations

BASH
# List all local models
ollama list
# NAME              ID              SIZE      MODIFIED
# llama3.2:latest   a80c4feeb02f    2.0 GB    2 hours ago
# mistral:latest    2b3e5c5f1e3d    4.1 GB    1 day ago

# Pull a specific model
ollama pull llama3.2
# pulling manifest... done
# success

# Show model details
ollama show llama3.2
# Model
#   architecture: llama
#   parameters:    3.2B
#   quantization:  Q4_K_M
#   context length: 131072

# Delete a model to free space
ollama rm llama3.2:3b
# deleted 'llama3.2:3b'
⚠️ Note: ollama rm is irreversible — Model files are permanently removed from disk. If the Model was pulled from the Ollama Library, you can re-download it with ollama pull, but large Model downloads can take a long time (10-30 minutes for 40GB+). Confirm you no longer need the Model before deleting.

Output:

TEXT
NAME                    ID              SIZE    
llama3.2:latest        a80...          2.0 GB  
mistral:latest         61...           4.1 GB

4. Model Tag System

⚠️ Warning: Pulling a 70B-parameter Model requires 40GB+ VRAM (multi-GPU) and 40GB+ disk space. If your hardware doesn't support it, don't blindly ollama pull llama3.1:70b — after downloading 40GB, you won't be able to run it, and it wastes disk space. Confirm your hardware before pulling.

(1) Tag Naming Rules

Tags specify a particular variant of a Model, in the format <name>:<tag>:

Tag Format Meaning Example
name:latest Default latest version llama3.2:latest
name / parameter count / quantization Parameter level llama3.1:8b / llama3.1:70b
name:q4_K_M Quantization level llama3.2:q4_K_M
name:v1.0 Version number llama3.2:v1.0
name (no tag) Equivalent to latest llama3.2

(2) Quantization Tag Comparison

Tag Quantization Level 8B Model Size Quality Assessment Use Case
q2_K 2-bit ~3 GB Noticeable degradation Extremely constrained hardware
q3_K_M 3-bit ~3.8 GB Mild degradation 4GB VRAM
q4_K_M 4-bit ~5 GB Near original 8GB VRAM (recommended)
q5_K_M 5-bit ~5.7 GB Nearly lossless 8GB VRAM
q8_0 8-bit ~8 GB Lossless 12GB+ VRAM
f16 16-bit ~16 GB Full precision 24GB+ VRAM
💡 Tip: When no Quantization tag is specified, Ollama auto-selects the optimal Quantization (usually Q4_K_M). Specify explicitly for precise control.

▶ Example 2: Pulling Different Quantization Variants

BASH
# Default: auto-select quantization (usually Q4_K_M)
ollama pull llama3.2

# Explicit: pull specific quantization
ollama pull llama3.2:q4_K_M     # Balanced (recommended)
ollama pull llama3.2:q8_0       # Higher quality, larger file

# Pull by parameter size
ollama pull llama3.1:8b         # 8 billion parameters
ollama pull llama3.1:70b        # 70 billion parameters (needs 40GB+ VRAM)

# List all available variants
ollama show llama3.2 --modelfile

Output:

TEXT
pulling manifest... 
success

5. Ollama Library and Model Selection

Model Parameters Size Strengths License
llama3.2 3B / 1B 2 GB General conversation, lightweight Deployment Llama Community
llama3.1 8B / 70B 5 / 40 GB General-purpose, multilingual Llama Community
mistral 7B 4.1 GB Instruction following, code Apache 2.0
qwen2.5 7B / 72B 4.7 / 42 GB Chinese-optimized, code Apache 2.0
codellama 7B / 34B 3.8 / 19 GB Code generation and completion Llama Community
phi-3-mini 3.8B 2.3 GB Reasoning, lightweight MIT
nomic-embed-text 274M 274 MB Text Embedding (for RAG) Apache 2.0

(2) Scenario-Based Model Selection Decision

100%
graph TD
    A[What do you need?] --> B{Primary use case?}
    B -->|Chat / General| C{Hardware?}
    B -->|Code| D[codellama / qwen2.5-coder]
    B -->|Chinese| E[qwen2.5]
    B -->|Embedding / RAG| F[nomic-embed-text / mxbai-embed-large]
    C -->|8GB RAM| G[llama3.2:3b / phi-3-mini]
    C -->|16GB+ RAM or 8GB VRAM| H[llama3.1:8b / mistral]
    C -->|40GB+ VRAM| I[llama3.1:70b]

▶ Example 3: Scenario-Based Model Selection

BASH
# Alice's SupportBot: multi-language customer service
ollama pull qwen2.5:7b          # Best Chinese + multilingual
ollama pull nomic-embed-text    # For RAG knowledge base

# Alice's GlobalShop: SQL generation
ollama pull codellama:7b        # Code-focused model

# Alice's SaaS: metrics analysis
ollama pull llama3.1:8b         # General reasoning

# Check total disk usage
ollama list | awk '{sum+=$3} END {print "Total: " sum/1024/1024/1024 " GB"}'

Output:

TEXT
NAME                    ID              SIZE    
llama3.2:latest        a80...          2.0 GB  
mistral:latest         61...           4.1 GB

6. Disk Space Management and Offline Migration

ℹ️ Info: Ollama uses content-addressable storage (CAS). Model files are stored as blobs in ~/.ollama/models/blobs/. Multiple Models sharing the same base layer blobs means ollama list total sizes may exceed actual disk usage.

(1) Storage Locations and Cleanup Strategy

Platform Default Path Notes
macOS ~/.ollama/models Follows user directory
Linux /usr/share/ollama/.ollama/models systemd service user
Windows C:\Users\<user>\.ollama\models User directory

(2) Offline Environment Model Migration Steps

Step Action Command
1 Pull Model on online machine ollama pull llama3.2
2 Locate Model files ls ~/.ollama/models/blobs/
3 Package blobs directory tar czf ollama-models.tar.gz blobs/
4 Transfer to offline machine scp ollama-models.tar.gz user@offline:~
5 Extract to target path tar xzf ollama-models.tar.gz -C /usr/share/ollama/.ollama/models/
6 Verify availability ollama list

▶ Example 4: Disk Space Management

BASH
# Check disk usage per model
ollama list

# Remove unused models to free space
ollama rm llama3.1:70b    # Free ~40GB
ollama rm mistral:latest  # Free ~4GB

# Change model storage path (if disk full)
export OLLAMA_MODELS=/data/ollama/models
ollama serve

# Verify new path
ls $OLLAMA_MODELS/blobs/

Output:

TEXT
NAME                    ID              SIZE    
llama3.2:latest        a80...          2.0 GB  
mistral:latest         61...           4.1 GB

▶ Example 5: Import Custom Model from GGUF File

BASH
# Download a GGUF file from HuggingFace
wget https://huggingface.co/.../model-q4_K_M.gguf

# Create a Modelfile pointing to the GGUF
cat > Modelfile <<EOF
FROM ./model-q4_K_M.gguf
EOF

# Build and register with Ollama
ollama create my-custom-model -f Modelfile

# Run it like any other model
ollama run my-custom-model "Hello"

Output:

TEXT
I'm a helpful AI assistant running locally on your machine...

7. Comprehensive Example: Alice's Model Management Script

BASH
#!/bin/bash
# ============================================
# Comprehensive: Model management dashboard
# Pull, inspect, clean, and report models
# ============================================

MODEL_STORE="$HOME/.ollama/models"

# Function: Show model inventory report
show_inventory() {
    echo "=== Ollama Model Inventory ==="
    echo ""
    ollama list | while read -r name id size modified; do
        if [ "$name" != "NAME" ]; then
            echo "Model: $name"
            echo "  ID:       $id"
            echo "  Size:     $size"
            echo "  Modified: $modified"
            echo ""
        fi
    done
    echo "Total disk: $(du -sh $MODEL_STORE 2>/dev/null | cut -f1)"
}

# Function: Pull models for SupportBot stack
pull_support_stack() {
    echo "=== Pulling SupportBot Model Stack ==="
    local models=(
        "qwen2.5:7b"           # Main chat model
        "nomic-embed-text"     # Embedding for RAG
        "llama3.2:3b"          # Fast classifier
    )
    for model in "${models[@]}"; do
        echo "Pulling $model..."
        ollama pull "$model"
    done
    echo "=== Stack Ready ==="
}

# Function: Clean old/unused models
clean_unused() {
    echo "=== Models Available for Cleanup ==="
    ollama list
    echo ""
    read -p "Enter model name to remove (or 'cancel'): " model
    if [ "$model" != "cancel" ] && [ -n "$model" ]; then
        ollama rm "$model"
        echo "Removed: $model"
    fi
}

# Main menu
echo "1. Show inventory"
echo "2. Pull SupportBot stack"
echo "3. Clean unused models"
read -p "Choose: " choice
case $choice in
    1) show_inventory ;;
    2) pull_support_stack ;;
    3) clean_unused ;;
esac

❓ FAQ

Q ollama pull download is too slow, what can I do?
A Models are hosted on ollama.com, which may be slow in some regions. You can set OLLAMA_MODELS to a custom path and download GGUF files from a mirror site for manual import. See Lesson 8 Modelfile for details.
Q Disk space wasn't freed after deleting a Model?
A Ollama uses content-addressable storage (CAS); blob files may be shared by other Models. ollama rm only removes references. Restart the service to trigger cleanup, or manually delete unreferenced files in the blobs directory.
Q How do I check a Model's maximum context length?
A Run ollama show <model> and look at the context length field. llama3.2 supports 131K tokens, mistral supports 32K tokens.
Q Can multiple Models run simultaneously?
A Yes, but limited by VRAM. Set OLLAMA_MAX_LOADED_MODELS=2 to allow loading 2 Models at once. A small Model (3B) + Embedding Model can share 8GB VRAM.
Q Does the latest tag auto-update?
A No. ollama pull only fetches the latest version when manually executed. Downloaded Models do not auto-update.
Q How do I get Models in an offline environment?
A Pull Models on an online machine, then package the ~/.ollama/models/blobs/ directory, transfer to the offline machine, and extract to the same path. You can also download GGUF files from HuggingFace and import via Modelfile.

📖 Summary


📝 Exercises

  1. Basic (Difficulty ⭐): Pull 3 Models with different parameter counts (3B/8B/Embedding), then view details with ollama list and ollama show.
  2. Intermediate (Difficulty ⭐⭐): Based on your hardware configuration, select an appropriate Model combination for a SupportBot scenario (main chat + Embedding) and explain your selection reasoning.
  3. Advanced (Difficulty ⭐⭐⭐): Implement an offline migration workflow — pull Models on one machine, package and transfer to another offline machine, and verify functionality.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏