
Learn how to run powerful DeepSeek AI models locally on your computer using Ollama. This guide covers installation, configuration, model management, and practical usage examples.
Running powerful AI models locally offers privacy, reduced costs, and lower latency. This guide will show you how to run DeepSeek models on your computer using Ollama, a tool designed for managing and running AI models locally.
Table of Contents
Prerequisites
Before starting, ensure your system meets these requirements:
Hardware Requirements:
- Minimum 16GB RAM (32GB recommended)
- NVIDIA GPU with 8GB+ VRAM (for GPU acceleration)
- 50GB+ free disk space
Software Requirements:
- Windows 10/11, macOS, or Linux
- NVIDIA drivers (if using GPU)
- Docker (optional, but recommended)
Installing Ollama
1. Windows Installation
# Using Windows Package Manager (winget)
winget install Ollama.Ollama
# Or download and run the installer from:
# https://ollama.ai/download/windows2. macOS Installation
# Using Homebrew
brew install ollama
# Or using curl
curl -fsSL https://ollama.ai/install.sh | sh3. Linux Installation
# Using curl
curl -fsSL https://ollama.ai/install.sh | sh
# For Ubuntu/Debian
curl -fsSL https://ollama.ai/install.sh | sudo bashSetting Up DeepSeek Models
1. Available DeepSeek Models
# List available DeepSeek models
ollama list
# Pull DeepSeek models
ollama pull deepseek-coder:6.7b
ollama pull deepseek-coder:33b
ollama pull deepseek-llm:7b2. Custom Model Configuration
# modelfile
FROM deepseek-coder:6.7b
PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER num_ctx 8192
# System prompt configuration
SYSTEM """You are an AI programming assistant. Write code that is:
- Well-documented
- Efficient
- Following best practices
"""3. Building Custom Model
# Build custom model from modelfile
ollama create deepseek-custom -f modelfile
# Verify model creation
ollama listUsage Examples
1. Basic Interaction
# Start interactive session
ollama run deepseek-coder:6.7b
# Or use single command
echo "Write a Python function to calculate fibonacci numbers" | ollama run deepseek-coder:6.7b2. Code Generation
# Example response from DeepSeek Coder
def fibonacci(n):
"""
Calculate the nth Fibonacci number using dynamic programming.
Args:
n (int): The position in the Fibonacci sequence (0-based)
Returns:
int: The nth Fibonacci number
"""
if n <= 1:
return n
fib = [0] * (n + 1)
fib[1] = 1
for i in range(2, n + 1):
fib[i] = fib[i-1] + fib[i-2]
return fib[n]3. API Integration
# Using Python with Ollama API
import requests
def query_deepseek(prompt):
response = requests.post('http://localhost:11434/api/generate',
json={
'model': 'deepseek-coder:6.7b',
'prompt': prompt,
'stream': False
})
return response.json()['response']
# Example usage
code = query_deepseek("Write a function to sort a list in Python")
print(code)Performance Optimization
1. GPU Acceleration
# Check GPU availability
nvidia-smi
# Enable GPU in Ollama
export OLLAMA_CUDA=1
export OLLAMA_GPU_LAYERS=352. Memory Management
# Configure memory limits
export OLLAMA_HOST=0.0.0.0
export OLLAMA_MODELS=/path/to/models
export OLLAMA_MEMORY_LIMIT=16GB3. Context Window Optimization
# Modelfile with optimized parameters
FROM deepseek-coder:6.7b
PARAMETER num_ctx 4096 # Adjust based on your RAM
PARAMETER num_gpu 1
PARAMETER num_thread 8Troubleshooting
1. Common Issues
# Check Ollama status
ollama serve status
# View logs
tail -f ~/.ollama/logs/ollama.log
# Reset Ollama
ollama kill
ollama serve2. Memory Issues
# Monitor memory usage
ps aux | grep ollama
nvidia-smi -l 1 # GPU memory monitoring
# Clear model cache
rm -rf ~/.ollama/models/*
ollama pull deepseek-coder:6.7b # Re-download modelBest Practices
1. Model Management
# Regular maintenance
ollama list # Check installed models
ollama rm unused-model # Remove unused models
ollama pull model:latest # Update models2. Production Setup
# Docker compose configuration
version: '3.8'
services:
ollama:
image: ollama/ollama
container_name: ollama-deepseek
ports:
- "11434:11434"
volumes:
- ./models:/root/.ollama/models
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]3. Security Considerations
# Secure API access
export OLLAMA_HOST=localhost # Restrict to local access
export OLLAMA_ORIGINS=https://your-app.com # CORS configuration
# Use environment variables for sensitive settings
export OLLAMA_API_KEY="your-api-key"Conclusion
Running DeepSeek models locally with Ollama provides a powerful way to leverage AI capabilities while maintaining control over your data and resources. Key takeaways:
- Choose appropriate model size based on your hardware
- Optimize performance using GPU acceleration
- Monitor resource usage and adjust configurations
- Follow security best practices for production deployments
Additional Resources
Written by
TheDBAdmin Team
KEEP LEARNING WITH THEDBADMIN
Turn this guide into a skill you can prove
Keep reading
Related articles
NextGen DBA + AI Engineer Bootcamp
Instructor-led, lab-first training for production DBAs: PostgreSQL, MongoDB, Docker, Kubernetes and AI.
- Live labs on real execution plans
- Backup, PITR & HA in production
- pgvector, RAG & AI for DBAs
🛒 FROM THE SHOP

AWS CLI for PostgreSQL DBA
PDF · 34 pages
₹50₹50090% off