Skip to content

macOS Commands

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

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; a guided first run is in macOS Virtual Machines.

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). 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

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

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.

Aliases: list, status, st.

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

barn mac ls
barn --json mac ls

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.

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.

OptionMeaning / defaultAvailable in
--clipboard on|offon/off, true/false, or yes/no; default on, active while the desktop window is focused1.1.0
--cpu intvCPUs, default 4; minimum 2, maximum host logical CPU count1.1.0
--disk sizeBase capacity, minimum 32 GiB; default uses the prepared base, or 100 GiB initially1.1.0
--ipsw stringinstall macOS from this restore image instead of downloading from Apple1.1.0
--memory sizeMemory, default 8 GiB; a whole MiB from 4 GiB to host RAM1.1.0
-n, --no-waitreturn once the VM runs; first boot may still be initializing1.1.0
--openshow the desktop as soon as the VM runs1.1.0
--share [name=]path[:ro]Repeatable [name=]path[:ro|:rw]; default writable, mounted under /Volumes/My Shared Files1.1.0
--subnet stringCanonical private /24, or auto; default selects the first free subnet1.1.0
--user stringGuest administrator; default is the host username, or barn if that name is invalid1.1.0
-y, --yesdownload macOS from Apple without asking (required without a terminal)1.1.0
barn mac up
barn mac up dev --cpu 8 --memory 16G --share ~/src --open
barn mac up build --yes --no-wait

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.

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.

OptionMeaning / defaultAvailable in
--allstart every machine1.1.0
-n, --no-waitreturn once the VM runs, without waiting for SSH1.1.0
--openshow the desktop as soon as the VM runs1.1.0
--recoveryboot macOS Recovery and show its desktop1.1.0
barn mac start mac1
barn mac start --all
barn mac start mac1 --recovery

barn mac stop

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

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.

OptionMeaning / defaultAvailable in
--allstop every machine1.1.0
--forcePower off immediately instead of requesting shutdown; unsaved guest work is lost1.1.0
barn mac stop dev
barn mac stop --all
barn mac stop dev --force

barn mac restart

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

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.

OptionMeaning / defaultAvailable in
-n, --no-waitreturn once the VM runs, without waiting for SSH1.1.0
--openshow the desktop as soon as the VM runs1.1.0
barn mac restart dev
barn mac restart dev --open

barn mac configure

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

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.

OptionMeaning / defaultAvailable in
--clipboard on|offon/off, true/false, or yes/no; omitted retains the setting1.1.0
--cpu intvCPUs, minimum 2 and maximum host logical CPU count; omitted retains current value1.1.0
--memory sizeMemory, a whole MiB from 4 GiB to host RAM; omitted retains current value1.1.0
--share [name=]path[:ro]Add or replace a named share; repeatable, writable by default, optional :ro or :rw1.1.0
--subnet stringmove to this private /24 network, or auto for the first free one1.1.0
--unshare stringArraystop sharing the named folder (repeatable)1.1.0
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

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.

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.

OptionMeaning / defaultAvailable in
--forceskip the confirmation (required without a terminal)1.1.0
-n, --no-waitreturn once the VM runs, without waiting for SSH1.1.0
--updateuse the newest prepared macOS base1.1.0
--yesSame as --force; no -y shorthand1.1.0
barn mac recreate dev
barn mac image update --yes
barn mac recreate dev --update --yes

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.

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

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

OptionMeaning / defaultAvailable in
--forceskip the confirmation (required without a terminal)1.1.0
--yesSame as --force; no -y shorthand1.1.0
barn mac destroy dev
barn mac destroy mac1 mac2 --yes

barn mac open

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

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.

barn mac open
barn mac open dev

barn mac ssh

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

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.

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

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

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.

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.

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

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

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

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.

OptionMeaning / defaultAvailable in
-c, --copycopy to the clipboard instead of printing1.1.0
barn mac password dev
barn mac password dev --copy

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.

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.

OptionMeaning / defaultAvailable in
-i, --installinstall the entries as one Include in ~/.ssh/config1.1.0
--removeremove the entries Barn installed1.1.0
barn mac ssh-config
barn mac ssh-config --install
barn mac ssh-config --remove

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.

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.

OptionMeaning / defaultAvailable in
-n, --lines intnumber of recent lines (default 100)1.1.0
barn mac logs dev
barn mac logs dev --lines 200

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.

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.

OptionMeaning / defaultAvailable in
--disk sizeBase capacity, at least 32 GiB. Defaults to the current base capacity or 100 GiB for the first base1.1.0
--ipsw stringinstall macOS from this restore image instead of downloading from Apple1.1.0
-y, --yesdownload macOS from Apple without asking (required without a terminal)1.1.0
barn mac setup --yes
barn mac setup --ipsw ~/Downloads/restore.ipsw --disk 200G

barn mac image ls

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

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.

barn mac image ls
barn --json mac image ls

barn mac image update

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

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.

OptionMeaning / defaultAvailable in
--ipsw stringuse this restore image instead of downloading from Apple1.1.0
-y, --yesdownload without asking (required without a terminal)1.1.0
barn mac image update --yes
barn mac image ls

barn mac image prune

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

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.

OptionMeaning / defaultAvailable in
--installersinclude downloaded restore images and partial downloads1.1.0
-y, --yesDelete the listed unused images; otherwise only list candidates1.1.0
barn mac image prune
barn mac image prune --installers --yes

barn mac doctor

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

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.

barn mac doctor
barn --json mac doctor

Implementation

command_mac.go

Table reader