Deploy a Self-Hosted AI Assistant Platform on Ubuntu 24.04

    This guide walks through deploying a self-hosted AI assistant platform on an Ubuntu 24.04 server, from preparing the Node.js runtime and installing the platform to configuring an OpenAI-compatible model provider, running it as a systemd service, and accessing the admin console securely through an SSH tunnel. It also covers common troubleshooting scenarios and baseline security practices such as least privilege, key isolation, loopback-only binding, and encrypted tunneling.

    1. Background and Approach

    Self-hosted AI assistant platforms are becoming an important option for organizations that want to build private AI capabilities. Compared with using closed services on public clouds, a self-hosted setup keeps model API credentials, conversation history, and business context inside servers you control, which helps meet data compliance and audit requirements. It also lets you swap the backend inference endpoint, so you can switch between model providers flexibly instead of being locked into a single interface.

    A typical self-hosted AI assistant platform has three layers. The first is the model access layer, which connects to external large model inference services through standard HTTP interfaces. The second is the orchestration and session layer, which handles multi-turn context management, tool calls, prompt templates, and task scheduling. The third is the interaction layer, which provides a web console, terminal interaction, and extensible message channel adapters.

    This article uses an Ubuntu 24.04 server as an example and lays out a path from scratch: prepare the runtime environment, install the platform, configure the model provider and key, securely access the admin interface through an encrypted tunnel, and troubleshoot common issues. It does not cover any specific vendor product. For model access, it describes a general “inference service with an OpenAI-style compatible API.”

    2. Prerequisites

    Before you start, confirm the following to avoid rework later.

    • A server running Ubuntu 24.04 with at least 2 cores and 4GB of RAM. This article uses the root user for demonstration; in production, create a regular user and configure sudo.
    • An available model inference endpoint and access key. Most mainstream model providers offer interfaces that follow common calling conventions. Keys are usually identified by an sk- prefix and can be created from the console after registration. Many platforms offer some free quota for individual developers.
    • A local computer that can connect to the server over SSH; any operating system works.
    • Normal outbound network access from the server, able to reach software repositories and model service domains. If you are on a restricted network, configure a proxy in advance.

    Note that the key is a highly sensitive credential. Create a key dedicated to this platform, set a quota limit and a call allowlist, and never commit it to a code repository or write it to logs.

    3. Step 1: Prepare the Node.js Runtime

    Most self-hosted assistant platforms are built on Node.js. The Node.js version in the official Ubuntu 24.04 repositories is relatively conservative, and some dependencies require a newer major version. It is therefore recommended to install the current LTS version through a version manager, which also makes it easy to keep multiple versions side by side and upgrade quickly.

    1. # Install the version manager
    2. curl -o- https://example.org/nvm-install.sh | bash
    3. source ~/.bashrc
    4. # Install and set the default version
    5. nvm install 22
    6. nvm alias default 22
    7. # Verify
    8. node --version # expect v22.x.x
    9. npm --version

    If the server cannot reach the external script URL, switch to an offline install: download the Node.js binary package for the target platform on a connected machine, upload it, extract it to /usr/local, and configure the PATH environment variable manually. This approach is more reliable in isolated networks and makes it easier to keep versions consistent across multiple nodes.

    After installation, run a global configuration step that points npm’s global directory to your user directory, which avoids permission and leftover-directory issues later:

    1. npm config set prefix ~/.npm-global
    2. export PATH=~/.npm-global/bin:$PATH # add to ~/.bashrc to persist

    4. Step 2: Install the Platform

    Once the runtime is ready, install the platform globally through npm:

    1. npm install -g openclaw@latest
    2. openclaw --version

    deprecated notices during installation are normal warnings from upstream dependencies and do not affect functionality. However, an error such as ENOTEMPTY usually means a previous installation left an incomplete directory. Clean up the leftovers and cache, then reinstall:

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

    In production, containerized deployment is preferred: package the runtime and platform code into an image, and use a container platform or orchestration system for automatic restart, centralized log collection, and version rollback. Containerization also lets you inject configuration through environment variables or mounted config files, keeping keys out of image layers.

    5. Step 3: Configure the Model Provider

    The platform generally provides an interactive configuration wizard to bind the provider, endpoint, and key:

    1. openclaw config

    Follow the prompts to select “Add custom provider,” enter a custom name (such as custom-provider), set the base URL to the v1 path that follows common calling conventions provided by the service (in the form https://<provider-domain>/v1), and paste the access key. Then specify the default model identifier, for example a lightweight “Flash” type model. Such models respond quickly and cost less, making them suitable as the default model for conversation and tool calls.

    After configuration, the config file is usually located in a hidden directory under the user’s home directory, with a structure roughly like this (illustrative):

    1. {
    2. "providers": {
    3. "custom-provider": {
    4. "baseURL": "https://<provider-domain>/v1",
    5. "apiKey": "sk-********"
    6. }
    7. },
    8. "defaultModel": "custom-provider/<model-name>"
    9. }

    Set strict permissions on this file so only the current user can read and write it:

    1. chmod 600 ~/.config/openclaw/config.json

    To switch providers later, simply add another provider entry and change defaultModel; there is no need to reinstall the platform. This “compatible interface plus configuration-driven” design is key to keeping a self-built setup portable.

    6. Step 4: Run as a Persistent Service

    Starting the process in the foreground means it terminates as soon as the SSH session ends. Use systemd to manage it for auto-start on boot and restart on failure:

    1. # /etc/systemd/system/openclaw.service
    2. [Unit]
    3. Description=Self-hosted AI Assistant
    4. After=network.target
    5. [Service]
    6. Type=simple
    7. User=deploy
    8. Environment=NODE_ENV=production
    9. ExecStart=/home/deploy/.npm-global/bin/openclaw serve --host 127.0.0.1 --port 8080
    10. Restart=on-failure
    11. RestartSec=5
    12. [Install]
    13. WantedBy=multi-user.target
    1. systemctl daemon-reload
    2. systemctl enable --now openclaw
    3. journalctl -u openclaw -f

    Bind the listening address to 127.0.0.1 and do not expose it directly to the public internet. If the admin interface has no strong authentication or transport encryption, exposing it publicly puts keys and conversation data at risk.

    7. Step 5: Access Securely via an SSH Tunnel

    Set up port forwarding in your local terminal to map the remote loopback port to your local machine:

    1. ssh -N -L 8080:127.0.0.1:8080 deploy@<server-address>

    Then open http://127.0.0.1:8080 in your local browser to reach the console. Compared with opening a security group port, the tunnel adds no new external exposure and reuses SSH’s strong encryption and key-based authentication.

    For multiple team members, the options include deploying a reverse proxy on the server with TLS and unified identity authentication; placing the console behind a zero-trust access proxy; or using a private network solution such as WireGuard so that only internal access is allowed.

    8. Common Issues and Troubleshooting

    • Installation fails with a non-empty directory error: clean the global modules directory and the npm cache, then reinstall.
    • Model calls return an authentication failure: confirm the key has not expired or exceeded its quota, and check whether /v1 is missing from the baseURL.
    • Requests time out or the connection resets: this is usually restricted outbound access; check proxy settings and DNS resolution.
    • The service exits immediately after starting: check the journalctl logs; it is usually a port conflict or a file permission or format problem.
    • An overly long context causes errors: shorten the history window or switch to a model with a larger context window.

    9. Summary

    The value of a self-hosted AI assistant platform lies in control and replaceability: data stays on your own servers, the model interface is accessed through a standard protocol, and the interaction layer can be extended as needed. The path described here follows five stages: runtime, platform, model, persistent service, and secure access. Least privilege, key isolation, loopback-only binding, and encrypted tunneling are baseline practices that no self-built deployment should skip.