39

The first time I run Terminal or start SmartGit either one is slow to start, taking up to ~30 seconds. When I look at the status bar for Terminal I see that it is stuck running some xcodebuild command. Not sure what exactly the command is.

Does anyone know how to view which commands Terminal runs on startup? Or if anyone else had this issue? I think it is related to this question but the slow down is only first the first startup of Terminal and for ~30 seconds. Not the 2-3 seconds users reported. Subsequent runs or commands work normally.

Dhananjay Suresh
  • 1,030
  • 1
  • 14
  • 28
  • I switched from Bash to Zsh and the problem went away. I guess something was in the bash config causing the slowdown but still don't know what. – Dhananjay Suresh Apr 20 '21 at 15:23
  • 1
    im having this problem too, since i switched to bigsur – anarchy Jun 04 '21 at 08:43
  • d= (-_- ) Same here, don't dive up! - running `xcodebuild -find clang` takes 43 seconds before echoing: `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang` (I will switch to static path till Apple fixes that) – Top-Master Jun 18 '21 at 10:24
  • Solution, if you are the developer of the tool (like I was) simply use `/usr/bin/xcode-select -p` output as path-prefix, instead of full-path using `xcodebuild` tool (which takes less than one second). – Top-Master Jun 18 '21 at 10:34

5 Answers5

32

Switch Apple Git to Git, the problem will go away.
Run brew install git to do it.
Relate link: https://blog.smittytone.net/2021/05/21/how-to-fix-xcodebuild-macos-terminal-slow-downs/

Another option is to accept the Xcode License

sudo xcodebuild -license accept

You can find this referring to the reference in the linked article.

Community
  • 1
  • 1
Quanuanc
  • 345
  • 3
  • 4
8

I've tried with sudo xcodebuild -license accept but at start the console is still very slow and, after a reboot, I have to wait at least 15s to see the terminal.

Looking around I found out that somehow it's nvm that needs xcodebuild.

The slowdown was fixed changing the nvm default to system

nvm alias default system
freedev
  • 25,946
  • 8
  • 108
  • 125
6

This worked for me:

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
sudo xcode-select -switch /Library/Developer/CommandLineTools

https://ospfranco.com/post/2021/08/05/fix-slow-terminal-start-(hanging-xcodebuild)/

StefanoF
  • 61
  • 1
  • 1
5

Try xcodebuild -runFirstLaunch

Then after it is complete, open up 2 new Terminal tabs.

Worked for me on macOS 12.6.

I found this solution over here: https://superuser.com/a/1742463/98148

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
0

context:

I used some of the other answers here, but they didn't actually fix it for me, as initially I didn't realize it only is slow for the first startup per restart. Following on the comment relating the problem to nvm, I came across an nvm GitHub issue regarding this problem. Their solution which works for me across restarts is:

OK! So it appears adding this line to ~/.zshrc above the nvm lines works around the problem for now:

alias manpath=false

solution (workaround):

Add the alias manpath=false line before sourcing nvm.sh in ~/.zshrc:

alias manpath=false
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

Now restart (or however you wish to trigger the ~/.zshrc file being resourced).

notes:

This agrees with the fact that it happens per restart, i.e., per ~/.zshrc execution. Also, for me I also have a non-system default for nvm, which corresponds to freedev's answer, but I need a v19+ default node version for isomorphic webcrypto, so that answer isn't acceptable.

You can read through the nvm GitHub issue for a more in depth analysis. I would recommend giving the issue a thumbs up, because the rep from nvm seemed to be incredulous that it was not a localized issue to that issue's OP. But this question has been upvoted 35 times, which clearly shows this is not the case.

wraiford
  • 181
  • 1
  • 5