Deploy an AI Coding Agent on Ubuntu 24.04: A Complete Practical Guide
This guide walks through deploying an AI coding agent on an Ubuntu 24.04 server, from preparing the Node.js runtime with a version manager to connecting an external LLM provider, accessing the web UI securely over an SSH tunnel, and troubleshooting common errors. It also covers API key handling and when to choose lightweight versus more capable models.
1. Why Self-Host an AI Coding Agent
Over the past couple of years, LLM-based coding tools have evolved from simple code-completion plugins into automation agents capable of reading and writing files, executing commands, and planning multi-step tasks. Their core value is no longer limited to offering passive snippets: they can understand a repository’s structure, locate relevant files, run a sequence of steps, and verify their own results.
Public hosted services, however, come with practical constraints. Code has to be uploaded to a third-party environment, internal corporate material may not be allowed to leave the network, and personal debugging scripts are not something you want sitting indefinitely on a machine you do not control. Self-hosting the tool on your own server is essentially about decoupling the execution environment from model capability: execution happens on a machine you fully control, while model inference is called through a standard interface to an external service. This architecture keeps model improvements flowing in while sensitive code stays local.
One note up front: this walkthrough uses a server running Ubuntu 24.04, and the root account is used purely for demonstration convenience. In production, create a dedicated non-privileged user and grant minimal permissions through sudo.
2. Prerequisites Checklist
Before starting, confirm four things:
- Server environment: Ubuntu 24.04, working internet access, and basic SSH login capability.
- Model service credentials: Register an account on a model service platform and create an API key. Most platforms offer some free quota, which is usually enough for everyday individual use; refer to the official documentation of the platform you choose for exact quotas and billing rules.
- Local terminal: Windows, macOS, and Linux all work; you only need a usable SSH client.
- Runtime environment: These tools are generally built on Node.js, and the version in distribution default repositories is often outdated, which tends to cause dependency incompatibility. Installing a newer LTS release through a version management tool is recommended.
The last point deserves elaboration. The Node.js version in the official Ubuntu 24.04 repositories is relatively conservative, an inevitable result of the distribution’s focus on stability, but not friendly to newer toolchains. A version manager such as nvm installs into the current user’s home directory, leaves the system package manager untouched, and lets you switch between versions at any time, making rollbacks easy when something breaks.
3. Step 1: Prepare the Node.js Runtime
The recommended approach is to install the Node.js LTS release through a version manager script:
# Install the version managercurl -o- https://<version-manager-install-script-url> | bashsource ~/.bashrc# Install and set as defaultnvm install 22nvm alias default 22# Verifynode --version # expect v22.x.xnpm --version
A few details that commonly trip people up:
- After the install script finishes, you must reload the shell configuration (
source ~/.bashrcor log in again), otherwise thenvmcommand will not be recognized. - If Node.js was previously installed via the system package manager, uninstall it first to avoid two versions competing on PATH.
nvmis a user-level tool, so after switching users you need to runnvm useagain. This is also why creating a regular user and configuring it once more was recommended earlier.
4. Step 2: Install the AI Coding Agent
Once the runtime is ready, install globally through npm:
npm install -g openclaw@latestopenclaw --version
If permissions on the global install directory or leftover files cause a failure, the typical error is a directory-not-empty exception (for example, ENOTEMPTY). This usually means a previous install was interrupted and left incomplete files behind. The fix is to clean up leftovers, clear the cache, then reinstall:
rm -rf ~/.npm-global/lib/node_modules/<package-name>npm cache clean --forcenpm install -g <package-name>@latest
Two additional notes:
- Plenty of
deprecatedwarnings during installation are normal. They reflect the maintenance status of upstream dependencies, do not affect functionality, and do not need to be addressed one by one. - To avoid permission problems entirely, configure a user-level global directory in advance by pointing
prefixto~/.npm-globaland adding that directory’sbinto PATH. The whole installation then requires no root privileges.
5. Step 3: Connect the LLM
The tool itself is only an execution framework; the actual capability comes from the model it connects to. Configuration is usually done through an interactive wizard:
openclaw config
Follow the prompts:
- Choose “Add custom provider”.
- Enter a provider name, for example
zhipu. This name is only a local identifier referenced later in the configuration file. - Enter the base endpoint, i.e., the OpenAI-compatible service endpoint provided by the model platform (in the form
https://<platform-domain>/api/paas/v4). - Paste your API key (usually starting with
sk-). - Specify the model name, for example a lightweight model from a platform’s Flash series.
A few key concepts need to be clear, otherwise you may finish configuring and still fail to connect:
The endpoint and the model name must match as a pair. Most platforms expose endpoints compatible with the common calling convention, so the tool needs no dedicated adapter per platform. But “compatible” only guarantees identical request and response structures; the available models are still decided by the platform, and a wrong model name returns a model-not-found error directly.
API key security boundaries. Once written into a configuration file, the key is equivalent to a calling credential for that account. Recommendations: tighten the configuration file permissions to 600; never hardcode the key into project code or commit it to version control; if a leak is suspected, revoke and regenerate it on the platform immediately.
Lightweight models versus complex tasks. Flash-class models respond fast and cost little, making them suitable for file retrieval, format conversion, comment generation, and single-file edits. For cross-file refactoring and complex logical reasoning, switch to a more capable model. A common practice is to keep two model entries in the configuration and switch manually by task type rather than using one model throughout.
After configuration, run a minimal check to confirm the chain works:
openclaw config list # show the active provider and modelopenclaw run "List the current directory structure and briefly explain it" # make a real call
If this step fails authentication, first check the key for extra spaces or line breaks; if it fails with a network error, check the server’s egress policy and DNS resolution.
6. Step 4: Access the Web UI Securely
These tools usually ship with a local web interface that listens on the loopback address by default. Mapping it directly to a public port is a clear anti-pattern: the interface often lacks strong authentication, and exposing it is equivalent to handing over command execution on the server.
The correct approach is SSH local port forwarding, which pulls the remote service to your local machine:
ssh -L 8080:127.0.0.1:8080 user@your-server-ip
Then open http://127.0.0.1:8080 in your local browser. The mechanism: SSH opens a listening port locally, all traffic travels through an encrypted tunnel to the server, and the server forwards it to the service on its loopback address. Data stays encrypted, no extra firewall ports need to be opened, and no third-party tunneling service is involved.
Further hardening:
- Confirm on the server that the service binds to
127.0.0.1rather than0.0.0.0. - Switch SSH login to key-based authentication and disable password login to reduce brute-force risk.
- If multiple team members need access, prefer deploying on a cloud platform with unified identity authentication and access control, filling in auditing and observability through common capabilities such as load balancing, logging, and monitoring alerts, instead of stitching together a fragile exposure scheme yourself.
7. Quick Troubleshooting Reference
| Symptom | Common cause | How to fix |
|---|---|---|
nvm: command not found |
Shell configuration not reloaded | Re-source the configuration or log in again |
| Global install fails with directory not empty | Leftovers from a previous install | Remove the module directory, clear the cache, reinstall |
| Calls fail authentication | Key missing, contains whitespace, or expired | Regenerate and check the format |
| Calls return model not found | Model name does not match the platform | Correct it against the platform’s model list |
| Local browser cannot open the UI | Forwarded port or bind address mismatch | Check the -L argument and the service listen address |
8. Summary
Self-hosting an AI coding agent is not technically difficult to install; the difficulty lies in three engineering judgments: isolating the runtime with a version manager, abstracting model capability into a replaceable external dependency, and using an encrypted tunnel instead of public exposure. Get these three right and the environment will serve daily development reliably over the long term, and switching models or migrating machines will require only minor configuration changes rather than rebuilding the whole chain.
