# sow rm

> Remove packages from selected Dists and preview the result.

---

LLMS index: [llms.txt](/llms.txt)

---

`sow rm` removes packages from the selected Dists and rebuilds their local indexes. Use `--check` to preview the removal, or `--skip` to postpone the build. Package files remain in `pool/` until [`sow gc`](/docs/command/gc/) can reclaim them.

## Synopsis

```text
sow rm PACKAGE... [-c|--check] [--skip] [-j|--jobs N] [-C|--workdir DIR] [-r|--repo NAME] [-d|--dist NAME]... [-T|--timeout DUR | -N|--no-wait] [--json] [--passfile PATH]
```

A `--check` preview can render signed metadata and also accepts `--passfile`. See [Password files](/docs/reference/config/#passfile).

## Options

| Flag | Description | Default |
|---|---|---|
| `-c, --check` | Preview only; compute and print the plan without writing anything | off |
| `--skip` | Update Desired state only; do not build | off |
| `-j, --jobs N` | Parallel workers | logical CPU count |
| `-C, --workdir DIR` | Workspace discovery start directory | current directory |
| `-r, --repo NAME` | Select a repository | selection rules |
| `-d, --dist NAME` | Select a distribution; repeatable | selection rules |
| `-T, --timeout DUR` | Maximum lock wait; `0` waits indefinitely | `0` |
| `-N, --no-wait` | Fail immediately when the lock is held | false |
| `--passfile PATH` | [Password file for this invocation](/docs/reference/config/#passfile) | per-key config, then `SOW_GPG_PASSFILE` |
| `--json` | Output JSON | false |

`--check` and `--skip` are mutually exclusive:

```console
sow rm epel-release -c --skip
usage error: --check and --skip are mutually exclusive
```

## Package references

`PACKAGE` accepts five forms. The full grammar and disambiguation rules are on
[Package References](/docs/reference/package-ref/); the short version:

| Form | Example |
|---|---|
| Content hash | `sha256:d6f332ed157de1d42058ec785b392a1cc4b5836c27830af8fbf083cce29ef0ab` |
| RPM coordinate | `rpm:epel-release-0:7-5.noarch` |
| DEB coordinate | `deb:libpq5=18.3-1:amd64` |
| Full filename | `epel-release-7-5.noarch.rpm` |
| Bare binary name | `epel-release` |

A bare name matches every version and architecture of that name in the selected Dists. Other reference forms must identify one object. An ambiguous reference returns an error with the matching candidates.

[`sow ls`](/docs/command/ls/) prints exact `sha256:` references and canonical coordinates,
so you never have to assemble one by hand.

If no package matches a reference, the command returns an error:

```console
sow rm nosuch -r pigsty -d el9
operation rejected: managed: operation rejected: package reference not found: package reference "nosuch" matches no Desired Membership
```

## Default behavior: remove and rebuild

Without `--check` or `--skip`, `rm` commits the Desired change and rebuilds every affected Dist
before returning. Pool objects stay on disk.

```console
sow rm 'rpm:centos-release-0:6-0.el6.centos.5.x86_64' -r demo -d el9
removed repository=demo operation=2283442100870457321 dists=el9 memberships=1 revision=2 generation=00000000000000000003 dirty=false changes=8
membership dist=el9 name="centos-release" coordinate="rpm:centos-release-0:6-0.el6.centos.5.x86_64" sha256:ffd9e7bdaa4884831a6c055ada01dac96b84c50a8d518dac409b445af5dadc16
```

The summary is followed by one `change` line per affected file (eight in this run). Add `--json` to
receive the same result as a stable standard envelope.

Removing the last member of a Dist is fine. SOW still renders a valid, signed-if-configured empty
index — an empty `Packages` with a verifiable `InRelease`, or empty per-architecture `repodata/`.

## Preview with --check

`-c/--check` previews the removal and resulting local file changes without modifying the Repository. `removed` lists memberships matched by your references. If the current policy removes additional members, their index changes appear in `changes`; their membership count appears in `sow log` after the removal runs.

Preview predicts membership removals, policy results, file paths, actions, Generation, and revision.
These match execution when package references, selected Dists, repository state, configuration, and signing keys remain unchanged.
Execution records its own publication time when it rebuilds metadata.
Indexes and signatures that contain time values can therefore differ in bytes, hashes, and sizes.

```console
sow rm centos-release -r demo -d el9 -c
preview repository=demo operation= dists=el9 memberships=2 revision=2 generation=00000000000000000003 dirty=false changes=2
membership dist=el9 name="centos-release" coordinate="rpm:centos-release-0:6-0.el6.centos.5.x86_64" sha256:ffd9e7bdaa4884831a6c055ada01dac96b84c50a8d518dac409b445af5dadc16
membership dist=el9 name="centos-release" coordinate="rpm:centos-release-0:7-2.1511.el7.centos.2.10.x86_64" sha256:b4111ef2a51542eacc9bd1ebd080da02e53d400f9d172530c75a1e4ac06e7ead
change op=update phase=pointer path="dists/el9/aarch64/repodata/repomd.xml" size=1509 sha256:1cfe38698967d11384f1a985618d75f5e690d1284accf951262fc663fa9afc81
change op=update phase=pointer path="dists/el9/x86_64/repodata/repomd.xml" size=1509 sha256:1cfe38698967d11384f1a985618d75f5e690d1284accf951262fc663fa9afc81
```

Both `centos-release` versions matched the bare name. The `change` lines describe the expected local file changes in `payload → metadata → pointer → delete` order. Use `--json` to read the `removed[]` and `changes[]` arrays in a script.

Preview validates the candidate configuration and existing state. It uses shared locks and can wait for a writer, but does not accept `--timeout` or `--no-wait`:

```console
sow rm centos-release -r pigsty -d el9 -c -T 5s
usage error: rm --check does not accept --timeout or --no-wait
```

## --skip

`--skip` commits the Desired change and leaves the public tree unchanged. The Repository is dirty if the resulting Desired state differs from Built state. Removing a pending-only addition can return it to clean without a build.

```console
sow rm 'rpm:centos-release-0:7-2.1511.el7.centos.2.10.x86_64' --skip -r demo -d el9
removed repository=demo operation=314678479940914827 dists=el9 memberships=1 revision=4 generation=00000000000000000004 dirty=true changes=0
membership dist=el9 name="centos-release" coordinate="rpm:centos-release-0:7-2.1511.el7.centos.2.10.x86_64" sha256:b4111ef2a51542eacc9bd1ebd080da02e53d400f9d172530c75a1e4ac06e7ead
```

```console
sow status -r pigsty
repository=pigsty status=dirty ready_to_copy=false revision=6 generation=5 dirty_dists=el9 pending=0/0 locked=false
```

`changes` is empty because nothing was built. Run [`sow build`](/docs/command/build/) to
build the pending changes.

## Policy interaction

After removal, SOW applies policy to the remaining members. If you remove `libpq5 18.3-1` from a `limit: 1` Dist, the previously excluded `18.2-1` stays excluded. Run `sow add` to restore it.

## Examples

Preview a removal, then apply it:

```bash
sow rm patroni -r pgsql -d el9 -c
sow rm patroni -r pgsql -d el9
```

Remove one exact object from two Dists with one command:

```bash
sow rm sha256:d6f332ed157de1d42058ec785b392a1cc4b5836c27830af8fbf083cce29ef0ab -r pgsql -d el9 -d el9-beta
```

Batch several removals, then rebuild once:

```bash
sow rm old-tool legacy-agent -r pgsql -d el9 --skip
sow build -r pgsql -d el9
sow check -r pgsql
```

Feed the preview plan to another tool:

```bash
sow rm patroni -r pgsql -d el9 -c --json | jq -r '.result.changes[] | "\(.phase)\t\(.op)\t\(.path)"'
```

## Exit codes

| Code | Trigger |
|---|---|
| `0` | Memberships removed and rebuilt, or a `--check` preview printed |
| `1` | Runtime I/O or renderer failure |
| `2` | Usage error — `--check` with `--skip`, `--check` with lock flags, ambiguous selection, Workspace not found |
| `4` | Repository lock held and `--no-wait` given or `--timeout` expired |
| `5` | Integrity or recovery error |
| `6` | A reference matched nothing, or a non-bare reference was ambiguous; the whole batch is rejected and no memberships are removed |

## See also

- [Package References](/docs/reference/package-ref/) — the full reference grammar
- [`sow ls`](/docs/command/ls/), [`show`](/docs/command/show/), and [`where`](/docs/command/where/) — finding the exact reference to remove
- [sow add](/docs/command/add/) — the inverse operation
- [sow build](/docs/command/build/) — build after `--skip`
- [Membership Policy](/docs/feature/policy/) — why removed members do not come back
- [`sow retain`](/docs/command/retain/) and [`sow gc`](/docs/command/gc/) — when bytes can be reclaimed
