Deploy an AI Coding Assistant on Ubuntu 24.04: Connecting to a Cloud LLM API

    This guide walks through deploying an AI coding assistant on an Ubuntu 24.04 server and connecting it to a cloud-hosted large language model. It covers why separating the tool layer from the model layer is practical, the prerequisites you need, installing a Node.js runtime with a version manager, globally installing the tool and clearing leftover conflicts, using the interactive wizard to register an OpenAI-compatible provider, layered connectivity testing, a troubleshooting table, and production hardening advice on identity, secret management, process supervision, observability, cost control, and portability.

    Deploy an AI Coding Assistant on Ubuntu 24.04: Connecting to a Cloud LLM API

    1. Why Pair a Self-Hosted Tool with a Cloud Model

    Over the past two years, AI coding assistants have evolved from simple code-completion plugins into development partners capable of context understanding, multi-turn conversation, script generation, and repository-level Q&A. Many teams want to deploy the tool side on their own servers while offloading model inference to a general-purpose cloud LLM service. This split delivers three immediate benefits:

    1. Controlled environment: The tool runs on machines the team owns, so configuration, logs, and keys stay inside internal assets and remain easy to audit.
    2. Replaceable model: The model service exposes its capabilities through a standard HTTP interface, so switching providers or model versions requires almost no changes on the tool side.
    3. Elastic cost: Individual developers can validate with a provider’s free tier, and teams can scale up gradually based on call volume.

    The key point is that the tool side handles “interaction and orchestration” while the model side handles “understanding and generation,” and the two are decoupled through a unified interface protocol. Once this is clear, the configuration steps below stop being isolated commands and become one coherent data flow.

    2. Prerequisites Checklist

    Before you start, confirm each of the following to avoid rework midway:

    • Server: An instance running Ubuntu 24.04. This article uses the root user for demonstration; in production, create a regular user and set up key-based login immediately.
    • Model service credentials: Register an account on a large-model open platform and create an API Key. The free tier is usually enough for individual validation.
    • Local terminal: Windows, macOS, and Linux all work, as long as you can connect to the server over SSH.
    • Runtime environment: The tool runs on Node.js. The Node.js version in the official Ubuntu 24.04 repositories is relatively old and tends to trigger engine-version mismatch warnings, so installing the current LTS release through a version manager is recommended.
    • Network and egress policy: Confirm the server can reach the model service’s public address. If it sits in an internal network, open the outbound rules or configure a proxy in advance.

    3. Step 1: Prepare the Node.js Runtime with a Version Manager

    Installing the runtime straight from the distribution repositories looks convenient, but it is a common source of later failures: global package directory permissions, version switching, and dependency compilation all become awkward when the version is too old. A more reliable approach is to introduce a version manager such as nvm and install the runtime under the user’s home directory.

    1. # Install the version manager
    2. curl -o- https://<version-manager-official-install-script> | bash
    3. source ~/.bashrc
    4. # Install and pin the LTS version
    5. nvm install 22
    6. nvm alias default 22
    7. # Verify
    8. node --version # expect v22.x.x
    9. npm --version

    A few practical points:

    • Pin the default version with nvm alias default. Otherwise, a newly opened SSH session may still point to the old version, causing the confusing situation where “it works when run manually but fails in a script.”
    • Do not mix root and sudo when installing global packages. The version manager already points the prefix to the user directory; adding sudo on top creates ownership confusion in those directories, a common trigger for ENOTEMPTY-type errors.
    • In CI or containers, write the version declaration into .nvmrc to keep local and pipeline environments consistent.

    4. Step 2: Install the Tool Globally and Clear Leftover Conflicts

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

    1. npm install -g openclaw@latest

    If it fails with a directory-not-empty error (ENOTEMPTY), a half-finished directory was left behind by a previous install. The cleanup approach is “remove leftovers first, clear the cache next, then reinstall”:

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

    Additional notes:

    • A deprecated notice in the install log is normal noise from the transitive dependency chain and does not mean the current package is unusable. Judge success by the exit code and the final version output.
    • If a restricted network interrupts the download, switch to a mirror and retry, and make sure the install runs in only one terminal to avoid concurrent writes to the same directory.
    • Verify immediately after installation:
    1. openclaw --version # outputs a version like 2026.3.2

    Record the version number. When troubleshooting later, the three elements “version + time + action” dramatically shorten the time to pinpoint a problem.

    5. Step 3: Connect a General-Purpose LLM via the Interactive Wizard

    The tool usually ships with a configuration wizard, which is less error-prone than hand-writing a config file:

    1. openclaw config

    Follow the prompts in order:

    1. Choose “add a custom provider.”
    2. Enter the provider identifier, for example zhipu.
    3. Enter the base URL, i.e., the OpenAI-compatible gateway address exposed by the model service.
    4. Paste the API Key that starts with sk-.
    5. Specify the model name (for example, a vendor’s lightweight Flash-series model) and save.

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

    1. {
    2. "providers": {
    3. "zhipu": {
    4. "baseURL": "https://<model-service-address>/api/paas/v4",
    5. "apiKey": "sk-********"
    6. }
    7. },
    8. "model": "glm-4.7-flash"
    9. }

    Security reminder: An API Key is equivalent to an account password. Be sure to set chmod 600 on the config file, never commit it to a code repository, and never expose it in shared screenshots. For team scenarios, issue a separate Key per member to make per-person auditing and revocation easy.

    6. Step 4: Connectivity Verification and a Minimal Working Test

    A finished configuration does not mean the setup is usable. Three layers of verification are recommended:

    • Credential layer: Call a model-list or minimal chat endpoint once and confirm it returns 200 rather than 401/403.
    • Tool layer: Start a single-turn Q&A inside the tool and observe whether streaming output and latency statistics appear.
    • Scenario layer: Have it read a small function and explain the logic to check that context assembly works correctly.

    An illustrative connectivity check (using curl against the compatible endpoint):

    1. curl https://<model-service-address>/api/paas/v4/chat/completions \
    2. -H "Authorization: Bearer $API_KEY" \
    3. -H "Content-Type: application/json" \
    4. -d '{"model":"glm-4.7-flash","messages":[{"role":"user","content":"ping"}]}'

    If authentication fails, first check whether the Key is truncated or contains extra spaces; if the model is reported as nonexistent, check the model-name spelling and the account’s available scope.

    7. Common Failures and Troubleshooting Order

    Symptom Likely cause Suggested fix
    Global install reports directory not empty Leftovers from a previous install Remove the leftover directory, clear the cache, then reinstall
    Command not found Default version not pinned or PATH not refreshed Run nvm alias default and reopen the terminal
    401/403 Invalid Key or insufficient permissions Reissue the Key and verify account status
    Request timeout Missing egress policy or proxy Open the domain or configure a proxy
    Output truncated Context/max-generation length set too low Adjust session parameters and retry

    When troubleshooting, follow “layered elimination”: runtime first, then the tool, then the network, and finally the model service, narrowing the scope layer by layer. This is far more efficient than blindly reinstalling.

    8. Production Hardening Recommendations

    Going from “it runs” to “it works well” requires a few more engineering capabilities:

    • Identity and permissions: Disable direct root login, switch to a regular user with key authentication, and use a firewall to restrict source network ranges.
    • Secret management: Put the Key into environment variables or a secret-management service instead of hardcoding it, and rotate it regularly.
    • Process supervision: Use systemd to manage long-running processes, with automatic restart and log rotation configured.
    • Observability: Connect a general-purpose logging service and monitoring/alerting, and set thresholds for call volume, error rate, and time-to-first-token latency.
    • Cost governance: Set quotas and rate limits at the gateway to prevent abnormal looping calls from inflating the bill.
    • Portability: Keep the runtime version, dependency manifest, and configuration templates under version control to guarantee one-command rebuilds.

    9. Summary

    Deploying an AI coding assistant on Ubuntu 24.04 and connecting it to a cloud LLM is not complicated at its core: pin the runtime with a version manager, obtain the tool via a global install, complete the model connection with the interactive wizard, and confirm the pipeline works with layered verification. What truly determines the long-term experience is the “invisible” engineering detail of secret management, permission reduction, and observability. Turn this workflow into a standard operating runbook for the team, and a new member can usually go from zero to usable in a dozen minutes, while 90% of later problems can be quickly narrowed down through version records and layered troubleshooting.