How to Install OpenClaw on Ubuntu Server (Complete Guide)

Unleashing OpenClaw: A Complete Installation Guide on Ubuntu Server

For developers and AI enthusiasts looking to self-host their AI assistant infrastructure, OpenClaw offers a robust and flexible platform. While it can run in various environments, a fresh Ubuntu Server installation on a Virtual Private Server (VPS) or a dedicated home server remains the most common and often most cost-effective choice. This guide will walk you through the entire process, from initial server setup to getting OpenClaw running as a reliable system service, all from the perspective of a developer who values practical notes and actionable steps.

We’ll assume you’re starting with a clean slate – specifically, an Ubuntu 22.04 LTS (Long Term Support) server. LTS releases are crucial for server environments due to their extended maintenance cycles, ensuring stability and security updates for years, which is ideal for a production-like setup.

Prerequisites: Laying the Groundwork

Before we dive into the commands, let’s ensure you have the necessary foundations in place. Think of these as your basic toolkit for a smooth installation:

  • Ubuntu 22.04 LTS Server: As mentioned, this is our target OS. Whether it’s a cloud instance (e.g., DigitalOcean, Linode, AWS EC2, Google Cloud Compute) or a local machine, ensure it’s a fresh installation. For cloud providers, new users often get generous credits; DigitalOcean, for instance, offers $200 in free credit, while Linode typically provides $100. This is an excellent way to spin up a basic 1-2 core, 2-4GB RAM server, which is usually sufficient for OpenClaw’s core operations.
  • SSH Access: You’ll be interacting with the server primarily via SSH. Make sure you know its IP address and have the necessary credentials (username and password, or preferably, an SSH key pair).
  • Non-root User with Sudo Privileges: This is a fundamental security best practice. Avoid running commands directly as the root user. Instead, create a standard user and grant them sudo privileges. If you’re starting as root, you can create a new user like this:
    adduser your_username
    usermod -aG sudo your_username

    Then, log out of root and log back in as your_username.

  • Basic Hardware: For typical AI assistant usage, a server with at least 2 CPU cores and 4GB of RAM is a good starting point. If you plan to run local LLMs or handle heavy concurrent requests, you might need more CPU, RAM, or even a GPU.

Step 1: System Update – The Essential First Move

Always, always, always start with updating your package lists and upgrading existing packages. This ensures you’re working with the latest security patches and stable software versions, preventing potential conflicts down the line.

sudo apt update && sudo apt upgrade -y

The -y flag automatically confirms any prompts, making the process non-interactive. Depending on your server’s age or recent updates, this might take a few minutes.

Step 2: Installing Node.js 20.x – OpenClaw’s Runtime

OpenClaw is built on Node.js, and it specifically requires a modern version to leverage the latest features and ensure compatibility. Node.js 20.x is an excellent choice for its performance improvements and LTS status. We’ll use Nodesource’s official repository for easy installation.

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
  • curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -: This command downloads and executes a script from Nodesource.
    • -f: Fail silently (no output on HTTP errors).
    • -s: Silent mode (don’t show progress meter or error messages).
    • -S: Show error messages (when -s is used).
    • -L: Follow redirects.
    • sudo -E bash -: Executes the downloaded script with sudo privileges, preserving your environment variables (-E) which is sometimes necessary for the script to correctly detect your OS and architecture.
  • sudo apt-get install -y nodejs: Once the Nodesource repository is added, this command installs the Node.js package.

Verify the installation by checking the Node.js and npm (Node Package Manager) versions:

node -v
npm -v

You should see something like v20.x.x for Node.js and a corresponding npm version.

Step 3: Installing OpenClaw – The Core Application

With Node.js in place, installing OpenClaw itself is straightforward using npm. We’ll install it globally so its commands are available system-wide.

sudo npm install -g openclaw
  • npm install -g openclaw: This command fetches the OpenClaw package from the npm registry and installs it.
  • -g: The global flag means the package will be installed in a system-wide directory (e.g., /usr/local/bin), making the openclaw command directly accessible from any directory in your shell.

Note on Permissions: If you ever encounter permission errors with npm install -g, it’s often due to npm trying to write to directories it doesn’t have access to. While sudo npm install -g works, a more robust solution for local development (not strictly necessary for this server setup but good to know) is to use a Node Version Manager (NVM) or configure npm to use a user-specific directory.

Step 4: Initial OpenClaw Setup Wizard

After installation, OpenClaw needs some initial configuration. This is handled via an interactive setup wizard.

openclaw setup

This command will guide you through essential configurations, such as:

  • Administrator User: Setting up the initial administrator username and password for accessing the OpenClaw UI.
  • Data Storage: Where OpenClaw should store its data (e.g., SQLite database file path, or connection details for external databases). For a basic setup, the default SQLite option is usually fine, but for scale, consider a dedicated PostgreSQL or MySQL instance.
  • API Keys: This is where you’ll plug in your API keys for various AI models. For example, if you plan to use OpenAI’s GPT models, Anthropic’s Claude, or other cloud-based LLMs, you’ll enter those keys here. OpenClaw is designed to be model-agnostic, allowing you to integrate with a wide range of providers.
  • Model Configuration: You might be prompted to configure default models or connect to local LLM providers like Ollama or Llama.cpp if you have them running on your server or another accessible host.

Follow the prompts carefully, providing the necessary details for your specific use case. This setup is crucial for OpenClaw to function correctly.

Step 5: Running OpenClaw as a System Service with PM2

While you can start OpenClaw with openclaw start, this command will tie up your SSH session and won’t automatically restart if the server reboots or the process crashes. For a production-ready setup, we need a robust process manager. PM2 (Process Manager 2) is an excellent choice for Node.js applications, providing features like automatic restarts, logging, and daemonization.

Install PM2

sudo npm install -g

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *