nvm icon indicating copy to clipboard operation
nvm copied to clipboard

`tar (child): xz: Cannot exec: No such file or directory` on brew gnu `tar`

Open cdoane-evo opened this issue 2 years ago • 11 comments

Operating system and version:

Mac osx 12.3 - M1 max chip

nvm debug output:

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

nvm ls output:

        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

How did you install nvm?

install script in readme

What steps did you perform?

nvm install 18

What happened?

Probably easiest to just show the output:

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?

.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.

cdoane-evo avatar Feb 13 '23 20:02 cdoane-evo

Hmm, thanks, this is interesting. So you have xz in the PATH, but your gnu tar doesn't support -J?

ljharb avatar Feb 14 '23 02:02 ljharb

So you have xz in the PATH

I don't think so, which xz returns nothing. In all honesty I thought xz were flags passed to tar not a separate command, but in the output I do see now it's a command.

your gnu tar doesn't support -J

It appears that it does, at least looking at tar --help it does list out -J, --xz filter the archive through xz as a possible option.

However, when I run the command directly with the -J flag in my terminal it fails the same as in nvm:

➜  bin git:(v0.39.3) tar -Jxf 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

So it looks like the problem is with my system missing xz? Although that only matters for gnu-tar usage not "mac-tar"?

cdoane-evo avatar Feb 14 '23 17:02 cdoane-evo

without xz present, nvm shouldn't even try to download an xz archive - see https://github.com/nvm-sh/nvm/blob/edacf8275e3bef4a80971625ed89df13a9af427c/nvm.sh#L4288-L4340

ljharb avatar Feb 14 '23 18:02 ljharb

Wouldn't that which xz check on line 4308 only trigger if I wasn't on mac? Since my machine passes the if DARWIN check, but sw_vers -productVersion for me is 12.3 so it just skips over that which xz check later down.

Unless I read that wrong, which is possible. I'm not a bash expert nor an nvm expert haha


Edit: Although now I see # all node versions v4.0.0 and later have xz later on, which is for sure true. Maybe something wrong with my path setup?

cdoane-evo avatar Feb 14 '23 18:02 cdoane-evo

Simply edit nvm.sh on your machine and put return 1 at the top of nvm_supports_xz function. Afterward, restart the shell (⚠️ important) and install again. It is simple and fastest. Don't spend more time on this.

nvm_supports_xz() {
  return 1
  # .....
}

gotham8x avatar Jun 29 '23 03:06 gotham8x

I've also run into this issue setting up a new Mac today. I'm using GNU versions of common tools like tar, but haven't installed xz. For my machine I drop through the conditions in nvm_supports_xz at the beginning that are there to determine if the tarball can be unpacked in .xz format as my MacOS version is newer than 10.8. This means I get a 'true' result as the function continues to comparing whether or not the node version itself supports xz compression natively (IIUC) - this though is quite a different thing to being able to unpack the node binary in xz format.

There's a potential PR at https://github.com/nvm-sh/nvm/compare/master...tim-mit:nvm:issue3034?expand=1 which I've tested to work for me. Instead of downloading the .xz tarball the .gz one is used and things unpack successfully.

Happy to raise the PR if it's something you'd accept?

tim-mit avatar Aug 22 '23 12:08 tim-mit

That seems like it will work - so to reproduce on my Mac, i need to have GNU tar installed, but not xz? Don’t regular tar and xz both come on a stock Mac?

ljharb avatar Aug 22 '23 15:08 ljharb

Mac OS doesn't ship with the command line xz tool by default, no. The version of tar on Mac OS is a BSD licensed version and does actually support unpacking an .xz formatted tarball with the -J flag. So for a completly unmodified Mac the nvm tool works nicely and does successfully use the .xz version of the node download.

For me though (and I suspect quite a number of others) the first thing I do when setting up a Mac is install the GNU versions of command line tools and put them in front of the BSD tools on the path so they're used by default. I'm often jumping to linux machines and being able to rely on tools working the same way everywhere is less frustrating. Here's an example gist from someone showing how it can be done - https://gist.github.com/skyzyx/3438280b18e4f7c490db8a2a2ca0b9da.

As nvm is currently expecting that a Mac OS machine will be using BSD tools, but my path has GNU tools there and no xz command things break.

$ tar -xJf node-v16.20.2-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

tim-mit avatar Aug 27 '23 04:08 tim-mit

ah, gotcha - so i clearly installed xz specifically, but i don't have any of the GNU tools installed, so i haven't been able to reproduce this.

I'd love a PR that addresses this :-)

ljharb avatar Aug 27 '23 04:08 ljharb

This issue helped me understand what was happening with my fresh install of nvm versions - thank you folks.

Uncommenting the line PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH that sets gnu-tar as the default tar command did work for me as a workaround per @tim-mit's original comment.

laryro avatar Oct 30 '23 19:10 laryro