nvm: Slow terminal startup running xcodebuild if not using system node

Operating system and version:

Latest Mac OS Monterey 12.2.1, but I’ve seen this on earlier OS versions too.

nvm debug output:

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

How did you install nvm?

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 or here 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?

No

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 8
  • Comments: 16 (8 by maintainers)

Most upvoted comments

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

alias manpath=false

I believe the Chrome beachball I was getting was because I had the devtools up which probably use a shell environment. Of course, nvm users are quite likely to have Chrome devtools running.

Obviously this is an ugly workaround and needs to be addressed in the default configuration as again, many others have run into this problem before me. Thanks for your help in finding this workaround.

Update: OK disregard the Chrome report that is probably something else. Anyway my terminals launch fast now with default to stable, thanks.

Dev tools definitely don’t have any shell environment, but I’m glad you found a workaround.

@beenotung not yet identified, and thus not yet fixable.

If you change your default shell to “not zsh”, do you still see this problem? I’m wondering if it’s some kind of zsh-specific manpath-related bug.

I’m running GNU bash, version 5.2.26 as my default and had the exact same issue. alias manpath=false seems to have fixed the issue for me also.

@beenotung not yet identified, and thus not yet fixable.

If you change your default shell to “not zsh”, do you still see this problem? I’m wondering if it’s some kind of zsh-specific manpath-related bug.

nvm is explicitly unsupported when installed with homebrew; what happens when you install it with the supported method?

Separately, do you have the xcode command line tools installed? That’s always the first step on any Mac - run curl, for example, and it should prompt you to do so (assuming you haven’t shadowed it with something from homebrew)