Leanpub Header

Skip to main content

The Leanpub CLI

leanpub lets you work with your Leanpub books from the command line: preview and publish, upload finished files, manage coupons, and check sales. It's a single small program with nothing else to install.

It uses the Leanpub API, which is included with a Pro Author membership or above.

Install with Homebrew

On macOS or Linux with Homebrew:

brew install leanpub/tap/leanpub

Homebrew keeps it up to date: brew upgrade leanpub.

Or download it

ComputerDownload
Mac with Apple silicon (M1 and later)leanpub-aarch64-apple-darwin.tar.gz
Mac with an Intel processorleanpub-x86_64-apple-darwin.tar.gz
Linux, x86-64leanpub-x86_64-unknown-linux-musl.tar.gz
Linux, ARM64leanpub-aarch64-unknown-linux-musl.tar.gz
Windows, x86-64leanpub-x86_64-pc-windows-gnu.zip

The macOS builds are signed and notarized by Apple. The Linux builds are static, so they run on any distribution, Alpine included.

macOS and Linux

Unpack the file and move leanpub somewhere on your PATH. For example, on a Mac with Apple silicon:

tar -xzf leanpub-aarch64-apple-darwin.tar.gz
mkdir -p ~/.local/bin
mv leanpub ~/.local/bin/
leanpub --version

If your shell says command not found, ~/.local/bin isn't on your PATH yet. Add this line to ~/.zshrc (or ~/.bashrc) and open a new terminal:

export PATH="$HOME/.local/bin:$PATH"

Windows

Unzip the file and move leanpub.exe to a folder on your PATH. To make one: create %USERPROFILE%\bin, then open Edit environment variables for your account from the Start menu, edit Path, and add that folder. Open a new terminal and run leanpub --version.

The Windows build isn't code-signed yet, so Windows may warn you the first time you run it. Choose More info, then Run anyway.

Checking a download

Every release lists the SHA-256 checksum of each file. To check yours, download the list next to it:

curl -fsSLO https://leanpub.com/downloads/cli/latest/sha256.sum
shasum -a 256 --check --ignore-missing sha256.sum

Staying up to date

A downloaded leanpub keeps itself up to date. At most once a day, after a command finishes in your terminal, it checks for a new version. When one has been out for at least a day, it installs it, after checking that it's signed with Leanpub's release key and matches its checksum. Bigger version jumps are announced, not installed.

Get started

leanpub login                  # opens your API key page and asks you to paste the key
leanpub books
leanpub preview my-book --wait
leanpub --help

On macOS and Windows the key is stored in the system keychain; on Linux in a file only you can read. In CI, skip leanpub login and set LEANPUB_API_KEY instead.

Every command has --help, and --json on any command prints the API's fields as JSON.