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.
📋 Prerequisites: You need to master the following first
- Lesson 3: CLI Basic Interaction
1. What You Will Learn
- Complete guide to ollama list / pull / rm / show commands
- Model tag system and variant selection
- Ollama Library browsing and selection guide
- Model file storage and disk management
- Offline GGUF file migration
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.
# 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
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
# 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'
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:
NAME ID SIZE
llama3.2:latest a80... 2.0 GB
mistral:latest 61... 4.1 GB
4. Model Tag System
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 |
▶ Example 2: Pulling Different Quantization Variants
# 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:
pulling manifest...
success
5. Ollama Library and Model Selection
(1) Popular Model Selection Guide
| 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
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
# 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:
NAME ID SIZE
llama3.2:latest a80... 2.0 GB
mistral:latest 61... 4.1 GB
6. Disk Space Management and Offline Migration
~/.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
# 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:
NAME ID SIZE
llama3.2:latest a80... 2.0 GB
mistral:latest 61... 4.1 GB
▶ Example 5: Import Custom Model from GGUF File
# 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:
I'm a helpful AI assistant running locally on your machine...
7. Comprehensive Example: Alice's Model Management Script
#!/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
OLLAMA_MODELS to a custom path and download GGUF files from a mirror site for manual import. See Lesson 8 Modelfile for details.ollama rm only removes references. Restart the service to trigger cleanup, or manually delete unreferenced files in the blobs directory.ollama show <model> and look at the context length field. llama3.2 supports 131K tokens, mistral supports 32K tokens.OLLAMA_MAX_LOADED_MODELS=2 to allow loading 2 Models at once. A small Model (3B) + Embedding Model can share 8GB VRAM.ollama pull only fetches the latest version when manually executed. Downloaded Models do not auto-update.~/.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
ollama list/pull/rm/showare the four core Model management commands- The tag system (
name/parameter count/quantization) precisely identifies Model variants - Q4_K_M Quantization is the best value choice — 70% size reduction with nearly lossless quality
- Scenario-based selection: use qwen2.5 for Chinese, codellama for code, nomic-embed-text for Embedding
- Model storage path can be customized via the OLLAMA_MODELS environment variable
- Offline migration requires only packaging the blobs directory or importing from GGUF files
📝 Exercises
- Basic (Difficulty ⭐): Pull 3 Models with different parameter counts (3B/8B/Embedding), then view details with
ollama listandollama show. - Intermediate (Difficulty ⭐⭐): Based on your hardware configuration, select an appropriate Model combination for a SupportBot scenario (main chat + Embedding) and explain your selection reasoning.
- Advanced (Difficulty ⭐⭐⭐): Implement an offline migration workflow — pull Models on one machine, package and transfer to another offline machine, and verify functionality.