# OpenClaw on a VPS — Full Setup Guide

A complete, command-by-command walkthrough. Copy/paste in order. Total time: ~20 minutes.

> **Before you start**, have these ready:
> - A DigitalOcean account
> - An LLM API key (Claude or OpenAI)
> - Telegram on your phone

---

## Step 1 — Create the server (Droplet)

1. In DigitalOcean, click **Create → Droplets**.
2. **Image:** Ubuntu **24.04 LTS**.
3. **Size:** Basic → Regular → **1 GB RAM / 1 vCPU / 25 GB SSD** (~$6/mo). 2 GB is smoother if you can.
4. **Authentication:** add your **SSH key** (recommended) or set a root password.
5. **Region:** pick one near you.
6. Create it, then copy the **public IP address**.

> Shortcut: DigitalOcean's Marketplace has a **1-Click OpenClaw** image that pre-installs everything. If you use it, skip to Step 4.

---

## Step 2 — Connect and install

Open a terminal on your computer and connect:

```bash
ssh root@YOUR_SERVER_IP
```

Update the system:

```bash
apt update && apt upgrade -y
```

Install Node.js (OpenClaw needs **Node 22 or newer**):

```bash
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt install -y nodejs
node --version   # should print v22.x or newer
```

Install OpenClaw:

```bash
curl -fsSL https://openclaw.ai/install.sh | bash
```

Create a non-root user to run the agent (safer than running as root):

```bash
adduser openclaw
usermod -aG sudo openclaw
loginctl enable-linger openclaw   # lets its service run without an active login
su - openclaw
openclaw --version
```

If `openclaw` isn't found after switching users, fix the PATH:

```bash
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```

---

## Step 3 — Create the Telegram bot

On your phone:

1. Open Telegram, search for **@BotFather**, open the chat.
2. Send `/newbot`.
3. Enter a **display name** (e.g. "My Agent").
4. Enter a **username** ending in `bot` (e.g. `my_agent_bot`).
5. BotFather replies with a **token** like:
   ```
   123456789:ABCdef_YourBotToken_Here
   ```
6. **Copy it** — you'll paste it in the next step. (Keep it secret; anyone with it controls your bot.)

---

## Step 4 — Run onboarding

Start the setup wizard (as the `openclaw` user):

```bash
openclaw onboard --install-daemon
```

Answer the prompts:

1. **Mode:** choose **QuickStart**.
2. **LLM provider:** pick Anthropic (Claude) or OpenAI, then **paste your API key** and choose a model.
3. **Channel:** choose **Telegram**.
4. **Bot token:** paste the BotFather token from Step 3.
5. **Optional features** (web search, skills, hooks): **skip** for a minimal first setup — you can add them later.

`--install-daemon` installs OpenClaw as a background service (systemd user service) that restarts on reboot.

---

## Step 5 — Approve the pairing and test

List and approve the Telegram pairing:

```bash
openclaw pairing list telegram
openclaw pairing approve telegram --notify
```

Now test it:

1. Open your bot in Telegram (the link BotFather gave you, or search its username).
2. Send `/start`.
3. Send `hi`.

If it replies, your agent is **live**. 🎉

---

## Step 6 — Keep it running 24/7

Make sure it survives logouts and reboots:

```bash
sudo loginctl enable-linger $USER
openclaw status
systemctl --user status openclaw-gateway.service
```

**If your droplet has only 1 GB RAM**, add 2 GB of swap so it never runs out of memory:

```bash
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
```

---

## Step 7 — (Optional) Open the control UI

OpenClaw has a local web UI on port `18789`. Don't expose it publicly — reach it through an SSH tunnel:

```bash
# run this on YOUR computer, not the server
ssh -L 18789:localhost:18789 root@YOUR_SERVER_IP
```

Then open `http://localhost:18789` in your browser.

---

## Step 8 — (Recommended) Basic security

```bash
# allow SSH, enable the firewall
sudo ufw allow OpenSSH
sudo ufw enable
```

- Use **SSH keys**, not passwords.
- Keep your **bot token** and **API key** private.
- Run the agent as the **non-root** user (Step 2).

---

## Done

You have a 24/7 AI agent on a $6 server, controlled from Telegram. See [`COMMANDS.md`](COMMANDS.md) for day-to-day commands and [`TROUBLESHOOTING.md`](TROUBLESHOOTING.md) if anything breaks.
