96

I am using Xcode command line tools instead of XCode app in my MAC. When i use swift --version I get Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51) I cloned a project with

git clone https://github.com/apple/example-package-dealer.git
cd example-package-dealer
swift run Dealer

I gives me this error:

error: terminated(72): OLDPWD=/Users/sayansen/Work/EdgeAnalytics/Trial TERM_PROGRAM=Apple_Terminal PWD=/Users/sayansen/Work/EdgeAnalytics/Trial/example-package-dealer SHLVL=1 SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.9lwBmlYTAx/Listeners HOME=/Users/sayansen LIBRARY_PATH=/usr/local/lib __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0 XPC_SERVICE_NAME=0 TMPDIR=/var/folders/kn/v4zm474x52n8zrycxs7nh5c40000gn/T/ LOGNAME=sayansen SHELL=/bin/bash TERM_PROGRAM_VERSION=433 _=/usr/bin/swift PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS CPATH=/usr/local/include SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk XPC_FLAGS=0x0 TERM=xterm-256color USER=sayansen LC_CTYPE=UTF-8 TERM_SESSION_ID=B285E686-2802-48C6-B8CE-03CA8F2314BF xcrun --sdk macosx --find xctest output:
xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

I am not using XCODE. I already did this:

sudo xcode-select -s /Library/Developer/CommandLineTools

But not helpfull.

How to solve this error without installing XCode?

Sayan Sen
  • 1,654
  • 3
  • 16
  • 26
  • I found xctest here : /Applications/Xcode.app/Contents/Developer/usr/bin/xctest, seems you have to install XCode to have it. – Philippe Apr 29 '20 at 13:09
  • @Philippe oh so no other way? I was avoiding installing xcode – Sayan Sen Apr 29 '20 at 13:13
  • Looks like it's you specified just not an appropriate path with `-s`, should be `-s /Applications/Xcode.app/Contents/Developer` and that's it. – poige Jan 24 '22 at 05:12

3 Answers3

253

Assuming you already have Xcode installed:

Start Xcode, select "Preferences -> Locations". Chances are that your Command Line Tools are not set. Select the suggested Xcode-tools location and you are done.

Additional:

You could check with:

xcode-select -p

which tools are set, mine showed:

/Library/Developer/CommandLineTools

After the location in the preferences was set, it showed:

/Applications/Xcode.app/Contents/Developer

(as it should)

Robin Daugherty
  • 7,115
  • 4
  • 45
  • 59
BalancingRock
  • 2,686
  • 1
  • 12
  • 10
  • 10
    Although the accepted answer, it does not address the original constraint, being: "How to solve this error without installing XCode?". To answer that question, it is currently not possible to build/run/test SPM packages using only the Command Line Tools. – Jeremy Wiebe Dec 16 '21 at 22:40
  • 1
    @JeremyWiebe that's the common thing with SO. – poige Jan 24 '22 at 05:10
  • The actual answer is given by @mojtaba-hosseini – Juanjo Jul 08 '22 at 17:46
  • No, none of the answers given in this thread actually answered OP's question. They asked how to solve the problem without installing XCode. AFAIK, there's no way to build/run/test programs on MacOS without installing XCode. – bytrangle Aug 19 '22 at 13:49
72

Xcode -> Preferences (or command+,)

Preview

Locations tab -> Command Line tools section: Select a tool there and you are done.

Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278
8

Just a wrong path, all the stuff still can be done w/o invoking GUI:

~/% sudo xcode-select -s /Library/Developer/CommandLineTools
~/% sudo xcode-select -p                                    
/Library/Developer/CommandLineTools
~/% sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
~/% sudo xcode-select -p                                           
/Applications/Xcode.app/Contents/Developer

The latest -s command fixes xcrun: error: unable to find utility "xctest" …

poige
  • 1,562
  • 15
  • 12
  • Thanks. Running `sudo xcode-select -s /Applications/Xcode.app/Contents/Developer` fixed the problem. – Noah Sussman Aug 16 '22 at 14:21
  • Fixed my problem for building Unreal Engine - Fail to generate Xcode project with GenerateProjectFiles, WARNING: Exception while generating include data for UnrealEditor: Platform Mac is not a valid platform to build. Check that the SDK is installed properly. – jth_92 Apr 23 '23 at 16:44