What Is Ollama?
Ollama is a tool that makes running large language models as easy as running a database. Instead of paying per API call to OpenAI, Anthropic, or Google, you download models to your computer and run them locally. Think of it like Docker for AI models, simple installation, easy model management, and standardized API access.
| Aspect | Cloud AI (OpenAI, etc.) | Ollama (Local AI) |
|---|---|---|
| Cost | Per-token API pricing | Free (hardware cost only) |
| Privacy | Data sent to cloud servers | 100% local, offline |
| Internet | Required | Optional (only for downloads) |
| Speed | Network latency + processing | Local processing only |
| Model Selection | Fixed (GPT-4, Claude, etc.) | Large open model library, custom fine-tunes |
| Hardware Required | None (cloud) | 8GB+ RAM recommended |
| Setup Time | Instant (API key) | 5-10 min install + download |
Why Use Ollama?
- Zero API Costs 2026: Run unlimited queries with no per-token charges, pay only for electricity.
- Complete Privacy 2026: Data never leaves your machine, critical for sensitive business data, healthcare, legal.
- Offline Capability 2026: Works without internet after model download, essential for air-gapped environments, demos, travel.
- Model Flexibility 2026: Run many open models (Llama, Mistral, Gemma, custom fine-tunes), switch models instantly.
- OpenAI-Compatible API 2026: Drop-in replacement for OpenAI API, migrate existing apps with minimal code changes.
- Fast Local Inference: No network latency, responses limited only by your hardware speed.
- Open-Source: MIT licensed, community-driven, transparent, no vendor lock-in.
How to Install Ollama
Installation on macOS
# Download installer
curl -fsSL https://ollama.com/install.sh | sh
# Or use Homebrew
brew install ollama
# Verify installation
ollama --version
# Output: ollama version (your installed version number)
Installation on Linux
# One-line install script
curl -fsSL https://ollama.com/install.sh | sh
# Start Ollama service
sudo systemctl start ollama
# Enable on boot
sudo systemctl enable ollama
# Check status
ollama serve
Installation on Windows
- Download installer from ollama.com/download
- Run
OllamaSetup.exe - Installation creates Windows service (auto-starts)
- Open Command Prompt or PowerShell → Type
ollamato verify
System Requirements
| Model Size | Min RAM | Recommended RAM | GPU (Optional) |
|---|---|---|---|
| Small (1-3B params) | 4GB | 8GB | Not needed |
| Medium (7-13B params) | 8GB | 16GB | 6GB VRAM (faster) |
| Large (30-70B params) | 32GB | 64GB | 24GB VRAM (required for speed) |
| Extra Large (405B params) | 256GB | 512GB | 80GB+ VRAM (A100/H100) |
Note: Most users run 7B-13B models on laptops with 16GB RAM. Quantized models (Q4, Q5) reduce memory requirements.
How to Use Ollama: Basic Commands
Download and Run Your First Model
# Pull Llama 3.1 (8B parameters, ~4.9GB download)
ollama pull llama3.1
# Run interactive chat
ollama run llama3.1
# Chat interface appears:
>>> Write a Python function to calculate factorial
# Model responds with code
>>> /bye
# Exit chat
Essential Ollama Commands
| Command | Purpose | Example |
|---|---|---|
ollama pull | Download model | ollama pull mistral |
ollama run | Start chat with model | ollama run llama3.1 |
ollama list | Show installed models | ollama list |
ollama ps | Show running models | ollama ps |
ollama rm | Delete model | ollama rm llama2 |
ollama serve | Start API server | ollama serve |
ollama create | Create custom model | ollama create mymodel -f Modelfile |
Popular Models in Ollama
| Model | Size | Best For | Pull Command |
|---|---|---|---|
| Llama 3.1 8B | 4.9GB | General purpose, fast | ollama pull llama3.1 |
| Llama 3.3 70B | 43GB | Advanced reasoning | ollama pull llama3.3 |
| Mistral 7B | 4.4GB | Coding, fast responses | ollama pull mistral |
| Gemma 2 9B | 5.4GB | Google's open model | ollama pull gemma2 |
| Phi-3 | 2.2GB | Small, efficient | ollama pull phi3 |
| CodeLlama 13B | 7.4GB | Code generation | ollama pull codellama:13b |
| DeepSeek Coder 6.7B | 3.8GB | Advanced coding | ollama pull deepseek-coder:6.7b |
| Mixtral 8x7B | 26GB | Mixture of experts | ollama pull mixtral |
Using Ollama API
Start Ollama API Server
# Ollama automatically starts server on install
# Default: http://localhost:11434
# Check server status
curl http://localhost:11434
# Output: Ollama is running
OpenAI-Compatible API
Ollama provides OpenAI-compatible endpoints, drop-in replacement for OpenAI SDK:
from openai import OpenAI
# Point to Ollama instead of OpenAI
client = OpenAI(
base_url="http://localhost:11434/v1",
api_key="ollama" # Not used, but required by SDK
)
response = client.chat.completions.create(
model="llama3.1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms"}
]
)
print(response.choices[0].message.content)
Native Ollama Python Library
import ollama
# Simple chat
response = ollama.chat(
model='llama3.1',
messages=[
{'role': 'user', 'content': 'Write a haiku about coding'}
]
)
print(response['message']['content'])
# Streaming response
for chunk in ollama.chat(
model='llama3.1',
messages=[{'role': 'user', 'content': 'Count to 10'}],
stream=True
):
print(chunk['message']['content'], end='', flush=True)
Ollama REST API
# Generate completion
curl http://localhost:11434/api/generate -d '{
"model": "llama3.1",
"prompt": "Why is the sky blue?",
"stream": false
}'
# Chat endpoint
curl http://localhost:11434/api/chat -d '{
"model": "mistral",
"messages": [
{"role": "user", "content": "What is 2+2?"}
]
}'
# List models
curl http://localhost:11434/api/tags
# Model info
curl http://localhost:11434/api/show -d '{"name": "llama3.1"}'
Advanced Ollama Features
Custom Modelfiles
Create custom models with specific prompts, temperature, context length:
# Create file: Modelfile
FROM llama3.1
# Set system prompt
SYSTEM You are a Python coding expert. Provide concise, executable code.
# Set parameters
PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER top_k 40
PARAMETER num_ctx 4096
# Create custom model
ollama create python-expert -f Modelfile
# Use it
ollama run python-expert "Write a binary search function"
Multimodal Models (Vision)
# Pull vision model (LLaVA)
ollama pull llava
# Analyze image
ollama run llava "What's in this image? /path/to/image.jpg"
# Python API
import ollama
response = ollama.chat(
model='llava',
messages=[{
'role': 'user',
'content': 'Describe this image',
'images': ['./screenshot.png']
}]
)
print(response['message']['content'])
Model Quantization Levels
Ollama offers quantized versions to reduce memory usage:
| Quantization | Quality | Use When |
|---|---|---|
| Q2 | Lowest | Very limited RAM |
| Q4 | Good | Most common (default) |
| Q5 | Better | Balance quality/size |
| Q8 | High | Max quality on consumer hardware |
| F16/F32 | Maximum | Research, benchmarking |
# Pull specific quantization
ollama pull llama3.3:70b-instruct-q4_0 # 70B model, 4-bit quantization
ollama pull mistral:7b-instruct-q8_0 # 7B model, 8-bit quantization
Ollama Use Cases
1. Local Chatbot Development
import ollama
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/chat', methods=['POST'])
def chat():
user_message = request.json['message']
response = ollama.chat(
model='llama3.1',
messages=[
{'role': 'system', 'content': 'You are a helpful customer service bot.'},
{'role': 'user', 'content': user_message}
]
)
return jsonify({'reply': response['message']['content']})
app.run(port=5000)
2. Document Q&A with RAG
import ollama
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings import OllamaEmbeddings
from langchain.vectorstores import Chroma
# Load document
with open('company-handbook.txt') as f:
text = f.read()
# Split into chunks
splitter = RecursiveCharacterTextSplitter(chunk_size=500)
chunks = splitter.split_text(text)
# Create embeddings (local with Ollama)
embeddings = OllamaEmbeddings(model='llama3.1')
vectorstore = Chroma.from_texts(chunks, embeddings)
# Query
query = "What is the vacation policy?"
relevant_docs = vectorstore.similarity_search(query, k=3)
context = "\n".join([doc.page_content for doc in relevant_docs])
# Generate answer
response = ollama.chat(
model='llama3.1',
messages=[{
'role': 'user',
'content': f'Context: {context}\n\nQuestion: {query}'
}]
)
print(response['message']['content'])
3. Code Review Assistant
import ollama
code = """
def calculate_total(items):
total = 0
for item in items:
total = total + item['price'] * item['quantity']
return total
"""
prompt = f"""Review this Python code for:
1. Bugs
2. Performance issues
3. Best practices
4. Security concerns
Code:
{code}
Provide specific suggestions."""
response = ollama.chat(
model='codellama',
messages=[{'role': 'user', 'content': prompt}]
)
print(response['message']['content'])
4. Data Analysis Assistant
import ollama
import pandas as pd
# Load data
df = pd.read_csv('sales_data.csv')
summary = df.describe().to_string()
prompt = f"""Analyze this sales data summary and provide insights:
{summary}
Identify trends, anomalies, and recommendations."""
response = ollama.chat(
model='llama3.1',
messages=[{'role': 'user', 'content': prompt}]
)
print(response['message']['content'])
Ollama vs. Alternatives
| Tool | Interface | Ease of Use | Best For |
|---|---|---|---|
| Ollama | CLI + API | Easy (one command) | Developers, API integration |
| LM Studio | GUI | Easiest (visual) | Non-technical users, testing models |
| llama.cpp | CLI (lower level) | Advanced | Performance optimization, embedded systems |
| GPT4All | Desktop app | Easy | Local ChatGPT alternative |
| Jan.ai | Desktop app | Easy | Privacy-focused ChatGPT replacement |
Common Ollama Mistakes to Avoid
Running Models Too Large for Your RAM
Mistake: Pulling 70B model on 16GB laptop → System freezes, swapping to disk.
Fix: Use ollama list to check model sizes before pulling. Stick to 7B-13B models on 16GB RAM. Use quantized versions (Q4) to reduce memory.
Not Setting Context Window
Mistake: Default context (4096 tokens on GPUs with under 24 GiB VRAM) too small for long conversations.
Fix: Increase in Modelfile: PARAMETER num_ctx 8192 or via API: options={'num_ctx': 8192}
Expecting GPT-4 Quality from 7B Models
Mistake: Disappointed when Llama 7B doesn't match GPT-4 reasoning.
Fix: Understand model capabilities. 7B: Good for basic tasks, summaries, simple code. 70B+: Complex reasoning, analysis. Or use cloud API for critical tasks.
Not Enabling GPU Acceleration
Mistake: Running on CPU only when GPU available → much slower.
Fix: Ollama auto-detects GPU (NVIDIA/AMD). Verify: ollama ps shows GPU usage. Install CUDA drivers (NVIDIA) or ROCm (AMD) if not detected.
Forgetting to Stop Running Models
Mistake: Models stay loaded in RAM after exit → Consumes memory.
Fix: Check running models: ollama ps. Models auto-unload after 5 min idle, but can stop manually: ollama stop llama3.1
Key Takeaways: Ollama for Local LLMs
- Ollama is the easiest way to run large language models locally, one command to install, one command to run Llama, Mistral, Gemma, and many more models completely free and offline.
- Zero API costs after hardware investment, unlimited queries with no per-token charges. 16GB RAM laptop can run 7B-13B models comfortably for most business use cases.
- Complete data privacy and security, nothing leaves your machine. Critical for healthcare, legal, financial services, and any sensitive data processing.
- OpenAI-compatible API makes migration simple, existing apps using OpenAI SDK can switch to Ollama with 2-line code change (base_url change only).
- Model flexibility unmatched, switch between Llama (general), CodeLlama (coding), Mistral (fast), Mixtral (powerful), or custom fine-tuned models instantly.
- Common pitfalls: Don't run models larger than your RAM, enable GPU acceleration, use quantized models (Q4/Q5) for consumer hardware, increase context window for long conversations.
- Ready to implement local AI in your business for privacy and cost savings? Distk (distk.in) helps companies deploy Ollama-based solutions, build RAG systems, and create privacy-first AI applications.