Deploying a Self-Hosted AI Assistant on Ubuntu 24.04: Full Integration Guide for Large Language Models

    This guide provides step-by-step instructions for deploying a self-hosted AI assistant platform on Ubuntu 24.04 LTS, covering system requirements, core platform installation, LLM service integration, security configurations, and maintenance best practices.

    System Requirements & Setup

    Server Specifications

    Recommended Ubuntu 24.04 LTS configuration:

    • CPU: 4 cores (8+ preferred for production)
    • Memory: 16GB RAM (32GB for high concurrency)
    • Storage: 100GB+ SSD-based disk space
    • Network: Static public IP or VPN solution

    Security Recommendation: While root access is used in examples, create dedicated users for production:

    1. sudo useradd -m aiuser && sudo passwd aiuser
    2. sudo usermod -aG sudo aiuser

    Node.js Environment

    Install using nvm for version management:

    1. # Install dependencies
    2. sudo apt update && sudo apt install -y curl git
    3. # Install nvm
    4. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    5. source ~/.bashrc
    6. # Install LTS Node.js
    7. nvm install 22
    8. nvm alias default 22
    9. node -v # Should show v22.x.x

    Core Platform Installation

    Global Installation

    1. npm install -g openclaw@latest --unsafe-perm=true --allow-root

    Parameters Explained:

    • --unsafe-perm: Resolves permission issues
    • --allow-root: Permits root installation (avoid in production)

    Troubleshooting:

    1. For ENOTEMPTY errors:
      1. rm -rf /root/.npm-global/lib/node_modules/openclaw
      2. npm cache clean --force
    2. Network timeouts: Use registry mirrors:
      1. npm config set registry https://registry.npmjs.org/

    Verify Installation

    1. openclaw --version # Should show version like 2026.3.2

    LLM Service Integration

    Obtain API Credentials

    1. Register with your preferred LLM provider
    2. Create dedicated project
    3. Generate API key (note the sk- prefix)
    4. Select nearest service region

    Configuration Wizard

    1. openclaw config

    Interactive setup steps:

    1. Select “Add custom provider”
    2. Enter provider name (e.g., zhipu-glm)
    3. Set API endpoint (example format):
      1. https://api.example.com/v1/chat/completions
    4. Paste API key (mask sensitive characters)
    5. Test connection (optional)

    Advanced Configuration (config.json):

    1. {
    2. "providers": {
    3. "zhipu-glm": {
    4. "apiBase": "https://api.example.com/v1",
    5. "apiKey": "sk-xxxxxxxxxxxxxxxx",
    6. "maxTokens": 4096,
    7. "temperature": 0.7
    8. }
    9. }
    10. }

    Secure Access Methods

    SSH Tunneling

    1. ssh -L 3000:localhost:3000 username@server_ip -N

    Access via http://localhost:3000

    Advantages:

    • No exposed web ports
    • End-to-end encryption
    • Network-agnostic

    Nginx Reverse Proxy (Production)

    1. Install Nginx:
      1. sudo apt install -y nginx
    2. Configure SSL (Let’s Encrypt example):
      1. sudo apt install -y certbot python3-certbot-nginx
      2. sudo certbot --nginx -d yourdomain.com
    3. Proxy configuration:

      1. server {
      2. listen 443 ssl;
      3. server_name yourdomain.com;
      4. location / {
      5. proxy_pass http://localhost:3000;
      6. proxy_set_header Host $host;
      7. proxy_set_header X-Real-IP $remote_addr;
      8. }
      9. ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
      10. ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
      11. }

    Maintenance Best Practices

    Log Management

    Configure log rotation:

    1. sudo mkdir /var/log/openclaw
    2. sudo chown aiuser:aiuser /var/log/openclaw

    Create /etc/logrotate.d/openclaw:

    1. /var/log/openclaw/*.log {
    2. daily
    3. missingok
    4. rotate 7
    5. compress
    6. delaycompress
    7. notifempty
    8. create 640 aiuser aiuser
    9. }

    Performance Optimization

    For high concurrency:

    1. Adjust Node.js memory:
      1. export NODE_OPTIONS="--max-old-space-size=8192"
    2. Enable clustering (if supported):
      1. openclaw start --workers 4

    Backup Strategy

    Regularly backup:

    • Configuration: ~/.openclaw/
    • Model caches (if applicable)
    • External databases

    Troubleshooting Guide

    Common Errors

    Code Cause Solution
    500 Model service error Check provider status page
    403 Invalid credentials Regenerate API key
    429 Rate limiting Adjust concurrency or upgrade plan
    ECONNREFUSED Network issue Verify firewall rules

    Diagnostic Commands

    1. # Service status
    2. systemctl status openclaw # If using systemd
    3. # Real-time logs
    4. journalctl -u openclaw -f
    5. # Network test
    6. curl -v https://api.example.com/health

    Advanced Features

    Multi-Model Routing

    1. {
    2. "routing": {
    3. "default": "zhipu-glm",
    4. "rules": [
    5. {
    6. "pattern": "^/tech/",
    7. "provider": "tech-specialized-model"
    8. }
    9. ]
    10. }
    11. }

    Plugin Development

    Example audit plugin:

    1. // ~/.openclaw/plugins/audit.js
    2. module.exports = {
    3. preProcess: (req) => {
    4. console.log(`Request from ${req.ip}`);
    5. },
    6. postProcess: (res) => {
    7. // Log response data
    8. }
    9. };

    Upgrade & Rollback

    Version Upgrade

    1. # Check for updates
    2. npm outdated -g openclaw
    3. # Upgrade
    4. npm update -g openclaw

    Rollback Procedure

    1. # Backup current version
    2. cp -r /usr/local/lib/node_modules/openclaw /usr/local/lib/node_modules/openclaw.bak
    3. # Install specific version
    4. npm install -g openclaw@2026.3.1

    This deployment framework enables rapid establishment of self-hosted AI assistant platforms on Ubuntu 24.04 while maintaining flexibility for enterprise requirements. The modular architecture supports seamless integration with various LLM providers while implementing robust security and monitoring controls. For production environments, we recommend implementing comprehensive monitoring alerts and regular security audits.