Xcode Command-line Tools

Vaishali
2 min readJun 22, 2020

--

The Command Line Tools Package is a small self-contained package available for download separately from Xcode and that allows you to do command line development in macOS which is consists of the macOS SDK and command-line tools such as Clang, which are installed at this location :/Library/Developer/CommandLineTools

Download Xcode command-line tools

There is two ways to install Xcode command line tool

  1. Install Xcode

If Xcode is installed on machine, then there is no need to install them. Xcode comes bundled with all command-line tools. macOS 10.9 and later includes shims or wrapper executables. These shims, installed in /usr/bin, can map any tool included in /usr/bin to the corresponding one inside Xcode. xcrun is one of such shims, which allows you to find or run any tool inside Xcode from the command line.

2. Download the Command Line Tools package from the Developer website

If we have more than one xcode installed on mac machine, What version of Xcode do the command-line tools currently use?

To find out what version of Xcode is being used by your tools, run the following command in Terminal:

$ xcode-select --print-path

To select a default Xcode for your command-line tools, run the following command in Terminal:

$ sudo xcode-select -switch <path/to/>Xcode.app

or set for default xcode using this command:

$ sudo xcode-select -switch /Applications/Xcode11.1/Xcode.ap

Build Project from command line tool:

xcodebuild is a command-line tool that allows you to perform build, query, analyze, test, and archive operations on your Xcode projects and workspaces from the command line.

To list all schemes in your workspace, run the following command in Terminal: xcodebuild -list -workspace <workspace_name>.xcworkspace

where <workspace_name> is the name of our workspace.

To list all targets, build configurations, and schemes used in your project, run the following command in Terminal: xcodebuild -list -project <project_name>.xcodeproj

where <project_name> is the name of our project.

Listing all information about an Xcode project.

$ xcodebuild -list -project MyProject.xcodeproj

To build a scheme in your project, run the following command in Terminal:

xcodebuild -scheme <scheme_name> build

To build your target with a configuration file, run the following command in Terminal:

xcodebuild -target <your_target_name> -xcconfig <configuration_file>.xcconfig

Testing the iOSApp scheme on an iPhone/Simulator.

$ xcodebuild test -workspace projectName.xcworkspace -scheme XCUITestAutomation -destination 'platform=iOS,name=iPhone'

if you don’t want to test any specific target , Hit the following command :

Do not test XCUITestTarget on an iPhone.

xcodebuild test -workspace projectName.xcworkspace -scheme XCUITestAutomation -destination 'platform=iOS,name=iPhone' -skip-testing:XCUITestTarget

I hope you will find this command helpful while working with xcode command line tools. I will update it periodically.

--

--