# macOS Commands

> Syntax, options, and examples for every barn mac subcommand.

---

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

---

Syntax, options, and examples for every `barn mac` subcommand. The machine model, networks, JSON results, and failure reasons these commands share are defined in the [Mac Runtime Reference](../../mac/); a guided first run is in [macOS Virtual Machines](../../../start/macos/).

## Common rules {#common-rules}

- **Host.** The commands need an Apple Silicon Mac on macOS 27 or later with the matching `Barn.app`, run as the logged-in desktop user ([requirements](../../../start/macos/#requirements)). At most two macOS VMs run at a time per Mac; starting a third fails with `mac_vm_limit`.
- **Machine names.** A command with an optional `[name]` uses the only existing machine, or `mac1`. With several machines and none named `mac1`, pass a name. `configure`, `recreate`, and `destroy` always need one. `start` and `stop` take several names or `--all`, not both.
- **Sizes.** `--memory` and `--disk` are binary even when written `GB`: `16G`, `16GiB`, and `16GB` all mean 16 GiB, and a bare number is bytes. Linux inventory `GB` is decimal.
- **Confirmation.** `recreate` and `destroy` print what they will delete and ask you to type the command name. `--yes` or `--force` skips the question and is required without a terminal; neither command has a `-y` shorthand. Commands that download macOS from Apple (`up`, `setup`, `image update`) ask first; `-y`/`--yes` skips that question and is required without a terminal.
- **State.** Machines live under `$BARN_HOME/mac`, separate from the Linux inventory. These commands ignore the Linux `BARN_IMAGE/BARN_ARCH/BARN_CPU/BARN_MEM/BARN_SCALE/BARN_DISK` overrides.

Every option below has been available since 1.1.0.

## `barn mac ls` {#barn-mac-ls}

Start here to see what exists: every machine with its state, address, SSH readiness, macOS build, resources, and shares.

```text
barn mac ls [flags]
```

It reads local records and queries running machines; it never creates, downloads, or starts anything. `barn mac` without a subcommand runs `ls`. The JSON shape is in [`ls` output](../../mac/#ls).

Aliases: `list`, `status`, `st`.

No local options beyond `--help`; global presentation options still apply.

```bash
barn mac ls
barn --json mac ls
```

## `barn mac up` {#barn-mac-up}

Use `up` to get a machine running: it creates the machine the first time, starts it afterwards, and returns once SSH and passwordless sudo work.

```text
barn mac up [name] [flags]
```

The default name is `mac1`. On a Mac without a prepared macOS base, `up` first downloads the restore image from Apple after you confirm and installs it once; later machines clone that base in seconds. A `--disk` size that differs from the prepared base's capacity installs a matching base first.

Creation options apply only to a new machine. On an existing machine `up` just starts it; an option that differs from the recorded setting fails with `mac_configuration_conflict`, and the `next:` line prints the command to use instead. `--share` names default to the folder's last path component, and `~/` expands to your home directory.

`--no-wait` returns once the VM is running. On a first boot, provisioning may still be in progress; run `barn mac up NAME` again to wait for SSH and finish initialization before using `ssh` or `exec`.

| Option | Meaning / default | Available in |
|---|---|---|
| `--clipboard on\|off` | on/off, true/false, or yes/no; default on, active while the desktop window is focused | 1.1.0 |
| `--cpu int` | vCPUs, default 4; minimum 2, maximum host logical CPU count | 1.1.0 |
| `--disk size` | Base capacity, minimum 32 GiB; default uses the prepared base, or 100 GiB initially | 1.1.0 |
| `--ipsw string` | install macOS from this restore image instead of downloading from Apple | 1.1.0 |
| `--memory size` | Memory, default 8 GiB; a whole MiB from 4 GiB to host RAM | 1.1.0 |
| `-n, --no-wait` | return once the VM runs; first boot may still be initializing | 1.1.0 |
| `--open` | show the desktop as soon as the VM runs | 1.1.0 |
| `--share [name=]path[:ro]` | Repeatable [name=]path[:ro\|:rw]; default writable, mounted under /Volumes/My Shared Files | 1.1.0 |
| `--subnet string` | Canonical private /24, or auto; default selects the first free subnet | 1.1.0 |
| `--user string` | Guest administrator; default is the host username, or barn if that name is invalid | 1.1.0 |
| `-y, --yes` | download macOS from Apple without asking (required without a terminal) | 1.1.0 |
{.wide .expand}

```bash
barn mac up
barn mac up dev --cpu 8 --memory 16G --share ~/src --open
barn mac up build --yes --no-wait
```

## `barn mac start` {#barn-mac-start}

Use `start` to boot machines that have already completed their first `up`. It waits for SSH and never creates a machine or downloads anything.

```text
barn mac start [name...] [flags]
```

Select names or `--all`, not both. A machine that has not finished its first boot fails with `mac_not_initialized`: if it is running, watch its first boot with `barn mac open NAME`; if it is stopped, continue with `barn mac up NAME --open`. `--recovery` boots macOS Recovery with its desktop shown and does not wait for SSH.

| Option | Meaning / default | Available in |
|---|---|---|
| `--all` | start every machine | 1.1.0 |
| `-n, --no-wait` | return once the VM runs, without waiting for SSH | 1.1.0 |
| `--open` | show the desktop as soon as the VM runs | 1.1.0 |
| `--recovery` | boot macOS Recovery and show its desktop | 1.1.0 |
{.wide .expand}

```bash
barn mac start mac1
barn mac start --all
barn mac start mac1 --recovery
```

## `barn mac stop` {#barn-mac-stop}

Use `stop` to shut machines down cleanly through macOS; disks and settings stay as they are.

```text
barn mac stop [name...] [flags]
```

A machine that has not stopped after two minutes is powered off, and the result says so (`"forced": true`). `--force` powers off at once, like holding the power button; unsaved work in the guest is lost.

| Option | Meaning / default | Available in |
|---|---|---|
| `--all` | stop every machine | 1.1.0 |
| `--force` | Power off immediately instead of requesting shutdown; unsaved guest work is lost | 1.1.0 |
{.wide .expand}

```bash
barn mac stop dev
barn mac stop --all
barn mac stop dev --force
```

## `barn mac restart` {#barn-mac-restart}

Use `restart` to apply settings saved with `configure`, or to reboot a guest that misbehaves.

```text
barn mac restart [name] [flags]
```

It shuts the machine down normally and starts it again. It takes at most one name and has no `--all`.

| Option | Meaning / default | Available in |
|---|---|---|
| `-n, --no-wait` | return once the VM runs, without waiting for SSH | 1.1.0 |
| `--open` | show the desktop as soon as the VM runs | 1.1.0 |
{.wide .expand}

```bash
barn mac restart dev
barn mac restart dev --open
```

## `barn mac configure` {#barn-mac-configure}

Use `configure` to change a machine's CPUs, memory, shared folders, network, or clipboard setting without touching its disk or account.

```text
barn mac configure <name> [flags]
```

CPUs, memory, shared folders, and the subnet change only while the machine is stopped; otherwise the command fails with `mac_running`. The clipboard setting can change anytime. Saved configuration, including a clipboard change, applies at the next start; to toggle clipboard sharing for the current session, use the menu bar.

Omitted options keep their values. `--share` adds a share or replaces the share of that name; `--unshare` removes one. `--subnet auto` moves the machine to the first free subnet, which is the fix for `mac_subnet_in_use`.

| Option | Meaning / default | Available in |
|---|---|---|
| `--clipboard on\|off` | on/off, true/false, or yes/no; omitted retains the setting | 1.1.0 |
| `--cpu int` | vCPUs, minimum 2 and maximum host logical CPU count; omitted retains current value | 1.1.0 |
| `--memory size` | Memory, a whole MiB from 4 GiB to host RAM; omitted retains current value | 1.1.0 |
| `--share [name=]path[:ro]` | Add or replace a named share; repeatable, writable by default, optional :ro or :rw | 1.1.0 |
| `--subnet string` | move to this private /24 network, or auto for the first free one | 1.1.0 |
| `--unshare stringArray` | stop sharing the named folder (repeatable) | 1.1.0 |
{.wide .expand}

```bash
barn mac stop dev
barn mac configure dev --cpu 8 --memory 16G --share ~/src
barn mac configure dev --unshare src --clipboard off
barn mac start dev
```

## `barn mac recreate` {#barn-mac-recreate}

Use `recreate` to get a clean disk from the base image while keeping the machine's name and settings, or, with `--update`, to move the machine to the newest prepared macOS.

> [!WARNING]
> `recreate` erases the machine's disk: files, apps, and settings inside the guest are lost. Shared folders on the host are untouched. Copy anything you need off the guest first.

```text
barn mac recreate <name> [flags]
```

The new machine keeps its name, account, CPUs, memory, disk capacity, shared folders, clipboard setting, and address, and gets a new login password and new SSH keys.

`--update` clones the default base that `barn mac image update` prepared, at the machine's own disk capacity. If the new macOS build is prepared only at another capacity, prepare it first, for example `barn mac setup --disk 200G`.

| Option | Meaning / default | Available in |
|---|---|---|
| `--force` | skip the confirmation (required without a terminal) | 1.1.0 |
| `-n, --no-wait` | return once the VM runs, without waiting for SSH | 1.1.0 |
| `--update` | use the newest prepared macOS base | 1.1.0 |
| `--yes` | Same as `--force`; no -y shorthand | 1.1.0 |
{.wide .expand}

```bash
barn mac recreate dev
barn mac image update --yes
barn mac recreate dev --update --yes
```

## `barn mac destroy` {#barn-mac-destroy}

Use `destroy` to delete machines you no longer need.

> [!WARNING]
> `destroy` powers each named machine off and deletes its disk, SSH keys, password, and settings. The shared macOS base, other machines, and shared folders on the host are kept.

```text
barn mac destroy <name...> [flags]
```

Explicit names are required. Run `barn mac image prune` afterwards to remove bases that no machine uses.

| Option | Meaning / default | Available in |
|---|---|---|
| `--force` | skip the confirmation (required without a terminal) | 1.1.0 |
| `--yes` | Same as `--force`; no -y shorthand | 1.1.0 |
{.wide .expand}

```bash
barn mac destroy dev
barn mac destroy mac1 mac2 --yes
```

## `barn mac open` {#barn-mac-open}

Use `open` to see and use the machine's desktop; it starts a stopped machine first.

```text
barn mac open [name] [flags]
```

Closing the window keeps the machine running in the background, and the clipboard is shared while the window is focused. A running machine that has not finished its first boot can be watched here; for a stopped one, use `barn mac up NAME --open`.

No local options beyond `--help`; global presentation options still apply.

```bash
barn mac open
barn mac open dev
```

## `barn mac ssh` {#barn-mac-ssh}

Use `ssh` for an interactive shell in the machine, or to run a shell command line in it.

```text
barn mac ssh [flags] [name] [-- command...]
```

Without a command, `ssh` opens an interactive session. A command after `--` is joined into one line for the guest shell, as plain `ssh` does, and its exit status is returned. Argument rules are in [SSH and exec](../../mac/#ssh-and-exec).

No local options beyond `--help`; global presentation options still apply.

```bash
barn mac ssh dev
barn mac ssh dev -- 'sw_vers; id'
```

## `barn mac exec` {#barn-mac-exec}

Use `exec` in scripts: it runs one program with its arguments passed exactly as given and returns the program's exit status.

```text
barn mac exec [flags] [name] -- command...
```

A command after `--` is required. Use `sh -c` explicitly for pipelines and other shell expressions. With `--json` the result carries `exit_code`, `stdout`, and `stderr`. Argument rules are in [SSH and exec](../../mac/#ssh-and-exec).

No local options beyond `--help`; global presentation options still apply.

```bash
barn mac exec dev -- sw_vers
barn mac exec dev -- printf '<%s>\n' 'a b' ''
barn --json mac exec dev -- sh -c 'echo out; exit 3'
```

## `barn mac password` {#barn-mac-password}

Use `password` when the guest desktop asks for the login password, at the lock screen or an administrator prompt.

```text
barn mac password [name] [flags]
```

The password is stored next to the machine's SSH key with the same protection. `--copy` puts it on the clipboard instead of printing it.

| Option | Meaning / default | Available in |
|---|---|---|
| `-c, --copy` | copy to the clipboard instead of printing | 1.1.0 |
{.wide .expand}

```bash
barn mac password dev
barn mac password dev --copy
```

## `barn mac ssh-config` {#barn-mac-ssh-config}

Use `ssh-config` to let `ssh`, `scp`, `rsync`, and editors reach each machine by name, with its own key and pinned host key.

```text
barn mac ssh-config [flags]
```

Without options it prints the OpenSSH fragment. The first machine to become ready installs the fragment as one `Include` in `~/.ssh/config`, and lifecycle commands keep it current. `--remove` deletes only what Barn installed and keeps it out until `--install`. A name that `~/.ssh/config` already uses for another host is published by address only. If `~/.ssh/config` is a symlink or hard link, the command fails with `ssh_config_linked` and prints the `Include` line for you to add.

`--install` and `--remove` are mutually exclusive. This command takes no machine names.

| Option | Meaning / default | Available in |
|---|---|---|
| `-i, --install` | install the entries as one Include in ~/.ssh/config | 1.1.0 |
| `--remove` | remove the entries Barn installed | 1.1.0 |
{.wide .expand}

```bash
barn mac ssh-config
barn mac ssh-config --install
barn mac ssh-config --remove
```

## `barn mac logs` {#barn-mac-logs}

Use `logs` when a machine fails to start, loses its network, or does not shut down: it shows the last lines of the machine's runtime log, including Apple Virtualization errors.

```text
barn mac logs [name] [flags]
```

`--lines`/`-n` must be positive and defaults to 100. Here `-n` means lines, not no-wait. There is no follow option.

| Option | Meaning / default | Available in |
|---|---|---|
| `-n, --lines int` | number of recent lines (default 100) | 1.1.0 |
{.wide .expand}

```bash
barn mac logs dev
barn mac logs dev --lines 200
```

## `barn mac setup` {#barn-mac-setup}

Use `setup` to prepare the macOS base ahead of time, for example in a provisioning script, so the first `up` only has to clone it.

```text
barn mac setup [flags]
```

It downloads macOS from Apple after you confirm, or reads `--ipsw`, and installs it once into the unbooted base that every machine is cloned from. `up` does the same automatically when no base is prepared.

| Option | Meaning / default | Available in |
|---|---|---|
| `--disk size` | Base capacity, at least 32 GiB. Defaults to the current base capacity or 100 GiB for the first base | 1.1.0 |
| `--ipsw string` | install macOS from this restore image instead of downloading from Apple | 1.1.0 |
| `-y, --yes` | download macOS from Apple without asking (required without a terminal) | 1.1.0 |
{.wide .expand}

```bash
barn mac setup --yes
barn mac setup --ipsw ~/Downloads/restore.ipsw --disk 200G
```

## `barn mac image ls` {#barn-mac-image-ls}

Use `image ls` to see which restore images and bases take up disk space, and which machines use them.

```text
barn mac image ls [flags]
```

It lists each restore image and base with its state and disk usage. It reads local state only and does not start the native runner.

Aliases: `list`.

No local options beyond `--help`; global presentation options still apply.

```bash
barn mac image ls
barn --json mac image ls
```

## `barn mac image update` {#barn-mac-image-update}

Use `image update` to move to Apple's newest macOS 27 build.

```text
barn mac image update [flags]
```

It asks Apple for the newest macOS 27 restore image, downloads it after you confirm, and installs it as the default base for new machines. Existing machines keep their base until you run `barn mac recreate NAME --update`.

| Option | Meaning / default | Available in |
|---|---|---|
| `--ipsw string` | use this restore image instead of downloading from Apple | 1.1.0 |
| `-y, --yes` | download without asking (required without a terminal) | 1.1.0 |
{.wide .expand}

```bash
barn mac image update --yes
barn mac image ls
```

## `barn mac image prune` {#barn-mac-image-prune}

Use `image prune` to reclaim disk space from bases that no machine uses.

```text
barn mac image prune [flags]
```

It lists unused bases other than the current default. `--installers` adds downloaded restore images and partial downloads. Nothing is deleted without `--yes`.

| Option | Meaning / default | Available in |
|---|---|---|
| `--installers` | include downloaded restore images and partial downloads | 1.1.0 |
| `-y, --yes` | Delete the listed unused images; otherwise only list candidates | 1.1.0 |
{.wide .expand}

```bash
barn mac image prune
barn mac image prune --installers --yes
```

## `barn mac doctor` {#barn-mac-doctor}

Run `doctor` first when something goes wrong, and after installing or upgrading Barn.

```text
barn mac doctor [flags]
```

It checks macOS and Apple Silicon support, the Mac component's signature, free disk space, the prepared base, and every machine: its files, keys, shared folders, network, and SSH. It changes nothing and starts nothing, and exits `3` if any check fails.

No local options beyond `--help`; global presentation options still apply.

```bash
barn mac doctor
barn --json mac doctor
```

## Implementation {#implementation}

[command_mac.go](https://github.com/pgsty/barn/blob/v1.4.0/cmd/barn/command_mac.go)
