Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cdoane-evo opened this issue Feb 13, 2023 · 11 comments · May be fixed by #3178
Open

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

cdoane-evo opened this issue Feb 13, 2023 · 11 comments · May be fixed by #3178
Labels
pull request wanted This is a great way to contribute! Help us out :-D

Comments

@cdoane-evo
Copy link

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.

@ljharb
Copy link
Member

ljharb commented Feb 14, 2023

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

@cdoane-evo
Copy link
Author

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"?

@ljharb
Copy link
Member

ljharb commented Feb 14, 2023

without xz present, nvm shouldn't even try to download an xz archive - see

nvm/nvm.sh

Lines 4288 to 4340 in edacf82

nvm_supports_xz() {
if [ -z "${1-}" ]; then
return 1
fi
local NVM_OS
NVM_OS="$(nvm_get_os)"
if [ "_${NVM_OS}" = '_darwin' ]; then
local MACOS_VERSION
MACOS_VERSION="$(sw_vers -productVersion)"
if nvm_version_greater "10.9.0" "${MACOS_VERSION}"; then
# macOS 10.8 and earlier doesn't support extracting xz-compressed tarballs with tar
return 1
fi
elif [ "_${NVM_OS}" = '_freebsd' ]; then
if ! [ -e '/usr/lib/liblzma.so' ]; then
# FreeBSD without /usr/lib/liblzma.so doesn't support extracting xz-compressed tarballs with tar
return 1
fi
else
if ! command which xz >/dev/null 2>&1; then
# Most OSes without xz on the PATH don't support extracting xz-compressed tarballs with tar
# (Should correctly handle Linux, SmartOS, maybe more)
return 1
fi
fi
# all node versions v4.0.0 and later have xz
if nvm_is_merged_node_version "${1}"; then
return 0
fi
# 0.12x: node v0.12.10 and later have xz
if nvm_version_greater_than_or_equal_to "${1}" "0.12.10" && nvm_version_greater "0.13.0" "${1}"; then
return 0
fi
# 0.10x: node v0.10.42 and later have xz
if nvm_version_greater_than_or_equal_to "${1}" "0.10.42" && nvm_version_greater "0.11.0" "${1}"; then
return 0
fi
case "${NVM_OS}" in
darwin)
# darwin only has xz for io.js v2.3.2 and later
nvm_version_greater_than_or_equal_to "${1}" "2.3.2"
;;
*)
nvm_version_greater_than_or_equal_to "${1}" "1.0.0"
;;
esac
return $?
}

@cdoane-evo
Copy link
Author

cdoane-evo commented Feb 14, 2023

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?

@gotham8x

This comment was marked as outdated.

tim-mit added a commit to tim-mit/nvm that referenced this issue Aug 22, 2023
GNU tar doesn't support using the -J flag required to unpack
xz-compressed tarballs. This change means that anyone using
GNU tar on MacOS will instead use gz-compressed tarballs.

Fixes nvm-sh#3034
tim-mit added a commit to tim-mit/nvm that referenced this issue Aug 22, 2023
GNU tar doesn't support using the -J flag required to unpack
xz-compressed tarballs. This change means that anyone using
GNU tar on MacOS will instead use gz-compressed tarballs.

Fixes nvm-sh#3034
tim-mit added a commit to tim-mit/nvm that referenced this issue Aug 22, 2023
GNU tar doesn't support using the -J flag required to unpack
xz-compressed tarballs when xv isn't installed. Check for this
scenario and fallback to using gzip-compressed tarballs.

Fixes nvm-sh#3034
@tim-mit
Copy link

tim-mit commented Aug 22, 2023

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?

@ljharb
Copy link
Member

ljharb commented Aug 22, 2023

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?

@tim-mit
Copy link

tim-mit commented Aug 27, 2023

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

@ljharb
Copy link
Member

ljharb commented Aug 27, 2023

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 :-)

tim-mit added a commit to tim-mit/nvm that referenced this issue Aug 27, 2023
GNU tar doesn't support using the -J flag required to unpack
xz-compressed tarballs when xv isn't installed. Check for this
scenario and fallback to using gzip-compressed tarballs.

Fixes nvm-sh#3034
@laryro
Copy link

laryro commented Oct 30, 2023

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.

@ljharb ljharb added the pull request wanted This is a great way to contribute! Help us out :-D label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull request wanted This is a great way to contribute! Help us out :-D
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@ljharb @tim-mit @laryro @gotham8x @cdoane-evo and others