Self-Hosting an AI Assistant on Linux: Deployment and LLM Integration Guide
This guide walks through deploying a self-hosted AI assistant on a Linux server and connecting it to a large language model, covering prerequisites, installing Node.js 22 via nvm, setting up the OpenClaw platform, troubleshooting common npm errors, and completing the onboarding wizard to connect a model API key.
If you want an AI assistant that can read internal documents and connect to your team’s chat tools, but you don’t want conversation content or API keys flowing to third-party servers, self-hosting is a practical option. This article walks through the full deployment on a Linux server. Every step includes executable commands, expected output, and fixes for common errors. By following along, you’ll end up with an AI assistant that listens only on localhost and is accessed through an SSH tunnel.
1. Prerequisites
Confirm the following three items before deploying.
- Server: A mainstream distribution such as Ubuntu 22.04/24.04 or Debian 12, with at least 2 GB of RAM and 10 GB of free disk space recommended. Perform day-to-day operations as a regular user with sudo privileges rather than running installation commands as root.
- Model API key: Create an API key in your model provider’s console. New accounts typically come with some free credit, which is enough for personal testing. It’s a good idea to create a dedicated key for this project so you can revoke it independently if something goes wrong, without affecting other services.
- Local computer: An SSH client and a browser. macOS and Linux ship with the
sshcommand built in, and Windows 10 or later includes OpenSSH.
Verify that you can log in to the server as a regular user:
ssh user@your-server-ip
After logging in, run sudo -v. If no error appears after entering your password, sudo privileges are working.
2. Install Node.js 22
The OpenClaw platform runs on Node.js and requires version 22 or later. Many distribution repositories ship older versions, so apt install nodejs often installs a version that doesn’t meet the requirement. The recommended approach is to manage Node.js with nvm (Node Version Manager). nvm installs runtimes in your home directory, requires no sudo, and won’t conflict with system packages.
First, download the nvm install script and read it before running. Piping a remote script straight into bash means your server will immediately execute any malicious code if the source has been tampered with, so don’t skip this review step:
curl -fsSL -o install-nvm.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.shless install-nvm.shbash install-nvm.sh
Press q to exit less. Only run the third line after confirming the script content looks as expected. The version is pinned to v0.40.1 to avoid pulling an unreviewed newer version on each install.
Next, reload your shell configuration, then install and set Node.js 22 as the default:
source ~/.bashrcnvm install 22nvm alias default 22node --versionnpm --version
The expected output of node --version is a version number in the v22.x.x format. If you use zsh, replace ~/.bashrc with ~/.zshrc.
3. Install the OpenClaw Platform
The platform is installed globally via npm. Global installation has a common pitfall: npm’s default global directory may be owned by root, causing an EACCES permission error for regular users. The most reliable fix is to change npm’s global prefix to a directory in your home folder, so future installs and upgrades never require sudo:
mkdir -p ~/.npm-globalnpm config set prefix ~/.npm-globalecho 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrcsource ~/.bashrc
Run the echo command only once. Running it repeatedly will append duplicate lines to ~/.bashrc.
Then install the platform and verify:
npm install -g openclaw@latestopenclaw --version
If openclaw --version prints a version number, the installation succeeded.
Common Installation Errors
ENOTEMPTY (directory not empty): This usually means a previous installation was interrupted and left an incomplete directory behind. Uninstall first, clean the cache, then reinstall:
npm uninstall -g openclawnpm cache clean --forcenpm install -g openclaw@latest
If the error persists after uninstalling, locate the leftover directory first:
ls "$(npm root -g)"
Delete only the openclaw subdirectory, not the entire global directory:
rm -rf "$(npm root -g)/openclaw"
EACCES (permission denied): Do not use sudo npm install -g. Installing with sudo makes the files owned by root, so all future upgrades and uninstalls will also require sudo, and it can leave directories with tangled permissions. Go back to the previous section and set npm’s prefix to a directory in your home folder instead.
Deprecated warnings: These are version notices from dependency packages and usually don’t affect operation. As long as the install command exits normally and openclaw --version prints a version number, you can ignore them.
4. Complete Onboarding and Connect the LLM
Run the onboarding wizard:
openclaw onboard
The wizard typically asks the following questions in sequence — follow the on-screen prompts for the exact options:
- Run mode: If you’re only using the assistant on this server itself, choose the local run mode.
- Model provider: Select the vendor you used when creating the API key.
- API Key: Paste the key you created earlier. The wizard writes the key into the platform’s configuration file.
- Base URL: If the provider offers an OpenAI-compatible endpoint, enter the full base URL, which typically ends with
/v1. Missing the path or adding an extra trailing slash will cause requests to fail.
