Deploy an AI Coding Assistant on Ubuntu 24.04: A Complete Practical Guide

    This guide walks through deploying an open-source-style AI coding assistant CLI on an Ubuntu 24.04 server, connecting it to an OpenAI-compatible large model inference API, and securely exposing the web interface through SSH port forwarding. It covers runtime preparation, installation, provider and API key configuration, access hardening, and common troubleshooting tips.

    1. Background and Overall Approach

    More and more teams want to bring large language model capabilities into their own server environments for code completion, script generation, log analysis, and documentation writing. Compared with using a ready-made public service, self-hosting offers three advantages: network egress stays under your control, so sensitive code never has to leave the internal network; the model provider and parameters can be swapped as needed, avoiding lock-in to a single vendor; and auditing, rate limiting, and cost accounting are easier to standardize.

    This article uses a server running Ubuntu 24.04 as an example to show how to deploy an open-source-style AI coding assistant CLI, point its chat backend at a cloud vendor’s large model inference service, and finally map the web interface to your local machine securely over SSH port forwarding. The overall approach has five layers:

    • Runtime layer: a Node.js long-term support (LTS) release and a package manager;
    • Tool layer: the globally installed assistant CLI;
    • Model layer: a large model API compatible with the OpenAI-style protocol;
    • Integration layer: provider configuration and API key injection;
    • Access layer: an SSH tunnel and the principle of minimal exposure.

    Note that the commands here are demonstrated as the root user, but in production you should create a regular user and configure sudo permissions immediately, rather than running a network service with superuser privileges for the long term.

    2. Environment Preparation and Pre-checks

    The Node.js version in the default Ubuntu 24.04 repositories is usually older, while most modern CLI tools require a newer LTS release. Installing through a version manager is the more reliable approach: it does not pollute system directories and makes it easy to keep multiple versions side by side and roll back quickly.

    1. # Install dependencies
    2. apt update && apt install -y curl git build-essential
    3. # Install Node.js 22 LTS via a version manager
    4. curl -o- https://<version-manager-official-install-script> | bash
    5. source ~/.bashrc
    6. nvm install 22
    7. nvm alias default 22
    8. node --version # expect v22.x.x
    9. npm --version

    The pre-checks should cover four things: available disk space (dependency packages and caches typically take up hundreds of MB), available memory (several GB or more if you run an inference model locally), outbound connectivity (whether you can reach the model service domain and package repositories), and the system time zone and time synchronization. If the clock is out of sync, request signature validation fails, which is an easily overlooked step when troubleshooting 401 errors.

    3. Installing the AI Coding Assistant CLI

    Once the runtime is confirmed, install the tool itself globally. To avoid permission and directory conflicts, set a global install prefix first:

    1. npm config set prefix ~/.npm-global
    2. export PATH=~/.npm-global/bin:$PATH # consider adding this to ~/.bashrc
    3. npm install -g assistant-cli@latest

    If you hit a non-empty directory error (ENOTEMPTY), it usually means the previous installation left residual files behind. Clear the cache and module directory, then retry:

    1. rm -rf ~/.npm-global/lib/node_modules/<assistant-directory-name>
    2. npm cache clean --force
    3. npm install -g assistant-cli@latest

    The deprecated notices that appear during installation are normal warnings from upstream dependencies and do not affect functionality. What really matters is the audit vulnerability summary at the end of the installation; you can record it first and evaluate it later. After installation, check the version and run a self-check:

    1. assistant-cli --version # output looks like 2026.x.y
    2. assistant-cli doctor # run this first if the tool provides a self-check subcommand

    4. Connecting to a Protocol-compatible Large Model Service

    These tools generally support a “custom provider” mechanism. As long as the target service is compatible with the OpenAI-style Chat Completions protocol, you can connect it by filling in the Base URL, model name, and key. Using a cloud vendor’s large model inference service as an example, the interactive configuration flow is:

    1. assistant-cli config

    Follow the prompts to add a custom provider, then enter:

    • Provider name: a custom identifier, for example custom-cloud;
    • API address: the service’s public v1-compatible endpoint (in the form https://…/api/paas/v4);
    • API Key: a key string starting with sk-;
    • Model identifier: the model code given in the service documentation;
    • Context length and temperature: start with conservative values, then tune based on actual results.

    The key design point is the “protocol compatibility layer” rather than any single vendor: as long as the same request and response structure is followed, switching providers usually only requires changing the Base URL and model name. So it is recommended to keep the key in an environment variable instead of writing it in plaintext into a config file:

    1. export LLM_API_KEY="sk-your-key"
    2. chmod 600 ~/.config/assistant/config.json

    There are three practical rules for key management: first, least privilege — request separate keys for different environments and set spending limits; second, rotation — replace keys regularly and keep a revocation path; third, zero hardcoding — never commit keys into version control, and use ignore rules at the repository root as a fallback. If several people on a team share keys, a better approach is to store the keys in a key management service or in encrypted CI variables and inject them at runtime.

    After configuration, run a minimal verification to confirm the pipeline works:

    1. assistant-cli chat "Explain idempotency in one sentence"

    If authentication fails, first check whether the key has extra whitespace, whether the Base URL duplicates the version path, and whether the server’s egress IP is on the allow list.

    5. Securely Accessing the Interface via SSH Port Forwarding

    The web interface listens on the server’s local loopback address by default. Exposing it directly to the public internet creates a risk of unauthorized access. The recommended approach is to keep the default binding and map the port to your local machine through an SSH tunnel:

    1. ssh -N -L 3000:127.0.0.1:3000 user@server-address

    Then open the local loopback address in your local browser. If you need the interface to run in the background for a long time, let a process supervisor manage the interface process and set it to start on boot with systemd; on the tunnel side, you can use a solution like autossh to keep it alive. Security hardening recommendations include: disable password login and switch to key-based authentication, restrict SSH to a fixed network range, enable login authentication for the interface itself, and record and alert on abnormal access through log services and monitoring alerts.

    6. Common Issues and Tuning Tips

    • Version mismatch: CLI errors are often caused by a runtime version that is too old; pinning an LTS release resolves it;
    • Installation leftovers: clear the module directory and cache, then reinstall;
    • Call timeouts: distinguish whether it is a network egress issue or model-side rate limiting; look at the response code first, then the latency;
    • Context overflow: shorten the message history or reduce the maximum output length;
    • Cost overruns: set spending alerts and add local caching for high-frequency calls.

    In summary, from runtime preparation to secure access, the core of a self-hosted AI coding assistant does not depend on any particular product, but on three general engineering capabilities: “protocol-compatible model integration + strict key governance + minimally exposed access.” Once you master this methodology, you can use any compliant cloud platform, such as Baidu AI Cloud, to store configuration backups in object storage, use a log service for auditing, and use monitoring alerts to guard cost boundaries, quickly replicating a stable and controllable private AI development environment.