docs/setup.md
::: code-group
npm install zx # add -g to install globally
npx zx script.js # run script without installing the zx package
npx [email protected] script.js # pin to a specific zx version
yarn add zx
pnpm add zx
bun install zx
deno install -A npm:zx
# zx requires additional permissions: --allow-read --allow-sys --allow-env --allow-run
npx jsr add @webpod/zx
deno add jsr:@webpod/zx
# https://jsr.io/docs/using-packages
docker pull ghcr.io/google/zx:8.5.0
docker run -t ghcr.io/google/zx:8.5.0 -e="await \$({verbose: true})\`echo foo\`"
docker run -t -i -v ./:/script ghcr.io/google/zx:8.5.0 script/t.js
brew install zx
:::
zx is distributed in several versions, each with its own set of features.
| Channel | Description | Install |
|---|---|---|
latest | Mainline releases with the latest features and improvements. | npm i zx |
lite | A minimalistic version of zx, suitable for lightweight scripts. | npm i zx@lite |
dev | Development snapshots with the latest changes, may be unstable. | npm i zx@dev |
legacy | Legacy supporting versions for compatibility with older scripts, no new features, only bugfixes | npm i zx@<version> |
Detailed comparison: versions.
Please check the download sources carefully. Official links:
To fetch zx directly from the GitHub:
# Install via git
npm i google/zx
npm i [email protected]:google/zx.git
# Fetch from the GH pkg registry
npm i --registry=https://npm.pkg.github.com @google/zx
If you'd prefer to run scripts in a container, you can pull the zx image from the ghcr.io. node:24-alpine is used as a base.
docker pull ghcr.io/google/zx:8.5.0
docker run -t ghcr.io/google/zx:8.5.0 -e="await \$({verbose: true})\`echo foo\`"
docker run -t -i -v ./:/script ghcr.io/google/zx:8.5.0 script/t.js
zx mostly relies on bash, so make sure it's available in your environment. If you're on Windows, consider using Windows Subsystem for Linux or Git Bash.
By default, zx looks for bash binary, but you can switch to PowerShell by invoking usePowerShell() or usePwsh().
import { useBash, usePowerShell, usePwsh } from 'zx'
usePowerShell() // Use PowerShell.exe
usePwsh() // Rely on pwsh binary (PowerShell v7+)
useBash() // Switch back to bash
zx is distributed as a hybrid package: it provides both CJS and ESM entry points.
import { $ } from 'zx'
const { $ } = require('zx')
It also contains built-in TypeScript libdefs. But @types/fs-extra and @types/node are required to be installed on user's side.
npm i -D @types/fs-extra @types/node
import { type Options } from 'zx'
const opts: Options = {
quiet: true,
timeout: '5s'
}
We use esbuild to produce a static build that allows us to solve several issues at once:
zx exports several entry points adapted for different use cases:
zx – the main entry point, provides all the features.zx/global – to populate the global scope with zx functions.zx/cli – to run zx scripts from the command line.zx/core – to use zx template spawner as part of 3rd party libraries with alternating set of utilities.The library is written in TypeScript 5 and provides comprehensive type definitions for TS users.
@types/node and @types/fs-extra to be installed.