Cybersecurity

What Is Ollama?

Python Docker LLMs RAG Prompt Engineering Linux Cloud REST API Quantization Local AI GGUF Ollama LLaMA HTTPS
1,385 words Includes Code
Key Takeaway: Ollama is the easiest way to run local AI models on your computer. One command downloads a model. Another command starts chatting. No API key, no internet required after download, complete privacy. Install in 5 minutes, chat with AI in 60 seconds.

You want to try local AI but the setup seems complicated. Model files, quantization, runtimes, command-line tools — where do you even start?

Ollama makes this simple. It is a single application that downloads, manages, and runs AI models on your computer. Think of it as "Docker for AI models" — pull a model, run it, chat with it. That is it.

What Is Ollama?

Ollama is a lightweight, open-source tool that lets you run large language models (LLMs) locally on your computer. It handles everything: downloading models, loading them into memory, managing GPU acceleration, and providing an API for your applications.

Ollama Architecture:

👤 You → 🖥️ Ollama (localhost:11434) → 🧠 Model → ⚡ CPU/GPU → 💬 Response
                                                            │
                                                            ↓
                                                      🔒 Everything stays on your PC

Why Use Ollama?

FeatureOllamaManual Setup
InstallationOne installerCompile from source, install dependencies
Model downloadollama pull modelFind model, download, convert format
Model managementAutomaticManual file management
GPU detectionAutomaticManual configuration
APIBuilt-in REST APIBuild your own
UpdatesOne commandManual rebuild

Supported Operating Systems

OSStatusNotes
macOS✅ SupportedApple Silicon (M1-M4) has native acceleration
Linux✅ SupportedNVIDIA GPU acceleration on most distros
Windows✅ SupportedNVIDIA GPU acceleration, WSL2 recommended

Installation

macOS

Download from https://ollama.com/download
Or with Homebrew: brew install ollama

Linux

curl -fsSL https://ollama.com/install.sh | sh

Windows

Download the installer from https://ollama.com/download
Run the .exe installer and follow the prompts.

Verify Installation

# Check Ollama is installed: ollama --version # → ollama version 0.x.x

Downloading a Model

# Download the Llama 3.1 8B model (~4.7 GB): ollama pull llama3.1:8b # Other popular models: ollama pull mistral:7b # ~4.1 GB ollama pull phi3:mini # ~2.2 GB — smallest useful model ollama pull qwen2.5:7b # ~4.4 GB ollama pull gemma2:9b # ~5.4 GB
💡 Tip: Start with phi3:mini (2.2 GB) if you have limited RAM or want the fastest download. It handles basic tasks well. Upgrade to llama3.1:8b when you want better quality.

Running a Model

# Start interactive chat: ollama run llama3.1:8b # You'll see a prompt where you can type questions: >>> What is the capital of France? The capital of France is Paris. >>> How do I read a file in Python? You can use the built-in open() function... >>> /bye # Type /bye to exit

Model Management

# List downloaded models: ollama list # Show model details: ollama show llama3.1:8b # Remove a model: ollama rm phi3:mini # Copy a model: ollama cp llama3.1:8b my-llama

Model Storage

Downloaded models are stored in:

OSDefault Location
macOS~/.ollama/models/
Linux~/.ollama/models/
Windows%USERPROFILE%\.ollama\models\

Models are stored in GGUF format (quantized). The actual disk usage depends on the quantization level.

📖 Read more: GGUF Explained: The Practical Guide to Local LLM Model Files

Configuration

Environment Variables

# Set custom model storage location: export OLLAMA_MODELS=/path/to/models # Set custom API host: export OLLAMA_HOST=0.0.0.0:11434 # Set GPU layers (for advanced users): export OLLAMA_NUM_GPU_LAYERS=35

Context Settings

Context length affects how much text the model can process. You can override it per request:

# In the API, set context length: { "model": "llama3.1:8b", "prompt": "...", "options": { "num_ctx": 8192 // 8K context window } }
📖 Read more: AI Tokens and Context Windows Explained: Why They Matter

API Usage

Ollama runs a local API server at http://localhost:11434. Every chat message you send in the terminal uses this API.

Generate Completion

# Using curl: curl http://localhost:11434/api/generate -d '{ "model": "llama3.1:8b", "prompt": "What is Python?", "stream": false }'

Chat Completion

# Using curl: curl http://localhost:11434/api/chat -d '{ "model": "llama3.1:8b", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is Python?"} ], "stream": false }'

Python Integration

The demo below shows a complete Python client for Ollama. It works with the real API when Ollama is running, and falls back to mock responses when it is not.

