Deploy a Self-Hosted AI Assistant on Ubuntu 24.04: A Complete Guide to Connecting LLM APIs

    This guide walks through deploying a self-hosted AI assistant platform on Ubuntu 24.04 LTS and connecting it to a large language model API. It covers why self-hosting matters, environment prerequisites, installing the runtime and platform with nvm and npm, common installation errors and fixes, configuring an OpenAI-compatible custom provider, and securing the web console through SSH port forwarding. A final acceptance checklist helps you confirm a private, model-agnostic setup with data kept on your own disk.

    1. Why Choose a Self-Hosted AI Assistant

    Running an AI assistant on your own server delivers three core benefits: control over where data flows, the ability to swap capabilities, and predictable usage costs. Compared with using a public hosted service directly, a self-hosted setup keeps conversation history, prompt templates, and knowledge snippets on disks you manage. At the same time, the model service is abstracted into a “replaceable backend.” You can connect a general-purpose LLM API from one vendor today and switch to another model service tomorrow by adjusting configuration only, without changing the application layer above it.

    A typical self-hosted AI assistant platform usually has the following capability layers:

    • Model integration layer: Uses the OpenAI-compatible HTTP interface as a common protocol to connect to various cloud LLM services or local inference services.
    • Session and orchestration layer: Maintains multi-turn context, system prompts, and tool-calling flows.
    • Interaction layer: Provides a browser-based web console and a terminal interface.
    • Channel layer: Connects to instant messaging tools through bot interfaces, making “the chat window the entry point.”

    Understanding this layering matters: most of the installation and configuration effort concentrates on the correctness of parameters in the model integration layer and the access security of the interaction layer.

    2. Environment Preparation and Prerequisites

    Item Recommendation
    Operating system Ubuntu 24.04 LTS server edition
    Runtime account root is available initially, but create a regular user and configure key-based login afterward
    Runtime Node.js 22 LTS (installed via a version manager)
    Model service A cloud vendor’s LLM API key (most platforms offer a free trial quota)
    Local terminal Any OS that supports SSH

    A note on the runtime choice: the Node.js version in the official Ubuntu repositories often lags behind, while this kind of AI assistant platform iterates frequently and has higher runtime version requirements. Installing Node.js under your user directory with nvm (Node Version Manager) avoids polluting the system package management state and makes it easy to switch versions and roll back at any time.

    1. # Install the version manager (use the latest version from the official source)
    2. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    3. source ~/.bashrc
    4. # Install and set the default LTS version
    5. nvm install 22
    6. nvm alias default 22
    7. node --version # expect output like v22.x.x
    8. npm --version

    If the server is on an internal network and cannot reach external repositories directly, download the install script and the Node.js binary package locally first, relay them through an internal file service or object storage, and then install offline.

    3. Install the AI Assistant Platform

    Once the runtime is ready, install globally with npm:

    1. npm install -g openclaw@latest
    2. openclaw --version # outputs a version number like 2026.3.2

    Common Failures and How to Diagnose Them

    1. ENOTEMPTY: directory not empty

    This is the most typical error for npm global installs. The root cause is an incomplete module directory left behind by a previous install or upgrade. Clean up the leftovers and cache, then reinstall:

    1. rm -rf /root/.npm-global/lib/node_modules/openclaw
    2. npm cache clean --force
    3. npm install -g openclaw@latest

    If you set a custom npm global prefix, replace the path with the actual output of npm prefix -g.

    2. Many deprecated warnings

    Deprecation warnings for packages in the dependency tree are normal in the ecosystem. As long as the install ultimately succeeds and the command is executable, no action is needed.

    3. EACCES permission errors

    Do not reflexively reach for sudo. A more robust approach is to configure a dedicated global directory for the current user:

    1. npm config set prefix ~/.npm-global
    2. echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
    3. source ~/.bashrc

    4. Command not found

    This is usually because PATH does not include the global bin directory, or the install was run under a different shell user. Check whether which node and npm prefix -g are consistent.

    4. Connect a Large Model Service (Using the Common Compatible Protocol)

    Most mainstream LLM platforms provide an OpenAI-compatible HTTP interface, which makes the “custom provider” configuration mode highly reusable. Run the interactive wizard:

    1. openclaw config

    Fill in the following in order:

    1. Select Add custom provider (add a provider manually);
    2. Provider name: a custom identifier, such as zhipu;
    3. API Base URL: the v4-compatible endpoint root from the vendor’s documentation, in the form https://<vendor-domain>/api/paas/v4;
    4. API Key: a key starting with sk-;
    5. Model name: a currently available model identifier on that platform (for example, a free or lightweight model like GLM-4.7-Flash);
    6. Keep the remaining parameters (temperature, max output length, timeout) at their defaults, and tune them after the setup works.

    After configuration, you can edit the config file directly to verify it and avoid input errors from the wizard:

    1. openclaw config get
    2. # or view the config file directly (path per the actual output)
    3. cat ~/.openclaw/config.json

    Key fields usually include providers, baseUrl, apiKey, model, and temperature. If a call returns 401, first check whether the key is truncated or contains spaces; a 404 usually means the Base URL is missing or has an extra /v4; a model-not-found error means the model identifier does not match the platform’s current list.

    It is recommended to put the key in an environment variable rather than in plaintext config:

    1. export LLM_API_KEY='sk-xxxxxxxx'

    Then reference the variable in the config, and tighten the config file permissions with chmod 600.

    5. Secure Access to the Web Console

    The web console listens on a local port on the server by default. Exposing it directly to the public internet creates a risk of unauthorized access. The recommended approach is SSH port forwarding, mapping the remote port to your local machine:

    1. ssh -L 8080:127.0.0.1:8080 user@your-server-ip
    2. # keep this terminal open, then open http://127.0.0.1:8080 in your local browser

    For long-running background use, add the -N -f options, or add an entry to your local ~/.ssh/config:

    1. Host ai-box
    2. HostName your-server-ip
    3. User your-server
    4. LocalForward 8080 127.0.0.1:8080

    After that, ssh ai-box establishes the tunnel. Compared with opening a public port, this approach keeps the console out of any scan range, protects access with the SSH key system, and requires no extra reverse proxy or certificates to maintain.

    Further hardening recommendations:

    • Create a regular user and disable root password login, keeping key authentication only;
    • Use a firewall to allow only the SSH port;
    • Set up a dedicated systemd service for the AI assistant process with Restart=always, and route logs to a centralized logging service;
    • Upgrade the runtime and platform versions regularly, and snapshot the config directory before upgrading.

    6. Deployment Acceptance Checklist

    1. node --version outputs the expected LTS version;
    2. The platform version command returns a normal version number;
    3. The model connectivity test in the config wizard passes;
    4. The terminal interface can complete a multi-turn conversation;
    5. After the SSH tunnel is established, the local browser can open the console and no public listening port exists on the remote side;
    6. The process comes back up automatically after a restart, with no repeating errors in the logs.

    Once you have completed the flow above, you have a private AI assistant environment that is model-replaceable, self-contained in data, and not exposed to the public internet. From here you can extend it with knowledge base retrieval, scheduled tasks, and multi-channel bot integration, gradually evolving it into a unified intelligent entry point for your team.