@aptos-labs/aptos-cli

中文文档
3.0.1发布于 2026/10/17Apache-2.0ES Module构建来源已验证近 30 天下载 61.5万

Aptos CLI available from npmjs

原始使用文档
文档目录12 节
  1. Download
  2. Install
  3. Usage
  4. Using a Custom Binary
  5. Installing a Specific Version
  6. Updating the Aptos CLI
  7. Development
  8. Building
  9. Building Move Artifacts in CI/CD
  10. Example: Building Publish Payload
  11. Example: Building Upgrade Payload (Object Code Deployment)
  12. Using Artifacts in Subsequent Jobs

Aptos CLI

The @aptos-labs/aptos-cli package allows you to use the Aptos CLI from inside a Nodejs project.

Download

To install the Aptos CLI, you need to have Node.js and npm installed on your system. Then, you can install it using:

npm install @aptos-labs/aptos-cli

That command will download the Aptos CLI and create a Node bin file, making it available to use in a Node environment.

Install

Once you have the package installed and the Node bin file, you can run the following command, in your project environment, to install the Aptos CLI in your project:

npx aptos --install

Alternatively, you can simply run the cli using the npx aptos command. That will install the Aptos CLI in your project if it's not already installed.

npx aptos

Usage

To use the Aptos CLI, in your project environment, run the npx aptos command, to see the available commands.

npx aptos

Wrapper-specific flags such as --install, --update, --binary-path, and --direct-download are handled by the Node CLI wrapper. Other arguments are forwarded to the Aptos CLI binary, and this forwarding also works when the binary needs to be installed as part of the same invocation. For example:

npx aptos --help
npx aptos move compile --package-dir ./my-move-package

Using a Custom Binary

If you already have the Aptos CLI binary installed on your system, you can specify its path to use it directly:

npx aptos --binary-path /path/to/aptos <command>

Installing a Specific Version

You can install a specific version of the Aptos CLI by setting the APTOS_CLI_VERSION environment variable:

# Install version 4.5.0
APTOS_CLI_VERSION=4.5.0 npx aptos --install

# Or with the v prefix
APTOS_CLI_VERSION=v4.5.0 npx aptos --install

When APTOS_CLI_VERSION is set:

  • The specified version is downloaded directly from GitHub releases (package managers are bypassed)
  • The version is validated to ensure it exists before downloading
  • This works for both --install and --update commands

This is useful for:

  • Pinning to a known working version
  • Testing against specific CLI versions
  • Reproducible builds in CI/CD pipelines

Updating the Aptos CLI

To update the Aptos CLI, you can run the following command within your project environment:

npx aptos --update

Development

To set up the project for development:

  1. Clone the repository
  2. Install dependencies:
    npm install
    
  3. Run the development server:
    npm run dev
    

This will build the project and run the CLI.

Building

To build the project:

npm run build

Building Move Artifacts in CI/CD

The Aptos CLI can be used in CI/CD pipelines to build Move packages and generate deployment payloads. This is useful for automated deployments and multi-step workflows.

Example: Building Publish Payload

# In your GitHub Actions workflow

# Prerequisites: Set up Node.js first
- name: Setup Node.js
  uses: actions/setup-node@v4
  with:
    node-version: "22"

- name: Install Aptos CLI npm package
  run: npm install @aptos-labs/aptos-cli

- name: Install Aptos CLI
  run: npx aptos --install

- name: Build Move package
  working-directory: your-move-project
  run: |
    ~/.local/bin/aptos move compile \
      --named-addresses your_module=0x1 \
      --save-metadata

- name: Generate publish payload
  working-directory: your-move-project
  run: |
    ~/.local/bin/aptos move build-publish-payload \
      --named-addresses your_module=0x1 \
      --json-output-file publish-payload.json \
      --assume-yes

- name: Upload artifact for later steps
  uses: actions/upload-artifact@v4
  with:
    name: move-artifacts
    path: your-move-project/publish-payload.json

Example: Building Upgrade Payload (Object Code Deployment)

For upgrading existing object-deployed contracts:

- name: Generate upgrade payload
  working-directory: your-move-project
  run: |
    ~/.local/bin/aptos move build-upgrade-payload \
      --named-addresses your_module=0x1 \
      --object-address 0xYOUR_OBJECT_ADDRESS \
      --json-output-file upgrade-payload.json \
      --assume-yes

Using Artifacts in Subsequent Jobs

jobs:
  build:
    runs-on: 4cpu-gh-ubuntu24-x64
    steps:
      # ... build steps above ...
      - uses: actions/upload-artifact@v4
        with:
          name: move-artifacts
          path: your-move-project/publish-payload.json

  deploy:
    needs: build
    runs-on: 4cpu-gh-ubuntu24-x64
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: move-artifacts

      - name: Use the payload
        run: |
          # The payload JSON can be used for deployment
          cat publish-payload.json

See the build-move-artifacts.yaml workflow for a complete working example.

版本与发布记录

@aptos-labs/aptos-cli 共发布 37 个版本,首次发布于 2023/08/24;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.1latest2026/10/1722 天前
3.0.02026/04/156 个月前
2.0.02026/03/137 个月前
1.1.12025/12/2210 个月前
1.1.02025/04/091.6 年前
1.0.22024/10/252 年前

关于 @aptos-labs/aptos-cli 的常见问题

@aptos-labs/aptos-cli 是什么?

Aptos CLI available from npmjs

如何安装 @aptos-labs/aptos-cli?

在项目目录运行 npm install @aptos-labs/aptos-cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 aptos,可以用 npx aptos 直接运行。

@aptos-labs/aptos-cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/aptos-labs__aptos-cli 是否存在。

@aptos-labs/aptos-cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aptos-labs/aptos-cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aptos-labs/aptos-cli 可以商用吗?

@aptos-labs/aptos-cli 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aptos-labs/aptos-cli 的下载量有多少?

根据 npm 官方下载统计,@aptos-labs/aptos-cli 在 2026/10/07 – 2026/11/05 这 30 天内被下载 615,294 次,日均约 20,510 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aptos-labs/aptos-cli 还在维护吗?

最新版本 3.0.1 发布于 2026/10/17(22 天前);至今共发布 37 个版本,其中过去 12 个月发布了 4 个;首次发布于 2023/08/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。