Chương 2: Cài Đặt OpenClaw
OpenClaw cài đặt trong 5 phút trên mọi nền tảng qua npm. Yêu cầu: Node.js 24+ (hoặc 22.16+), internet, 2GB RAM, và một API key AI.
⚠️ Yêu cầu: Node.js 24+ (khuyên dùng) hoặc Node 22.16+, internet, 2GB RAM trống, và một API key từ nhà cung cấp AI (OpenAI, Google, Anthropic...).
2.1 Cài trên macOS
Cài Node.js rồi dùng npm:
# Bước 1: Cài Node.js 24+
brew install node@24
# Bước 2: Cài OpenClaw
npm install -g openclaw@latest
# Bước 3: Chạy wizard
openclaw onboard --install-daemon2.2 Cài trên Windows
Khuyên dùng WSL2. Hoặc cài Node.js từ nodejs.org:
# Cách 1: WSL2 (khuyên dùng)
wsl --install
# Rồi theo hướng dẫn Linux bên dưới
# Cách 2: Native Windows
# Tải Node.js 24+ từ https://nodejs.org
npm install -g openclaw@latest
openclaw onboard --install-daemon2.3 Cài trên Linux
# Bước 1: Cài Node.js 24+ (NodeSource)
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
sudo apt-get install -y nodejs
# Bước 2: Cài OpenClaw
npm install -g openclaw@latest
openclaw onboard --install-daemon2.5 Kiểm tra cài đặt
openclaw --version
# → OpenClaw v1.x.x
openclaw doctor
# → Kiểm tra tất cả dependencies2.6 Cấu hình API Key
OpenClaw cần ít nhất 1 API key để kết nối model AI. Bạn có thể lấy từ:
- • OpenAI — platform.openai.com → Rẻ, nhanh, phổ biến nhất
- • Google Gemini — ai.google.dev → Có tier miễn phí
- • Anthropic Claude — console.anthropic.com → Thông minh nhất
- • DeepSeek — platform.deepseek.com → Rẻ nhất, tốt cho tiếng Việt
openclaw config set api_key YOUR_API_KEY_HERE
# Hoặc chỉnh file cấu hình:
openclaw config edit💡 Mẹo cho người Việt: DeepSeek là lựa chọn rẻ nhất (~$0.14/1M tokens) và hiểu tiếng Việt khá tốt. Google Gemini có tier miễn phí nếu bạn muốn thử trước.
2.7 Onboard Wizard — Cài đặt có hướng dẫn
Nếu bạn mới hoàn toàn, chạy wizard để được dẫn từng bước:
openclaw onboard --install-daemon
# Wizard sẽ hỏi bạn:
# 1. Chọn AI provider (Anthropic/OpenAI/Google...)
# 2. Paste API key
# 3. Chọn kênh chat (Telegram/Discord/Web)
# 4. Đặt tên cho trợ lý
# → Xong! Chạy lệnh bên dưới để bắt đầuopenclaw dashboard
# Mở trình duyệt → http://localhost:30002.8 Cài bằng Docker Compose (nâng cao)
Dùng Docker Compose để quản lý dễ hơn, đặc biệt khi chạy trên server:
version: "3.8"
services:
openclaw:
image: openclaw/openclaw:latest
container_name: openclaw
restart: unless-stopped
ports:
- "3000:3000" # Dashboard
- "18789:18789" # Gateway
volumes:
- ./openclaw-data:/root/.openclaw
environment:
- TZ=Asia/Ho_Chi_Minh
- OPENCLAW_API_KEY=${OPENCLAW_API_KEY}
healthcheck:
test: ["CMD", "openclaw", "doctor", "--quick"]
interval: 60s
timeout: 10s
retries: 3# Tạo file .env cùng thư mục
echo "OPENCLAW_API_KEY=sk-your-key-here" > .env
# Khởi động
docker compose up -d
# Xem logs
docker compose logs -f openclaw2.9 Xử Lý Lỗi Cài Đặt Thường Gặp
EACCES permission denied→ Dùng sudo hoặc --prefixnode: command not found→ Cài Node.js 24+Port 18789 already in use→ lsof -i :18789 → kill PIDAPI key invalid→ Kiểm tra lại key từ providerGateway auth error→ openclaw config set gateway.auth.mode token
openclaw doctor --deep --yes
# Tự động phát hiện và sửa hầu hết lỗi2.10 Cài trên Android (Termux)
Bạn có thể chạy OpenClaw ngay trên điện thoại Android — miễn phí, không cần máy tính:
# Tải Termux từ F-Droid (KHÔNG dùng Google Play)
# https://f-droid.org/packages/com.termux/pkg update && pkg upgrade
pkg install nodejs-lts
npm i -g openclaw
openclaw onboard⚠️ Termux chạy chậm hơn máy tính. Nên dùng model nhẹ (DeepSeek, Gemini Flash).
2.11 Deploy lên Cloud (VPS / Railway / Render)
Muốn OpenClaw chạy 24/7 không cần bật máy? Deploy lên cloud:
# Thuê VPS từ $3-5/tháng (DigitalOcean, Linode, Vultr)
# SSH vào server:
ssh root@your-server-ip
# Cài đặt
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g openclaw@latest
openclaw onboard --install-daemon
# Chạy nền (daemon)
openclaw gateway start --daemon# Truy cập railway.app → New Project → Deploy from GitHub
# Chọn repo: openclaw/openclaw
# Thêm biến môi trường: OPENCLAW_API_KEY
# → Tự động deploy, có SSL, miễn phí $5/tháng2.12 Chọn Model AI nào cho lần đầu?
Lần đầu dùng OpenClaw? Đây là gợi ý theo ngân sách:
| Ngân sách | Model khuyên dùng | Chi phí |
|---|---|---|
| Miễn phí | Gemini 2.0 Flash | $0 (1500 req/ngày) |
| Tiết kiệm | DeepSeek V3 | ~$1-3/tháng |
| Cân bằng | GPT-4o mini | ~$3-8/tháng |
| Chất lượng cao | Claude Sonnet 4 | ~$5-15/tháng |
| Local (offline) | Ollama + Llama 3 | $0 (cần GPU 8GB+) |
# Ví dụ: dùng DeepSeek (rẻ, tiếng Việt tốt)
openclaw config set models.primary.provider deepseek
openclaw config set models.primary.apiKey sk-your-deepseek-key
openclaw config set models.primary.model deepseek-chat
# Kiểm tra kết nối
openclaw doctor --check-models2.13 Lấy API Key — Hướng dẫn từng provider
Anthropic (Claude)
- 1. Truy cập console.anthropic.com
- 2. Đăng ký / Đăng nhập → API Keys → Create Key
- 3. Copy key (bắt đầu bằng sk-ant-...)
OpenAI (GPT)
- 1. Truy cập platform.openai.com
- 2. API Keys → Create new secret key
- 3. Copy key (bắt đầu bằng sk-...)
Google (Gemini)
- 1. Truy cập aistudio.google.com
- 2. Get API Key → Create API key
- 3. Free tier: 1500 requests/ngày!
DeepSeek
- 1. Truy cập platform.deepseek.com
- 2. Đăng ký → API Keys → Create
- 3. Nạp $5 dùng được vài tháng!
OpenRouter (1 key = 100+ models)
- 1. Truy cập openrouter.ai
- 2. Keys → Create Key
- 3. 1 API key dùng được Claude, GPT, Gemini, DeepSeek...
🚨 Lỗi thường gặp: Nếu thấy 'command not found', hãy đóng terminal và mở lại, hoặc thêm OpenClaw vào PATH. Chạy 'openclaw doctor' để kiểm tra.
