Skip to content
Latchkey

xcrun simctl create and erase: Clean iOS Simulators in CI

xcrun simctl create makes a new simulator from a device type and runtime, and simctl erase wipes an existing one back to factory state.

Flaky iOS tests often come from dirty simulator state carried between runs. Creating a dedicated device or erasing before the test gives every run the same clean slate.

What it does

simctl create <name> <deviceType> <runtime> registers a new simulator and prints its UDID. simctl erase <udid|all> deletes the device data, resetting it to first-boot state (the device must be shut down first). simctl delete removes the device entirely.

Common usage

Terminal
# create a device pinned to a known type + runtime
UDID=$(xcrun simctl create "ci-iphone" \
  "iPhone 15" "com.apple.CoreSimulator.SimRuntime.iOS-17-5")
# wipe all devices back to clean state
xcrun simctl shutdown all
xcrun simctl erase all
xcrun simctl delete "$UDID"

Options

SubcommandWhat it does
create <name> <type> <runtime>Create a device, prints its UDID
erase <udid|all>Reset device(s) to factory state
delete <udid|all|unavailable>Remove device(s); unavailable clears stale ones
list devicetypes / runtimesEnumerate valid type and runtime identifiers
shutdown <udid|all>Shut down before erasing

In CI

Run xcrun simctl delete unavailable and xcrun simctl erase all at the start of a job to clear devices left over from a previous Xcode version. Creating a purpose-named device and deleting it at the end keeps the runner clean without touching Apple-provided defaults.

Common errors in CI

"Unable to erase contents and settings in current state: Booted" means you must shut the device down first (simctl shutdown). "Invalid runtime: com.apple.CoreSimulator.SimRuntime..." means that iOS runtime is not installed in this Xcode; list runtimes with simctl list runtimes. "Invalid device type" is the analogous error for the device type identifier.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →