Deploy a Self-Hosted AI Assistant on Ubuntu 24.04: A Step-by-Step Guide
This guide walks through deploying a self-hosted AI assistant on Ubuntu 24.04, covering runtime setup with a version manager, installing the assistant package, connecting a large language model service, securing the web console with SSH port forwarding, and running the service persistently with systemd. It also includes troubleshooting tips and a quick reference for common issues, helping you keep your data on your own infrastructure while staying free to switch model providers.
1. Why Self-Host an AI Assistant
The core value of self-hosting is a clear data boundary. Conversation content, attachments, and call logs stay on machines you control and never leave your internal network with each request. You also decide which model service to connect to and which model tier to use, without being locked into a client’s preset options. A mature self-hosted assistant typically has three layers: an interaction layer for humans (browser console, terminal interface), an access layer for channels (treating messaging apps as input/output channels), and a service layer for models (connecting to inference APIs from different vendors through a unified protocol). Understanding these three layers gives every step that follows a place to land.
The trade-off to be clear about up front: self-hosting transfers operational responsibility to you. Process supervision, version upgrades, key rotation, and disk and memory levels are all yours to manage. For a trial, a 2-core, 4 GB cloud host is enough; for long-term multi-user use, prioritize memory headroom and log growth.
2. Prerequisites Checklist
- An Ubuntu 24.04 server reachable over SSH. For production, avoid operating as root long-term; create a regular user, configure sudo and key-based login, and disable password authentication.
- A large model service credential. Register on any model provider’s open platform and create a key. Personal trials usually include free quota—watch the quota validity period and concurrency limits.
- A local terminal environment. Windows, macOS, and Linux all work; you only need an SSH client.
- A usable runtime environment. This kind of assistant is generally built on Node.js, and the version in the distribution’s default repositories is often outdated. Installing the current LTS through a version manager is recommended.
Security note: a key is a long-lived credential. Do not commit it to a code repository and do not pass it as a command-line argument (it will land in shell history and the process list). Prefer environment variables or a config file with 600 permissions.
3. Step 1: Set Up a Controllable Runtime Environment
Installing the runtime with a version manager rather than the system package manager lets you switch versions at any time, avoids polluting system directories, and prevents conflicts with system dependencies. A typical flow:
# Install the version managercurl -o- https://example.org/install.sh | bashsource ~/.bashrc# Install and set the default LTS versionnvm install 22nvm alias default 22# Verifynode --version # expect v22.x.xnpm --version
Two common pitfalls: first, before executing a script through a pipe, verify the source is trusted, and download and review it first if necessary; second, nvm takes effect by modifying shell startup files, so non-interactive sessions (some CI environments, or after sudo) may not pick it up—source it explicitly or use an absolute path in that case.
4. Step 2: Install the Assistant and Handle Common Failures
Global installation is the fastest approach:
npm install -g openclaw@latestopenclaw --version
If you want a controllable installation that is easy to roll back, set an explicit prefix directory to avoid interfering with system directories:
npm config set prefix "$HOME/.npm-global"export PATH="$HOME/.npm-global/bin:$PATH" # consider adding to ~/.bashrcnpm install -g <package>@latest
A troubleshooting approach matters more than memorizing a single command. A “directory not empty” error during global installation is essentially leftover files from a previous install blocking the overwrite. The order is: uninstall first, clean the cache, then reinstall.
npm uninstall -g <package>rm -rf ~/.npm-global/lib/node_modules/<package>npm cache clean --forcenpm install -g <package>@latest
If it still fails, check in order: whether the disk is full (df -h), whether directory ownership matches the current user (leftover root ownership is a common cause; confirm with ls -l), and whether the network can reach the mirror. Deprecation warnings during installation usually only indicate a dependency is no longer maintained and do not affect operation; but an engine version mismatch warning means the runtime version is too low—go back to Step 3 and upgrade.
5. Step 3: Connect a Large Model Service
This kind of platform usually provides an interactive configuration wizard. The goal is to give the service layer four things: protocol style, endpoint, credential, and model identifier.
openclaw config
Follow the prompts to choose “Add custom service provider,” then enter:
- Provider name: a custom identifier for local distinction only, e.g.,
custom-a. - API base URL: the API root path from the provider’s open platform. Note whether a version suffix is required, and do not add a trailing slash.
- Credential: a key string with the usual prefix.
- Model identifier: must exactly match the name in the provider’s model list—case, dots, and suffixes cannot be changed arbitrarily.
A wrong model identifier is the most frequent failure, showing up as authentication passing but a model-not-found error. Another frequent issue is a base URL that duplicates the version path, sending requests to a nonexistent endpoint. After configuring, run a minimal connectivity check before using the interface:
# Example: verify the endpoint and credential work (field names per the provider's documentation)curl -s "$BASE_URL/chat/completions" \-H "Authorization: Bearer $API_KEY" \-H "Content-Type: application/json" \-d '{"model":"<model-id>","messages":[{"role":"user","content":"ping"}]}'
If authentication fails, check whether the key is polluted by extra spaces or newlines; if the model is not found, go back to step 4; if the connection times out, check outbound network policy and security groups first rather than repeatedly changing the config.
6. Step 4: Secure Access to the Web Console
Do not expose the console directly on a public port. The console often ships without strong authentication, and exposing it is equivalent to handing your model usage quota to strangers. SSH port forwarding is recommended to map the remote port to your local loopback:
# Run locally: -L local_port:target_address:target_portssh -N -L 8080:127.0.0.1:8080 user@server-ip# Then open http://127.0.0.1:8080 in your local browser
For long-term use, add it to your local SSH config file to reduce it to a single command; on Windows, a graphical client’s tunneling feature also works. If multiple users genuinely need access, the correct approach is to put a reverse proxy in front with transport-layer encryption and authentication enabled, and restrict source network ranges—not to open a bare port.
7. Step 5: Persistent Operation and Daily Maintenance
A foreground process exits when the interactive session ends, so use process supervision:
# /etc/systemd/system/ai-assistant.service example[Unit]Description=Self-hosted AI AssistantAfter=network-online.target[Service]Type=simpleUser=appuserEnvironmentFile=/etc/ai-assistant.envExecStart=/home/appuser/.npm-global/bin/openclaw startRestart=on-failureRestartSec=5[Install]WantedBy=multi-user.target
sudo systemctl daemon-reloadsudo systemctl enable --now ai-assistantjournalctl -u ai-assistant -f # live logs
Put the key in the file referenced by EnvironmentFile, with 600 permissions and ownership set to the runtime user. Focus daily maintenance on three things: log growth (configure rotation to avoid filling the disk), memory levels (model requests are often the source of memory peaks; add swap or limit concurrency if needed), and version strategy (back up the config directory before upgrading so you can roll back quickly).
8. Common Issues Quick Reference
- The UI opens but the conversation is unresponsive: usually a credential or model identifier issue—check server logs first, then the config.
- A request hangs for a long time: determine whether outbound traffic is blocked, the provider is rate-limiting, or local resources are insufficient; rule it out layer by layer with a minimal request.
- Startup fails after an upgrade: roll back the version first and keep the old config directory, then compare config field changes one by one.
- Port forwarding stops working: confirm the remote service listens on the loopback address rather than only on the local machine, otherwise the tunnel target is unreachable.
Follow these steps in order and you can have a dedicated AI assistant within half an hour—one that keeps your data on your own infrastructure, lets you swap models, and does not expose access to the open internet. Whether you later add messaging channel integrations or pipe logs and metrics into a unified logging service with monitoring and alerting, it all builds on this clean foundation.