import json, urllib.request class OllamaClient: def __init__(self, base_url="http://localhost:11434"): self.base_url = base_url def chat(self, model, messages, temperature=0.7): payload = { "model": model, "messages": messages, "stream": False, "options": {"temperature": temperature}, } data = json.dumps(payload).encode("utf-8") req = urllib.request.Request( f"{self.base_url}/api/chat", data=data, headers={"Content-Type": "application/json"}, ) with urllib.request.urlopen(req, timeout=60) as resp: return json.loads(resp.read()) # Usage: client = OllamaClient() response = client.chat( model="llama3.1:8b", messages=[{"role": "user", "content": "What is Python?"}], ) print(response["message"]["content"])
💡 Try it yourself: Save the demo as demo.py and run python demo.py to see the full Ollama integration in action. Run python demo.py --test to verify all 15 test cases.

First 10 Things to Try

#Try ThisWhat You Learn
1ollama run phi3:miniBasic chat interaction
2Ask "Explain Python in 3 sentences"Concise responses
3Ask "Write a Python function to sort a list"Code generation
4ollama listModel management
5ollama pull llama3.1:8bDownloading models
6Compare answers between phi3 and llama3.1Model quality differences
7Ask the same question 3 timesResponse consistency
8Ask about your code (paste a snippet)Code analysis
9ollama show llama3.1:8bModel metadata
10Ask "What are you good at?"Model self-assessment

Common Ollama Problems and Solutions

ProblemSolution
"command not found: ollama"Restart your terminal after installation, or check PATH
"model not found"Run ollama pull model_name first
"out of memory"Use a smaller model (phi3:mini) or more RAM
Very slow responsesModel is running on CPU. Install NVIDIA drivers for GPU acceleration
"connection refused"Start Ollama: ollama serve (or restart the Ollama app)
Garbled outputModel may be corrupted. Delete and re-download: ollama rm + ollama pull
Model uses too much RAMSmaller models use less RAM. phi3:mini needs ~4GB, llama3.1:8b needs ~8GB
GPU not detectedInstall NVIDIA CUDA drivers. On macOS, GPU acceleration is automatic for Apple Silicon

Hardware Requirements

RAMBest ModelExperience
8GBphi3:mini (3.8B)Basic chat, works but slower on CPU
16GBllama3.1:8b, mistral:7bGood for most tasks
32GB13B-30B modelsStrong performance
16GB + GPUllama3.1:8b at full speedBest experience
📖 Read more: Local AI in 2026: What Can You Really Run on a Laptop?

Build a Local Command-Line Assistant

The demo includes a complete LocalAssistant class that you can use as a starting point:

from demo import LocalAssistant assistant = LocalAssistant( model="llama3.1:8b", system_prompt="You are a helpful coding assistant." ) # Ask questions: answer = assistant.ask("How do I read a file in Python?") print(answer) # Multi-turn conversation: answer = assistant.ask("Can you show me an example?") print(answer) # Clear history: assistant.clear_history()

FAQ

Q: Is Ollama free?
A: Yes. Ollama is open-source and free to use. Models are also free to download.

Q: Do I need an API key?
A: No. Ollama runs locally. No API key, no account, no subscription.

Q: Does Ollama work offline?
A: Yes. After downloading models, everything runs offline. No internet required.

Q: Can I use Ollama with Python?
A: Yes. Ollama provides a REST API at localhost:11434. Use urllib, requests, or the official ollama Python package.

Q: How much disk space do I need?
A: 5-10 GB for a few small models. Each model is 2-6 GB depending on size and quantization.

Q: Can Ollama use my GPU?
A: Yes. Ollama automatically detects and uses NVIDIA GPUs on Linux/Windows, and Apple Silicon GPU on macOS.

What to Learn Next

🟢 Start here: Local AI Explained: What It Is, Why It Matters
🟡 Runtime comparison: Ollama vs llama.cpp vs LM Studio
🟡 Model files: GGUF Explained: The Practical Guide to Local LLM Model Files
🟡 Quantization: LLM Quantization Explained: 4-bit vs 8-bit Models
🟡 Hardware guide: Local AI in 2026: What Can You Really Run?
🔵 Build something: Build a Private Local AI Assistant
🔵 Prompt Engineering: Prompt Engineering: Complete Tutorial
🔵 RAG: RAG Explained: Complete Guide

Further Reading

Continue Learning: Understand what local AI is, compare runtimes, learn about quantization, and build your first local AI assistant.

Discuss this topic on BestWordz Community.

💬 Discuss on BestWordz Community

Join the conversation about Python, Docker, LLMs on the BestWordz Community forum.

Visit Forum →