Linux 部署 OpenClaw

本文教你从零在 Linux 上部署 OpenClaw:先做环境准备(中科大源、Node.js、git、npm 国内镜像),再安装并初始化 openclaw。命令在 Debian / Ubuntu / Fedora 下均可使用。

环境准备

切换为中科大源

Debian

sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

Ubuntu

sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list

安装 Node.js(fnm)

推荐用 fnm(Fast Node Manager)管理 Node.js 版本:

# Download and install fnm:
curl -o- https://fnm.vercel.app/install | bash

# Download and install Node.js:
fnm install 24

# Verify the Node.js version:
node -v # Should print "v24.14.0".

# Verify npm version:
npm -v # Should print "11.9.0".

安装 git

# Debian/Ubuntu
# For the latest stable version for your release of Debian/Ubuntu
# apt-get install git

# For Ubuntu, this PPA provides the latest stable upstream Git version
# add-apt-repository ppa:git-core/ppa
# apt update; apt install git

# Fedora
# yum install git (up to Fedora 21)
# dnf install git (Fedora 22 and later)

npm 切换为国内镜像

1. 淘宝源(最新)

这是目前最常用的源。

  • 设置方法

    npm config set registry https://registry.npmmirror.com
    
  • 检查是否配置成功

    npm config get registry
    
  • 其他国内镜像源

    • 腾讯云https://mirrors.cloud.tencent.com/npm/
    • 中科大https://mirrors.ustc.edu.cn/npm/
    • 清华大学https://mirrors.tuna.tsinghua.edu.cn/npm/
  • 恢复官方源

    如果需要切回官方源,执行:

    npm config set registry https://registry.npmjs.org/
    

2. 推荐的安装方式:cnpm

可以安装 cnpm 专门用于国内下载。

npm install -g cnpm --registry=https://registry.npmmirror.com
# 之后使用 cnpm install 代替 npm install

3. 配置成功检查

执行以下命令,若输出 https://registry.npmmirror.com/ 则说明配置成功:

npm config get registry

环境验证

node -v
npm -v
git -v

三个命令均能正常输出版本号,说明环境准备完成。

安装 OpenClaw

npm i -g openclaw
openclaw onboard

openclaw onboard 是交互式配置向导,按提示选择模型、设置网关即可完成初始化。

验证部署

openclaw --version
# 输出版本号即安装成功

openclaw gateway
# 网关正常启动,浏览器访问 http://127.0.0.1:18789/ 可打开控制台

参考