Quanlong
Quanlong

Reputation: 25486

How to install iOS simulators from command line

It's a common case to run tests against different versions of iOS simulators/SDKs on CI. However, only the latest iOS simulator is installed by Xcode on default.

So I need install other missing iOS simulators from command line in CI environment. But I cannot find a way to install those simulators from command line.

Upvotes: 16

Views: 24047

Answers (9)

Erick M. Sprengel
Erick M. Sprengel

Reputation: 2209

Alternative using xcodes

As xcodes is a popular cli to install multiple Xcode versions and easy to use:

to list runtimes:

xcodes runtimes

to install runtimes:

xcodes runtimes install "iOS 17.2"

Upvotes: 2

ahmnouira
ahmnouira

Reputation: 3411

You can use the -verbose option to see the progress

xcodebuild -downloadPlatform iOS -verbose 
Downloading iOS 17.4 Simulator (21E213): 1,2 % (83,4 MB of 7,23 GB)

Upvotes: 1

Cameron Lowell Palmer
Cameron Lowell Palmer

Reputation: 22245

Installing and managing Simulator runtimes

You can download and install one platform's simulators like this

xcodebuild -downloadPlatform iOS

or for all platforms

xcodebuild -downloadAllPlatforms

keep in mind these are very large downloads.

Lastly, to get a list of the available SDKs you can use

xcodebuild -showsdks

Upvotes: 2

abdulkareem alabi
abdulkareem alabi

Reputation: 81

if you are reading this 2024, ios installation of simulation for ios 17.2 has changed so here is how to fix it

download xcode normal from appstore or apple developer page then download ios simulation runtime of your choice also, and installed using a command line

sudo xcrun simctl runtime add 'iOS_17.2_Simulator_Runtime.dmg'

read more here https://developer.apple.com/documentation/xcode/installing-additional-simulator-runtimes

Upvotes: 2

zepar
zepar

Reputation: 165

  1. Download a simulator .dmg file from the Apple Developer Portal
  2. Install the simulator using a command: xcrun simctl runtime add <path to DMG file>

Upvotes: 1

RY_ Zheng
RY_ Zheng

Reputation: 3427

xcrun simctl create <name> <device type> <runtime>

For example:

xcrun simctl create "ry" "iPhone 11 Pro Max" iOS13.3  

xcrun simctl is command utils to control iOS simulator, just like adb for Android. You can also run xcrun simctl help, there are a bundle of useful subcommands. When successful, most of these commands exit with 0; when failed, most exit with a non-zero number.

Personally, I have an article about how to use simulator from terminal.

Upvotes: 4

Quanlong
Quanlong

Reputation: 25486

It can be done with xcode-install, with the following commands

gem install xcode-install
xcversion simulators --install='iOS 9.3'

Upvotes: 30

ipraba
ipraba

Reputation: 16543

FYI

All simulators are packed with Xcode app. Instead of installing simulators you can just install the specific Xcode versions. Xcode7.0 has iOS9 Simulators Xcode6.4 has iOS8.x Simulators

In your CI testing if you want to test you app for a specific simulator just select xcode version before you do the xcodebuild command

xcode-select -switch <path to your xcode app>

This will set your default xcode to run the xcodebuild Then run the xcodebuild with your respective simulator.

xcodebuild -configuration ${BUILD_TYPE} -target ${TARGET_NAME} -arch ${CPU_ARCHITECTURE} -sdk ${SIMULATOR_OR_IOS_SDK} 

In the place of SIMULATOR_OR_IOS_SDK give your simulator value.

You can find the simulator value by running

xcodebuild -showsdks

This will show like

OS X SDKs:
    OS X 10.11                      -sdk macosx10.11

iOS SDKs:
    iOS 9.1                         -sdk iphoneos9.1

iOS Simulator SDKs:
    Simulator - iOS 9.1             -sdk iphonesimulator9.1

tvOS SDKs:
    tvOS 9.0                        -sdk appletvos9.0

tvOS Simulator SDKs:
    Simulator - tvOS 9.0            -sdk appletvsimulator9.0

watchOS SDKs:
    watchOS 2.0                     -sdk watchos2.0

watchOS Simulator SDKs:
    Simulator - watchOS 2.0         -sdk watchsimulator2.0

This way you can build your project on any specific device/simulator/os.

Hope this helps :)

Upvotes: 0

Related Questions