Home/Guides/How to manage iOS simulators with simctl: create, boot, erase and delete

How to manage iOS simulators with simctl: create, boot, erase and delete

Updated · airankrush

What this guide covers

When you finish, you can prepare a clean simulator and run tests on it using only Terminal, and clear out devices and runtimes you no longer use. You need: Xcode installed and at least one iOS simulator runtime.

Steps

  1. First see what is on the machine

    xcrun simctl list devices available
    xcrun simctl list runtimes
    xcrun simctl list devicetypes

    The first lists the simulators currently available and their state, the second lists installed runtimes, and the third lists the device types you can create. Add -j for JSON output, which is easier for scripts to parse.

  2. Install a runtime

    If the iOS version you need is missing, follow Apple's component installation documentation: click Get in Components under Xcode > Settings, or:

    xcodebuild -downloadPlatform iOS

    The documentation also says you can use -buildVersion to specify the OS version and -exportPath to download without installing. Runtime files are large and download speed depends on the line, so run it inside tmux.

  3. Create a dedicated simulator

    xcrun simctl create "ci-phone" <device type identifier> <runtime identifier>

    Take the two identifiers from the output of list devicetypes and list runtimes. Creating one device just for CI with a fixed name gives you more control than using the batch Xcode generates automatically: test scripts can find it by name and will not fail because the default devices changed after an Xcode upgrade.

  4. Boot, install the app, run

    xcrun simctl boot "ci-phone"
    xcrun simctl install booted build/App.app
    xcrun simctl launch booted com.example.app

    booted stands for the currently booted device. When several are booted, simctl picks one itself, so scripts are better off naming the device or its identifier. For running tests, hand over to xcodebuild test with the destination written as -destination 'platform=iOS Simulator,name=ci-phone'.

  5. Erase before each test round

    xcrun simctl shutdown all
    xcrun simctl erase "ci-phone"

    erase clears the device's contents and settings, the equivalent of a factory reset. When test results are affected by data left over from the previous round, this is the most direct fix.

  6. Clean up unused devices and runtimes

    xcrun simctl delete unavailable
    xcrun simctl runtime list
    xcrun simctl runtime delete <runtime identifier>

    delete unavailable deletes devices the current Xcode no longer supports. runtime delete also supports --notUsedSinceDays <days> to clean up by last use, and --dry-run shows what would be deleted without deleting it. Remember to run a cleanup after upgrading or removing an Xcode.

  7. Limits on remote and build machines

    A simulator is not a real device. Push notifications, the camera and some hardware-related capabilities have to be verified on a real device, and a remote Mac cannot be connected to the device in your hand; see can a remote Mac debug on a real device.

    When you watch the simulator over remote desktop, smoothness depends on your local network connection. CI tests do not need the picture and are unaffected. Also, simulators need a graphical session: the official GitLab Runner documentation points out that the runner has to run in a user session to access simulators. So a build agent should be installed as a service under the logged-in user.

FAQ

Why does the remote desktop get laggy after a simulator boots?

A simulator's picture changes a lot, so the amount of data the remote session sends goes up. If you only run automated tests, there is no need to open the Simulator app window; boot the device from the command line.

simctl says the device cannot be found. Why?

Use list first to confirm the name and state. A common cause is that you switched Xcode versions and the original device became unavailable under the new version. Create a new one.

Can I run several simulators at once?

Yes, but each one uses memory and CPU. How many can run in parallel depends on the machine configuration and your tests, and we have no measured figures to offer. See the plans page for configurations.

Do I need to clean up simulators before the rental ends?

Not for the sake of reclamation; the whole machine is erased. What you need to take with you are result files produced by tests, such as screenshots and logs, if they exist only on this machine.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All guides