Repository: nvm
Issue: Slow terminal startup running xcodebuild if not using system node
Labels: shell: zsh,OS: Mac OS,needs followup,pull request wanted

<!-- Thank you for being interested in nvm! Please help us by filling out the following form if you‘re having trouble. If you have a feature request, or some other question, please feel free to clear out the form. Thanks! -->

#### Operating system and version:

Latest Mac OS Monterey 12.2.1, but I've seen this on earlier OS versions too.

#### `nvm debug` output:
<details>
<!-- do not delete the following blank line -->

```sh
nvm --version: v0.39.1
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/zsh
$SHLVL: 1
whoami: '[me]'
${HOME}: /Users/[me]
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${NVM_DIR}/versions/node/v16.14.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:${HOME}/Library/Android/sdk/platform-tools
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.8 (x86_64-apple-darwin21.0)'
uname -a: 'Darwin 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64'
checksum binary: 'shasum'
OS version: macOS 12.2.1 21D62
curl: /usr/bin/curl, curl 7.77.0 (x86_64-apple-darwin21.0) libcurl/7.77.0 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.42.0
wget: not found
sed: /usr/bin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir
xargs: /usr/bin/xargs
git: /usr/local/bin/git, git version 2.35.1
grep: /usr/bin/grep, grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
awk: /usr/bin/awk, awk version 20200816
nvm current: v16.14.0
which node: ${NVM_DIR}/versions/node/v16.14.0/bin/node
which iojs: iojs not found
which npm: ${NVM_DIR}/versions/node/v16.14.0/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v16.14.0
npm root -g: ${NVM_DIR}/versions/node/v16.14.0/lib/node_modules```
</details>

#### `nvm ls` output:
<details>
<!-- do not delete the following blank line -->

```sh
       v12.22.3
       v14.17.3
->     v16.14.0
         system
default -> stable (-> v16.14.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.14.0) (default)
stable -> 16.14 (-> v16.14.0) (default)
lts/* -> lts/gallium (-> v16.14.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.10 (-> N/A)
lts/fermium -> v14.19.0 (-> N/A)
lts/gallium -> v16.14.0
```
</details>

#### How did you install `nvm`?
<!-- (e.g. install script in readme, Homebrew) -->
Homebrew

#### What steps did you perform?
`nvm alias default stable`

or, if starting terminal with nvm default set to system, `nvm use stable`

#### What happened?

Every time I start the terminal **for the first time** after an OS reboot, or set nvm to use the non-system version of node **for the first time**, the terminal freezes for a minute with `xcodebuild` shown in its title bar. This actually slows down many aspects of my computer, including Chrome browser. It's a well-known problem: see [here](https://ospfranco.com/post/2021/08/05/fix-slow-terminal-start-(hanging-xcodebuild)/) or [here](https://stackoverflow.com/questions/65846945/terminal-slow-to-start-first-time-due-to-xcodebuild) for examples of others reporting this. But I found no github issue on it so I posted this one.

The workaround is to use `nvm alias default system` and only use `nvm use stable` (or whichever other version is desired) when needed, though this will also run xcodebuild for a seeming eternity the first time you do it. I did other workaround ideas such as `brew install git`, `brew install zsh`, `sudo xcodebuild -license accept`, and none got rid of this serious lag.

#### What did you expect to happen?

Should run promptly every startup, as the system version does.

#### Is there anything in any of your profile files that modifies the `PATH`?
<!--  (e.g. `.bashrc`, `.bash_profile`, `.zshrc`, etc) -->

No