How to Install Dify on Ubuntu 24.04
A step-by-step installation guide.
How to Install Dify on Ubuntu 24.04
Dify is the leading open-source LLM app platform β create visual RAG pipelines, agent workflows, and AI chatbots with drag-and-drop. Connect any LLM, embed knowledge bases, and deploy via API. This guide covers self-hosted installation on Ubuntu 24.04 using Docker.
Prerequisites
- CPU: 2 cores minimum (4 recommended)
- RAM: 4 GB minimum (8 GB recommended)
- Disk: 10 GB free space (20 GB+ for embeddings)
- OS: Ubuntu 24.04 LTS
- Docker + Docker Compose (v2.20+)
- Git and sudo access
Step 1 β Install Docker (if missing)
curl -fsSL https://get.docker.com | sudo sh
sudo usermod -aG docker $USER
newgrp docker
docker --version && docker compose version
Step 2 β Deploy with Docker Compose
git clone https://github.com/langgenius/dify.git
cd dify/docker
cp .env.example .env
docker compose up -d
Once running: Web UI at http://YOUR_IP:3001, API at http://YOUR_IP:3000 (image: langgenius/dify:latest).
Step 3 β Environment Variables
Edit dify/docker/.env before first start:
SECRET_KEYβ Session encryption key. Generate withopenssl rand -base64 42. Never change after setup β doing so invalidates all sessions.INIT_PASSWORDβ Admin password for first-run initialization.LOG_LEVELβINFO,WARNING, orERROR. UseWARNINGin production.
LLM Providers
Add API keys in Settings β Model Provider. Supports OpenAI, Azure, Anthropic, Gemini, Ollama, and dozens more.
RAG Configuration
Set Embedding Model (e.g., text-embedding-3-small via OpenAI, or local via Ollama) and optional Rerank Model (Cohere, BAAI/bge-reranker, Jina) under Settings β Model Provider.
Step 4 β Nginx Reverse Proxy (Same Domain)
Serve Web UI and API on one domain:
server {
listen 80;
server_name dify.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /api/ {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Enable HTTPS: sudo certbot --nginx -d dify.yourdomain.com.
Step 5 β Backup
docker exec dify-db-1 pg_dump -U dify dify > dify_$(date +%F).sql
tar -czf dify_storage_$(date +%F).tar.gz ./dify/docker/volumes
Step 6 β Update
cd dify && git pull && docker compose up -d --pull always && docker image prune -f
Review GitHub releases for breaking changes before upgrading.
Step 7 β Change Default Admin Password
After first login, go to Settings β Account β Security and set a strong password (8+ chars, mixed case + numbers).
Troubleshooting
Port conflicts (5432/6379): PostgreSQL and Redis use these ports. Remap in docker-compose.yml: db β ports: "5433:5432", redis β ports: "6380:6379".
Database migration fails: Run docker compose run --rm api flask db upgrade manually, then restart.
LLM API key issues: Verify quota/status in the provider dashboard. For Ollama, ensure the container can reach the server at http://host.docker.internal:11434 (Docker Desktop) or the host IP. Check logs: docker compose logs api | grep -i error.
Visit runthisai.com/en/tool/dify for system requirements, VPS recommendations, and related tutorials.