Self-Hosted AI Assistant on Ubuntu 24.04: A Practical Guide to Deploying the Platform and Connecting LLM Services

    This guide walks through deploying a self-hosted AI assistant platform on Ubuntu 24.04 and connecting it to an external LLM service. It covers the four-layer architecture, preparation requirements, Node.js runtime setup, platform installation, model provider configuration, secure access to the web console via an SSH tunnel, and operational practices such as process supervision, secret management, and upgrades. The model backend is treated as a replaceable capability, so the instructions apply to any compatible HTTP API provider.

    1. Background and Overall Approach

    As large language models mature, more developers and organizations want to run AI assistants on their own servers instead of relying entirely on hosted services. Self-hosting offers three core benefits: control over where data flows, auditable interaction paths, and customizable extensibility. Conversation history, knowledge documents, and call logs can stay inside your own infrastructure, while the backend model service can be swapped on demand.

    A typical self-hosted AI assistant platform consists of four layers:

    1. Runtime layer: Provides the JavaScript runtime and package management that the platform processes depend on.
    2. Platform layer: Handles session management, plugin loading, multi-channel message adapters, and web console rendering.
    3. Model integration layer: Connects to external LLM services through a common HTTP interface, authenticated with an API key.
    4. Access layer: Includes the local terminal interface, browser console, and adapters for various instant messaging channels.

    This guide uses an Ubuntu 24.04 server as the example and explains how to build the stack layer by layer, then point the backend model at an LLM API service offered by a cloud vendor or platform. The provider and model are described generically (a common “provider name + model version” pattern in the industry) and can be freely replaced. The model service is simply a replaceable capability backend; the platform itself is not tied to any specific vendor.

    2. Preparation Checklist

    Before starting, confirm the following:

    • Server: A cloud host or physical machine running Ubuntu 24.04, with 2 cores and 4 GB of RAM as a starting point. If you operate as root, create a regular user and configure sudo privileges afterward to avoid running services with high privileges long term.
    • Model service credentials: Register an account on an LLM service platform and create an API key (usually prefixed with sk-). Free quotas during personal trials are generally enough to validate functionality, but production use requires attention to quotas and rate-limiting policies.
    • Local terminal: Windows, macOS, or Linux all work, as long as you can log in to the server over SSH.
    • Network and ports: Confirm the server can reach the model service’s HTTPS endpoint outbound; open only the SSH port inbound and access everything else through a tunnel to reduce exposure.

    3. Step 1: Prepare the Node.js Runtime

    The Node.js version in Ubuntu 24.04’s default repositories is relatively old, and some newer platform releases may require a higher major version. The recommended approach is to install the latest LTS release with a version manager, which allows multiple versions to coexist and rollback at any time.

    1. # Install the version manager script (example version; adjust as needed)
    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. # Verify
    8. node --version # expected output v22.x.x
    9. npm --version

    If the server cannot reach the script URL above, fall back to the system package manager, or extract the official prebuilt binaries into /usr/local and configure PATH manually. Either way, run node -v and npm -v after installation to confirm they work.

    4. Step 2: Install the Self-Hosted AI Assistant Platform

    With the runtime in place, install globally through the package manager. A global install writes the command into a user-level or system-level prefix directory, so make sure that directory is on PATH.

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

    Common installation issues and troubleshooting

    • Directory not empty errors (ENOTEMPTY): Usually caused by leftovers from a previous installation. Remove the same-named folder under the global modules directory, force-refresh the cache, and retry.
    1. rm -rf /root/.npm-global/lib/node_modules/openclaw
    2. npm cache clean --force
    3. npm install -g openclaw@latest
    • Insufficient permissions (EACCES): Avoid casually using sudo npm for global installs. A better approach is to configure a dedicated global prefix directory for the current user and add it to PATH, eliminating permission problems at the source.
    • Many deprecated warnings: These are normal notices during dependency resolution, do not affect functionality, and can be ignored.
    • Slow installation or timeouts: Switch to a general-purpose mirror registry or increase the network timeout, then switch back to the default registry after installation.

    5. Step 3: Connect the LLM Service

    The platform usually provides an interactive configuration wizard for registering a custom model provider. The core is three elements: base URL, auth key, and model identifier.

    1. openclaw config

    Follow the prompts to complete the following:

    1. Select “Add custom provider”.
    2. Enter a provider name, for example zhipu (an identifier only; any name works).
    3. Enter the base URL, in the form https://open.bigmodel.cn/api/paas/v4 (paths differ across platforms; follow the provider’s documentation).
    4. Paste the API key.
    5. Enter the model identifier, for example the name of a vendor’s Flash-series lightweight model.
    6. Save and select it as the default model.

    After configuration, the config file is generally located in a hidden config directory under the user’s home directory. Tighten its permissions to read-only for the owner to prevent key leakage:

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

    General design principles of the integration layer

    Self-hosted platforms can “swap models without changing architecture” because they follow the industry’s common compatible HTTP calling convention: a unified request body structure, a unified auth header, and a unified streaming response format. As long as the target service is compatible with this convention, you can connect it by filling in the base URL and key, with no platform code changes. This also means you can configure multiple providers for different scenarios, for example a lightweight, low-latency model for daily conversation and a more capable model for complex reasoning.

    6. Step 4: Securely Access the Web Console

    After the platform starts the web service, do not expose the port directly to the public internet. A safer approach is to listen only on the loopback address and map it to your local browser through an SSH tunnel.

    1. # Server side: listen on localhost only
    2. openclaw web --host 127.0.0.1 --port 8080
    3. # Local side: establish an encrypted tunnel
    4. ssh -N -L 8080:127.0.0.1:8080 user@your-server-ip

    Then open http://127.0.0.1:8080 in your local browser. The advantages are fully encrypted traffic, no extra firewall ports to open, and no certificates to configure.

    If multi-user collaboration is genuinely needed, add a reverse proxy and access control on top, and prefer the platform’s built-in authentication rather than simply opening the port.

    7. Process Supervision and Operations

    • Persistent running: Write a unit file with the system service manager and set Restart=always for auto-start on boot and recovery after crashes.
    • Logging and monitoring: Pipe standard output into a logging service, and use monitoring and alerting to observe process liveness and API error rates.
    • Secret management: Inject keys through environment variables or a permission-restricted config file; never commit them to a code repository.
    • Upgrade strategy: Back up the config directory before upgrading, and validate compatibility of the new version on a test instance first.
    • Resource control: Set memory and CPU limits for the service to prevent abnormal sessions from bringing down the whole machine.

    8. Summary

    Getting a self-hosted AI assistant running on Ubuntu 24.04 comes down to four steps: prepare the runtime, install the platform, connect the model, and access it securely. The real engineering challenges are not the installation commands but the long-term operational details: least privilege, key protection, process supervision, and observability. Treat the model service as a pluggable backend capability and the platform as your own interaction and data hub, and you get a flexible and secure dedicated AI assistant at a controllable cost.