Repository: nvm
Issue: `tar (child): xz: Cannot exec: No such file or directory` on brew gnu `tar`
Labels: 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:
Mac osx 12.3 - M1 max chip
#### `nvm debug` output:
<details>
<!-- do not delete the following blank line -->

```sh
nvm --version: v0.39.3
$TERM_PROGRAM: iTerm.app
$SHELL: /bin/zsh
$SHLVL: 1
whoami: 'me'
${HOME}: /Users/me
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${NVM_DIR}/versions/node/v18.14.0/bin:${HOME}/tools/current_jdk/bin:${HOME}//tools:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/gnu-getopt/bin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/gnu-indent/libexec/gnubin:/opt/homebrew/opt/coreutils/libexec/gnubin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:${HOME}/Library/Application Support/JetBrains/Toolbox/scripts
$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.4.0 Darwin Kernel Version 21.4.0: <timestamp removed> arm64 arm Darwin'
checksum binary: 'sha256sum'
OS version: macOS 12.3 21E230
awk: /opt/homebrew/bin/awk, GNU Awk 5.2.1, API 3.2, (GNU MPFR 4.1.0-p13, GNU MP 6.2.1)
curl: /usr/bin/curl, curl 7.79.1 (x86_64-apple-darwin21.0) libcurl/7.79.1 (SecureTransport) LibreSSL/3.3.5 zlib/1.2.11 nghttp2/1.45.1
wget: /opt/homebrew/bin/wget, GNU Wget 1.21.3 built on darwin21.3.0.
sed: /opt/homebrew/opt/gnu-sed/libexec/gnubin/sed
cut: /opt/homebrew/opt/coreutils/libexec/gnubin/cut
basename: /opt/homebrew/opt/coreutils/libexec/gnubin/basename
rm: /opt/homebrew/opt/coreutils/libexec/gnubin/rm
mkdir: /opt/homebrew/opt/coreutils/libexec/gnubin/mkdir
xargs: /opt/homebrew/opt/findutils/libexec/gnubin/xargs
git: /usr/bin/git, git version 2.32.1 (Apple Git-133)
ls: cannot access 'grep:': No such file or directory
grep: grep: aliased to grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}), grep (GNU grep) 3.8
nvm current: v18.14.0
which node: ${NVM_DIR}/versions/node/v18.14.0/bin/node
which iojs: iojs not found
which npm: ${NVM_DIR}/versions/node/v18.14.0/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v18.14.0
npm root -g: ${NVM_DIR}/versions/node/v18.14.0/lib/node_modules
```
</details>

#### `nvm ls` output:
<details>
<!-- do not delete the following blank line -->

```sh
        v17.9.1
->     v18.14.0
default -> 17 (-> v17.9.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.14.0) (default)
stable -> 18.14 (-> v18.14.0) (default)
lts/* -> lts/hydrogen (-> v18.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.12 (-> N/A)
lts/fermium -> v14.21.2 (-> N/A)
lts/gallium -> v16.19.0 (-> N/A)
lts/hydrogen -> v18.14.0
```
</details>

#### How did you install `nvm`?
<!-- (e.g. install script in readme, Homebrew) -->
install script in readme
#### What steps did you perform?
`nvm install 18`
#### What happened?
Probably easiest to just show the output:
```sh
Downloading and installing node v18.14.0...
Local cache found: ${NVM_DIR}/.cache/bin/node-v18.14.0-darwin-arm64/node-v18.14.0-darwin-arm64.tar.xz
Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/bin/node-v18.14.0-darwin-arm64/node-v18.14.0-darwin-arm64.tar.xz
tar (child): xz: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
mv: cannot stat '/Users/me/.nvm/.cache/bin/node-v18.14.0-darwin-arm64/files/*': No such file or directory
Binary download failed, trying source.
Clang v3.5+ detected! CC or CXX not specified, will use Clang as C/C++ compiler!
Local cache found: ${NVM_DIR}/.cache/src/node-v18.14.0/node-v18.14.0.tar.xz
Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/src/node-v18.14.0/node-v18.14.0.tar.xz
tar (child): xz: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
nvm: install v18.14.0 failed!
```

As I note below, I am using https://formulae.brew.sh/formula/gnu-tar instead of the mac built-in version. If I un-comment the line for adding gnu-tar to my path `nvm` works as expected.

So I'm **not blocked** by this anymore since I only install new node versions... rarely. Wanted to bring it up since I didn't notice this in other issues.

output of `tar --version` (truncated license stuff): `tar (GNU tar) 1.34`
#### What did you expect to happen?
Install works with no errors
#### Is there anything in any of your profile files that modifies the `PATH`?
<!--  (e.g. `.bashrc`, `.bash_profile`, `.zshrc`, etc) -->
`.zshrc` does, notably `export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"` to add `gnu-tar` to the path instead of the default `tar`.