Deploy an AI Coding Assistant on Ubuntu 24.04: A Complete Practical Guide
This guide walks through deploying a self-hosted AI coding assistant on an Ubuntu 24.04 server. It covers setting up a reliable Node.js environment with nvm, installing the tool globally via npm, resolving common installation errors, connecting an OpenAI-compatible LLM provider, and securely accessing the web interface through SSH local port forwarding. You will also find troubleshooting tips and cost-control recommendations.
1. Background and Overall Approach
As large language models are increasingly used for code generation, code explanation, and unit test writing, more development teams want to deploy a controllable AI coding assistant on their own servers. Compared with using public online services directly, a self-hosted deployment offers clear advantages in data isolation, access auditing, and internal network integration.
This article uses a cloud server running Ubuntu 24.04 as the base and demonstrates the full process of installing an open-source-style AI coding tool (referred to below as the “AI coding tool”), connecting it to an LLM service that is compatible with the OpenAI API specification, and safely using its web interface in a local browser through SSH port forwarding.
The overall solution has four layers:
- Runtime layer: Prepare the Node.js runtime, preferably installed with a version manager rather than the system package manager.
- Installation layer: Install the AI coding tool globally through the package manager and handle anomalies caused by installation leftovers.
- Model integration layer: Connect a general-purpose LLM API with free quota by adding a custom model provider.
- Secure access layer: Avoid exposing the web port directly and use SSH local forwarding for access.
Prerequisites include: an Ubuntu 24.04 server (the example uses the root user; in production, create a regular user and configure sudo privileges); an API key for an OpenAI-compatible LLM service (usually available with a free quota after registration on a model platform); and a local computer that can connect to the server over SSH, with any operating system.
2. Step 1: Build a Reliable Node.js Runtime
AI coding tools are typically built on the Node.js ecosystem, but the Node.js version in the official Ubuntu 24.04 repositories is relatively conservative and may be lower than the tool’s minimum requirement, leading to dependency installation failures or runtime errors. A more reliable approach is to use nvm (Node Version Manager) to manage multiple Node.js versions under the user directory, avoiding changes to the system environment and making future upgrades and rollbacks easier.
Example commands:
# Install the version managercurl -o- https://<version-manager-install-url> | bashsource ~/.bashrc# Install and switch to the 22 LTS releasenvm install 22nvm alias default 22# Verifynode --version # expected output: v22.x.xnpm --version
There are three practical points here. First, nvm alias default determines the version used by default in new login sessions; without this step, the node command will not be found after reconnecting over SSH. Second, after the install script finishes, you must reload the shell configuration (source ~/.bashrc or log in again), otherwise the current session will not recognize the nvm command. Third, if the server is on an internal network or has restricted external access, configure an npm mirror registry in advance to speed up dependency downloads:
npm config set registry https://<mirror-registry-url>npm config get registry
3. Step 2: Install the AI Coding Tool and Handle Common Errors
Once the runtime is ready, install the tool globally with npm:
npm install -g openclaw@latest
After installation, verify the version first:
openclaw --version # expected output: a version number like 2026.3.2
The most common error in practice is ENOTEMPTY. The root cause is that a previous installation or upgrade was interrupted, leaving incomplete files in the global modules directory that npm cannot overwrite. The fix follows three steps: clean up leftovers, reset the cache, and reinstall:
rm -rf /root/.npm-global/lib/node_modules/openclawnpm cache clean --forcenpm install -g openclaw@latest
If you set a custom global install prefix, replace the path with the actual prefix directory. In addition, deprecated warnings in the installation log are normal messages from transitive dependencies and can be ignored as long as the version check passes. However, if an EACCES permission error appears, the ownership of the global directory is incorrect; fix the directory ownership or switch to a user-level prefix instead of relying on root privileges.
4. Step 3: Connect a General-Purpose LLM Service
The tool itself is only a shell; the real capability comes from the backend model. Most AI coding tools support custom model providers, so as long as the target service is compatible with the OpenAI Chat Completions API specification, you can connect it by entering the base URL and API key.
Start the interactive configuration wizard:
openclaw config
Follow the prompts to complete the following steps:
- Select “Add custom provider”.
- Enter a provider identifier, for example
zhipu; this name is only used for local distinction. - Enter the API base URL, in the form
https://<platform-domain>/api/paas/v4. - Paste the API key starting with
sk-. - Select the model identifier and enter the name of the lightweight model offered by the platform.
- Save and set this model as the default.
After configuration, you can check the key fields in the configuration file to detect any abnormal writes from the wizard:
{"provider": "custom","baseURL": "https://<platform-domain>/api/paas/v4","apiKey": "sk-***","model": "<lightweight-model-id>"}
Security recommendation: the API key is a sensitive credential. Set the file permission to chmod 600 and never commit it to a code repository. If the server is shared by multiple people, create a separate account and a separate key for each person to make usage tracking and revocation easier.
5. Step 4: Securely Access the Web Interface via SSH Port Forwarding
After startup, the tool listens on a local port by default (for example, 3000). Exposing this port to the public internet creates a risk of unauthorized access. The correct approach is to use SSH local forwarding to map the remote port to your local machine:
ssh -L 3000:127.0.0.1:3000 root@<server-ip>
Then open http://127.0.0.1:3000 in your local browser. If you want it to run in the background long term, combine it with a process supervisor:
nohup openclaw web --host 127.0.0.1 --port 3000 > /var/log/openclaw.log 2>&1 &
Optional hardening measures include: disable password login and switch to key-based authentication; allow only the SSH port in the firewall; and set ServerAliveInterval for forwarding sessions to prevent idle disconnects.
6. Troubleshooting and Tuning Tips
- The model returns 401: the key is wrong or not active; regenerate it and confirm the account is verified.
- Slow responses: lightweight models are better suited for high-frequency calls such as code completion; switch to a larger model for complex reasoning.
- Fails to start after an upgrade: back up the configuration file first, then clean the global modules directory and reinstall.
- Cost control: set usage alerts for the team to avoid charges from abnormal repeated calls.
At this point, you have completed the full setup on Ubuntu 24.04, from building the environment and installing the tool to connecting the model and enabling secure access, giving you a dedicated AI coding assistant with controllable data and restricted access.
