Install OpenClaw on Ubuntu
This guide walks through installing Node.js 22, OpenClaw, and configuring the Alibaba Cloud Bailian (Qwen) model on Ubuntu.
1. Requirements
- OS: Ubuntu (20.04 / 22.04 LTS recommended)
- Node.js: ≥ 22.12.0 (required by OpenClaw)
- Memory: ≥ 4GB recommended
- Network: Access to Alibaba Bailian API (dashscope.aliyuncs.com)
2. Install Node.js 22
NodeSource PPA (recommended, system-wide)
# Update and install dependencies
sudo apt update && sudo apt install -y curl
# Add Node.js 22 repo and install
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs build-essential
# Verify
node -v # Should show v22.x.x
npm -v
3. Install OpenClaw
One-line install (recommended)
curl -fsSL https://openclaw.ai/install.sh | bash
The script will detect/install Node.js and install OpenClaw. After installation, run:
openclaw onboard --install-daemon
Complete the wizard: workspace, security, channels, etc. You can skip models for now and configure Bailian later.
Install via npm (when Node 22 is already installed)
sudo npm install -g openclaw@latest
openclaw onboard --install-daemon
4. Get Alibaba Bailian API Key
- Sign in at Alibaba Bailian (Model Studio) (default region: Beijing).
- Go to Key Management and click Create API Key.
- Copy the API Key (only visible at creation; store it safely).
New users can claim free trial credits on the Bailian platform.
5. Configure Alibaba Bailian (Qwen) in OpenClaw
Bailian exposes an OpenAI-compatible API; OpenClaw can use it via baseUrl and apiKey.
5.1 Edit OpenClaw config
Config path: ~/.openclaw/openclaw.json.
Add a Bailian provider under models.providers (or merge into existing JSON), for example:
{
"models": {
"mode": "merge",
"providers": {
"bailian": {
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
"apiKey": "YOUR_DASHSCOPE_API_KEY",
"api": "openai-completions",
"models": [
{ "id": "qwen-plus", "name": "Qwen Plus" },
{ "id": "qwen-turbo", "name": "Qwen Turbo" },
{ "id": "qwen-max", "name": "Qwen Max" },
{ "id": "qwen3-max", "name": "Qwen3 Max" }
]
}
}
},
"agents": {
"defaults": {
"model": { "primary": "bailian/qwen-plus" },
"models": {
"bailian/qwen-plus": { "alias": "Qwen" },
"bailian/qwen-turbo": {},
"bailian/qwen-max": {},
"bailian/qwen3-max": {}
}
}
}
}
Notes:
- baseUrl (choose by region): Beijing:
https://dashscope.aliyuncs.com/compatible-mode/v1; Singapore:https://dashscope-intl.aliyuncs.com/compatible-mode/v1; Virginia:https://dashscope-us.aliyuncs.com/compatible-mode/v1 - apiKey: Replace with your Bailian API Key. If
DASHSCOPE_API_KEYis set, some versions allow"dashscope"here to read from env. - agents.defaults.model.primary: Default model, e.g.
bailian/qwen-plus. - Model IDs follow Bailian docs; common ones:
qwen-turbo,qwen-plus,qwen-max,qwen3-max.
If you already have other providers (e.g. qwen-portal), keep them and add bailian under providers.
5.2 Set default model via CLI (optional)
openclaw models set primary bailian/qwen-plus
openclaw models list
6. Remote access
OpenClaw does not allow plaintext ws:// to non-loopback addresses (SECURITY ERROR and gateway exit). For remote access, choose one:
- Recommended: Option A — Keep gateway
bind: "loopback"and use SSH tunnel from your machine (no need to expose 18789; most secure). - Option B — If you must use a public IP, put HTTPS/WSS in front (e.g. Nginx/Caddy or Tailscale), use
wss://, then you may setbind: "lan".
6.1 Option A: loopback + SSH tunnel (recommended)
Gateway listens only on localhost; you access it remotely via SSH port forwarding. No need to open 18789 or expose it.
(1)Edit ~/.openclaw/openclaw.json — in the gateway section ensure:
"gateway": {
"port": 18789,
"mode": "local",
"bind": "loopback",
"controlUi": {
"allowedOrigins": [
"http://127.0.0.1:18789",
"http://localhost:18789"
]
},
"auth": {
"mode": "token",
"token": "your-access-token"
}
}
Note: mode: "local" is for local/tunnel access. If set to "remote", OpenClaw may require remote config (e.g. WSS) before starting, or the gateway may exit with "Gateway start blocked" (see FAQ).
(2)Start the gateway on the server
openclaw gateway start
# or: systemctl --user restart openclaw-gateway.service
(3)On your own machine, create an SSH tunnel
ssh -N -L 18789:127.0.0.1:18789 user@YOUR_SERVER_IP
Keep this terminal open. Then open http://localhost:18789 in the browser (or with token: http://localhost:18789/?token=your-token).
Note: Token must be sent as query ?token=xxx, not #token=xxx (hash is client-side only). Traffic is over SSH, so you don’t need to open 18789 in the firewall.
6.2 Option B: Public IP (requires HTTPS/WSS)
If you need to reach the gateway at http://<public-IP>:18789, OpenClaw requires wss://, not plain ws://. So:
- Use Nginx/Caddy (or similar) to serve HTTPS on 443 and proxy WebSocket to
http://127.0.0.1:18789. - Keep gateway
bind: "loopback"and only reach it via the reverse proxy. - Use
https://your-domain/wss://your-domainin the browser and CLI, nothttp://IP:18789.
You can also use Tailscale Serve/Funnel for HTTPS remote access. See official docs for reverse proxy details.
If you had bind: "lan" and see SECURITY ERROR, switch back to bind: "loopback" and use Option A or configure WSS first.
6.3 CLI config (optional)
# Local mode + loopback (recommended with SSH tunnel)
openclaw config set gateway.mode "local"
openclaw config set gateway.bind "loopback"
6.4 Restart gateway to apply config
systemctl --user restart openclaw-gateway.service
# or
openclaw gateway start
6.5 Access summary
- Local:
http://localhost:18789orhttp://127.0.0.1:18789 - Remote (Option A): Run
ssh -N -L 18789:127.0.0.1:18789 user@SERVER_IP, then openhttp://localhost:18789(use?token=your-tokenif needed; do not use#token=...) - Remote (Option B): Use your configured HTTPS URL (e.g.
https://your-domain)
Do not use http://public-IP:18789 directly: OpenClaw blocks plain WebSocket to non-loopback; with loopback the gateway does not listen on the public interface. Use Option A (SSH tunnel) or Option B (HTTPS reverse proxy).
7. Ports and firewall
- Option A (SSH tunnel): No need to open 18789; only SSH (22) must be reachable.
- Option B (HTTPS): Open 443 (and 80 if you redirect HTTP to HTTPS); gateway still listens only on localhost; do not expose 18789.
Open 80 or others only if you need callbacks (e.g. for some channels).
8. Start and verify
# If daemon is installed, start the gateway
openclaw gateway start
# Or run as service (depending on your onboard choice)
- Local:
http://localhost:18789 - Remote: Establish SSH tunnel (Section 6) then
http://localhost:18789, or use your HTTPS URL
In the console Models or chat page, select Qwen (or the configured alias) and send a message; a normal reply means Bailian is connected.
9. Common commands
| Command | Description |
|---|---|
openclaw doctor | Check environment and config |
openclaw models list | List configured models |
openclaw models set primary <provider/model> | Set default model |
openclaw config get models.providers.bailian.baseUrl | Inspect provider config |
openclaw gateway start | Start gateway |
10. FAQ
-
Node version too low
Runnode -v. If below 22, install Node 22 via NodeSource (Section 2) and reinstall OpenClaw. -
Bailian 401 / call failure
- Check
apiKeyis correct and not expired. - Ensure the model (e.g. qwen-plus) is enabled in Bailian console.
- If using env var, run
source ~/.bashrcand confirmecho $DASHSCOPE_API_KEYin the current shell.
- Check
-
Cannot open console
- Confirm
openclaw gateway startis running. - Check firewall/security group for 18789 if you expect direct access (Option B).
- Confirm
-
Page loads but "disconnected from gateway" or no connection
- With SSH tunnel: ensure the tunnel is up and the browser uses
http://localhost:18789. - Check
gateway.controlUi.allowedOriginsincludes your access Origin (for local:http://127.0.0.1:18789,http://localhost:18789). - Restart gateway after config changes:
systemctl --user restart openclaw-gateway.serviceor runopenclaw gateway startagain.
- With SSH tunnel: ensure the tunnel is up and the browser uses
-
502 Bad Gateway on remote
- With SSH tunnel: Often gateway not running or tunnel not active. On server run
openclaw gateway status(Runtime running); on your machine ensure the tunnel process is running and the browser useshttp://localhost:18789only. - With Nginx/reverse proxy: 502 means the proxy cannot reach
http://127.0.0.1:18789. First: (1) On server runcurl -I http://127.0.0.1:18789/(expect 200 or 3xx). (2) Proxy must forward WebSocket (Upgrade,Connection: upgrade,proxy_http_version 1.1). Example for Nginx:(3) Reload proxy and restart gateway:location / {
proxy_pass http://127.0.0.1:18789;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}systemctl --user restart openclaw-gateway.service.
- With SSH tunnel: Often gateway not running or tunnel not active. On server run
-
SECURITY ERROR: Gateway URL uses plaintext ws:// to a non-loopback address
- OpenClaw disallows plain WebSocket to non-loopback and may exit.
- Fix: Set
gateway.bindto"loopback"and use SSH tunnel (Section 6 Option A), or configure HTTPS/WSS first then usebind: "lan". - You can run
openclaw doctor --fixor see official docs.
-
Gateway start blocked: set gateway.mode=local (current: remote) or pass --allow-unconfigured
- When
gateway.modeis"remote", OpenClaw may require remote config (e.g. WSS) before starting; otherwise it exits (exit 1). - Fix: For loopback + SSH tunnel, set
gateway.modeto"local":openclaw config set gateway.mode "local"
systemctl --user restart openclaw-gateway.service - To keep
mode: "remote", you can add--allow-unconfiguredto the gateway command in the systemd unit (edit~/.config/systemd/user/openclaw-gateway.service).
- When
-
Gateway exits right after start (Runtime: stopped, last exit 1 / RPC probe: 1006)
- Check logs:
cat /tmp/openclaw/openclaw-YYYY-MM-DD.log
journalctl --user -u openclaw-gateway.service -n 100 --no-pager - Common causes: gateway.mode=remote not fully configured (see above), Node < 22, port in use, invalid JSON or field in config, workspace/permission issues.
- Run
openclaw doctorand try foreground start:openclaw gateway --port 18789to see errors.
- Check logs:
-
Region for servers in China
For Beijing region, usebaseUrl:https://dashscope.aliyuncs.com/compatible-mode/v1. -
No API key found for provider "anthropic"
- The agent is trying to use Anthropic (Claude) but no API key is set. If you only use Qwen, configure the agent to use Bailian.
- Steps (on server): (1) Ensure
~/.openclaw/openclaw.jsonhas correctmodelsandagents.defaults.model.primary(e.g.bailian/qwen-plus). (2) Add auth for the agent:Configure API key for bailian (or dashscope); ifopenclaw agents add mainDASHSCOPE_API_KEYis set, check docs for using env. (3) Optionally restrict the agent to Qwen only so it doesn’t fall back to anthropic. - If the error says to copy auth from main agent: copy the main agent’s auth file to the failing agent’s dir (only when main already has Bailian configured):
cp ~/.openclaw/agents/main/agent/auth-profiles.json ~/.openclaw/agents/<agentDir>/auth-profiles.json