Skip to content

fix(downloads): fix fnm, Homebrew, n, and 0install snippets - #9351

Closed
rxliuli wants to merge 3 commits into
nodejs:mainfrom
rxliuli:fix/macos-download-snippets
Closed

rxliuli wants to merge 3 commits into
nodejs:mainfrom
rxliuli:fix/macos-download-snippets

Conversation

@rxliuli

@rxliuli rxliuli commented Nov 28, 2026 •

Copy link
Copy Markdown

Description

Fixes four broken download snippets discovered while testing the macOS and Linux shell install options end-to-end (see #9350):

  1. fnm.bash
    • On macOS, fnm's install script defaults to USE_HOMEBREW="true" and aborts when Homebrew isn't installed, even though macOS already has curl and unzip. Pass -s -- --force-no-brew on macOS so fnm installs its native macOS binary directly.
    • On macOS, fnm's installer places the binary in $HOME/Library/Application Support/fnm rather than Linux's $HOME/.local/share/fnm. Update the macOS PATH export accordingly so eval "$(fnm env)" works immediately in the same shell.
  2. brew.bash
    • Replace curl -o- ... | bash with Homebrew's official interactive invocation (/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)") so stdin stays attached to the TTY and sudo can prompt instead of failing with Insufficient permissions to install Homebrew to "/opt/homebrew".
    • Load brew shellenv immediately in the current shell AND persist it (idempotently via grep -qs) to ~/.zprofile on Apple Silicon macOS (/opt/homebrew/bin/brew) and ~/.bashrc on Linux (/home/linuxbrew/.linuxbrew/bin/brew), matching Homebrew's own "Next steps" instructions so brew and node keep working in newly opened terminals.
    • Prepend $(brew --prefix node@<major>)/bin to PATH immediately AND persist the resolved static path (idempotently via grep -qs, avoiding running brew --prefix on every shell startup) to ~/.zshrc (macOS) / ~/.bashrc (Linux) so keg-only LTS formulas (e.g. node@24, node@22) work in both the current shell and future terminals.
  3. n.bash
    • n-install updates ~/.bashrc / ~/.zshrc for future shells, but does not modify the current shell's environment. As a result, the subsequent node -v and npm -v commands immediately fail with command not found in the same shell on both Linux and macOS (after Xcode CLT).
    • Add # In lieu of restarting the shell: with export N_PREFIX="$HOME/n" and export PATH="$N_PREFIX/bin:$PATH" so node, npm, and n work immediately in the current shell.
  4. zeroinstall.bash
    • Change ./0install.sh to ./0install.sh install home so 0install is actually installed into $HOME/bin instead of printing usage help and exiting.
    • Follow-up note for maintainers on ARM64 (Apple Silicon macOS & Linux aarch64):
      • On Linux x86_64 (tested in ubuntu:24.04 --platform linux/amd64), ./0install.sh install home works end-to-end (0install 2.18, node v26.13.1, npm 11.20.0).
      • On Apple Silicon macOS without Rosetta 2, https://get.0install.net/0install-darwin-arm64-latest.tar.bz2 performs two 302 redirects (-> 0install-darwin-arm64-2.16.tar.bz2 -> 0install-darwin-x86_64-2.16.tar.bz2, Last-Modified: Sat, 26 Sep 2020). Running ./0install.sh install home fails with ./0install: Bad CPU type in executable (and because the extracted install.sh lacks set -e, it still prints OK and installs the x86_64 binary into ~/bin/0install, so every 0install add fails with bad CPU type in executable: 0install). Upstream https://get.0install.net/ defaults macOS users to brew install zero-install (Homebrew provides native Apple Silicon bottles for v2.18).
      • On Linux aarch64 (tested in ubuntu:24.04 aarch64), https://get.0install.net/0install-linux-aarch64-latest.tar.bz2 redirects to https://github.com/0install/0install/releases/download/v2.18/0install-linux-aarch64-2.18.tar.bz2, which returns HTTP 404.
      • This PR intentionally keeps only the minimal cross-Unix invocation fix (./0install.sh install home). Happy to also adjust ZEROINSTALL compatibility in apps/site/util/download/constants.json (e.g. dropping "MAC") if maintainers prefer.

Validation

  • Verified rendered output of fnm.bash, brew.bash, n.bash, and zeroinstall.bash across MAC, LINUX, and WIN using apps/site/util/interpreter.ts, plus bash -n and zsh -n syntax validation on both raw and comment-stripped outputs.
  • Clean macOS 27.2.1 (arm64) VM (no Homebrew, no Xcode CLT, no Rosetta 2, no ~/.zshrc), via real interactive login zsh PTY paste:
    • fnm.bash: tested v26.13.1 + npm, v24.22.3 + npm, v26.13.1 + pnpm, and v26.13.1 + yarn — installs cleanly and persists in a new login zsh session.
    • brew.bash: confirmed interactive sudo Password: prompt appears instead of stdin is not a TTY on clean VM; verified brew --prefix node@26 -> /opt/homebrew/opt/node and brew --prefix node@24 -> /opt/homebrew/opt/node@24; tested exact rendered macOS zsh persistence block (clean empty home -> ~/.zprofile + ~/.zshrc creation, new zsh -l -i lookup, and idempotent re-run deduplication).
    • zeroinstall.bash: reproduced the upstream 302 redirect to x86_64 (Bad CPU type in executable).
  • macOS (arm64) with Xcode CLT installed (isolated empty $HOME, no ~/.zshrc, real interactive zsh PTY):
    • n.bash: reproduced zsh: command not found: node before this fix; confirmed v26.13.1, 11.20.0, n ls, and new-shell persistence all pass after this fix.
  • Linux (ubuntu:24.04 Docker containers):
    • brew.bash (linux/amd64): tested full from-scratch Linuxbrew (Homebrew 7.0.17) + keg-only node@24 (v24.22.3, npm 11.19.1) end-to-end — verified same shell, new bash -ic shell persistence via ~/.bashrc, and idempotent re-run (grep -qs deduplication).
    • n.bash (aarch64): reproduced node: command not found before this fix; confirmed v26.13.1, 11.20.0, n ls, and new-shell persistence all pass after this fix.
    • fnm.bash (aarch64): confirmed v26.13.1, 11.20.0, and new-shell persistence pass.
    • zeroinstall.bash: confirmed end-to-end pass on linux/amd64 (0install 2.18, v26.13.1, 11.20.0) and confirmed upstream HTTP 404 on linux/aarch64.
  • Ran pnpm test, pnpm lint, pnpm lint:types, and pnpm prettier — all passed.

Related Issues

Refs #9350

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run pnpm format to ensure the code follows the style guide.
  • I have run pnpm test to check if all tests are passing.
  • I have run pnpm build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@rxliuli
rxliuli requested a review from a team as a code owner November 28, 2026 11:51
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nodejs-org Ready Ready Preview Nov 28, 2026 3:31pm UTC

Request Review

@rxliuli rxliuli changed the title fix(downloads): fix macOS fnm, Homebrew, and 0install snippets fix(downloads): fix fnm, Homebrew, n, and 0install snippets Nov 28, 2026

@avivkeller avivkeller left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned with the extreme added complexity to these commands, WDYT @nodejs/web

Comment on lines +4 to +14
# Add Homebrew to your PATH:
${props.os === 'MAC' ?
`if [ -x /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
grep -qs '/opt/homebrew/bin/brew shellenv' ~/.zprofile ~/.zshrc || { echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"'; } >> ~/.zprofile
fi` :
`if [ -x /home/linuxbrew/.linuxbrew/bin/brew ]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
grep -qs '/home/linuxbrew/.linuxbrew/bin/brew shellenv' ~/.bashrc ~/.profile || { echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"'; } >> ~/.bashrc
fi`
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Homebrew's own instructions do not include this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Homebrew's official install.sh does instruct users to do this on both Apple Silicon macOS and Linux — it does not add /opt/homebrew/bin or /home/linuxbrew/.linuxbrew/bin to PATH automatically. At the end of a fresh install, Homebrew prints:

Warning: /opt/homebrew/bin is not in your PATH.
==> Next steps:
- Run these commands in your terminal to add Homebrew to your PATH:
    echo >> ~/.zprofile
    echo 'eval "$(/opt/homebrew/bin/brew shellenv zsh)"' >> ~/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv zsh)"

Without running eval "$(... brew shellenv)" first, the very next line in this snippet (brew install node@26) fails immediately with zsh: command not found: brew on a clean Apple Silicon Mac or Linux machine. And without persisting it to ~/.zprofile / ~/.bashrc, both brew and node become command not found as soon as the user opens a new terminal.

Comment on lines +19 to +21
# Add Node.js to your PATH (required for keg-only LTS formulas):
export PATH="$(brew --prefix node@${props.release.major})/bin:$PATH"
grep -qs "$(brew --prefix node@${props.release.major})/bin" ${props.os === 'MAC' ? '~/.zshrc' : '~/.bashrc'} || { echo; echo 'export PATH="'"$(brew --prefix node@${props.release.major})/bin"':$PATH"'; } >> ${props.os === 'MAC' ? '~/.zshrc' : '~/.bashrc'}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels rather complex. Why isn't brew adding this to PATH by itself?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Homebrew's versioned LTS Node formulas (node@24, node@22, etc.) are keg-only (brew info node@24 explicitly reports: node@24 is keg-only, which means it was not symlinked into /opt/homebrew).

So when a user selects an LTS release like v24 on nodejs.org/en/download, brew install node@24 does not link node or npm into /opt/homebrew/bin (or /home/linuxbrew/.linuxbrew/bin). Without adding $(brew --prefix node@24)/bin to PATH, the node -v and npm -v commands right below it fail with command not found, and node remains unavailable in new terminals too.

'winget install Schniz.fnm' :
'curl -o- https://fnm.vercel.app/install | bash'
props.os === 'MAC' ?
'curl -o- https://fnm.vercel.app/install | bash -s -- --force-no-brew' :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding --force-no-brew invokes the same FORCE_INSTALL="true" as --force-install. This generates a warning. I do not think this should be the path we recommend users go down, and this goes against fnm's own guidance for installing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a clean macOS machine without Homebrew, running curl -o- https://fnm.vercel.app/install | bash aborts immediately:

Checking availability of curl... OK!
Checking availability of unzip... OK!
Checking availability of Homebrew (brew)... Missing!

Notice fnm.bash on nodejs.org is already broken on macOS for a second reason too: its PATH line exports $HOME/.local/share/fnm, whereas fnm's macOS installer actually installs into $HOME/Library/Application Support/fnm.

If nodejs.org prefers not to pass --force-no-brew, then the macOS fnm snippet effectively requires Homebrew as an undocumented prerequisite — in which case either stating Homebrew as a prerequisite (and using brew install fnm) or fixing the install method would be needed, because the current curl | bash snippet does not work on a clean Mac.

Comment on lines +4 to +6
# In lieu of restarting the shell:
export N_PREFIX="$HOME/n"
export PATH="$N_PREFIX/bin:$PATH"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not keen on this; I think we should instead advise restarting the shell, or re-sourcing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime instructions already cover what to do. I would not make this change.

For example:

===
CONTINUE (y/N)? y
-- Cloning https://github.com/tj/n to '/home/mike/n/n/.repo'...
-- Running local n installation to '/home/mike/n/bin'...
-- Shell initialization file '/home/mike/.bashrc' updated.
-- Installing helper scripts in '/home/mike/n/bin'...
-- Installing the requested Node.js version(s)...
   1 of 1: 26...
  installing : node-v26.13.1
       mkdir : /home/mike/n/n/versions/node/26.13.1
       fetch : https://nodejs.org/dist/v26.13.1/node-v26.13.1-linux-x64.tar.xz
     copying : node/26.13.1
   installed : v26.13.1 (with npm 11.20.0)
=== n successfully installed.
  The active Node.js version is: v26.13.1

  Run `n -h` for help.
  To update n later, run `n-update`.
  To uninstall, run `n-uninstall`.

  IMPORTANT: OPEN A NEW TERMINAL TAB/WINDOW or run `. /home/mike/.bashrc`
             before using n and Node.js.
===

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that nodejs.org/en/download renders n.bash, node.bash, and npm.bash together inside a single code block with a single "Copy to clipboard" button — just like nvm.bash, fnm.bash, and vp.bash, which all include an # In lieu of restarting the shell step specifically so the trailing node -v and npm -v verification lines in the same block actually succeed when pasted.

Right now, pasting the n block on Linux (or macOS with Xcode CLT) prints n's "OPEN A NEW TERMINAL" message and then immediately executes node -v and npm -v in the same shell, which fail with command not found. Adding the same # In lieu of restarting the shell exports brings n.bash in line with nvm.bash, fnm.bash, and vp.bash.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The observation that the script does not verify the installed versions of node & npm is correct. I would suggest handling this as a separate issue. The maintainer of n may be able to offer a better alternative.

An example of an unattended installation of n on Linux would be:

curl -L https://bit.ly/n-install | bash -s -- -y
. ~/.bashrc
node -v
npm -v

It's not actually clear from the instructions whether it's intended for the script to be executed by copying the whole thing and executing it in one go, or whether a user is expected to execute each one of the commands manually, one after another.

@MattIPv4

Copy link
Copy Markdown
Member

I'm concerned with the extreme added complexity to these commands

Agreed, and many of these changes seem to go against the installers' own installation guidance...

@MikeMcC399

Copy link
Copy Markdown
Member

I'm not sure that having changes to several Node.js version managers in one PR is a good idea for review. Maintainers for each of the version managers would ideally be involved in reviewing instructions for their version manager and that is also better handled in separate PRs.

@rxliuli

rxliuli commented Nov 29, 2026

Copy link
Copy Markdown
Author

Thanks for the reviews! I've replied inline to each specific point with the actual outputs from clean macOS (arm64) and Ubuntu 24.04 environments.

On the broader points:

  • Complexity vs. working on clean machines: I agree the snippets become longer when handling PATH setup and persistence — that's largely a reflection of what these installers actually require on a clean Apple Silicon Mac (no Homebrew, no Xcode CLT, no ~/.zshrc) or Linux machine. Right now, keeping the snippets short comes at the cost of 6 out of 7 macOS options failing when a user copies and pastes them as presented on nodejs.org/en/download (see screenshots and full logs in macOS download snippets: 6 of 7 options fail on a clean macOS machine (and all emit zsh '#' errors) #9350).
  • Splitting per version manager: Fair point from @MikeMcC399. Before splitting into separate PRs (or closing), could @nodejs/web clarify what the intended contract of the download code box is? Specifically:
    1. Are these snippets expected to work when copied and pasted on a clean OS install, or are prerequisites like Homebrew / Xcode CLT / manual shell restarts expected to be left to the user?
    2. If each installer snippet should stay strictly aligned with upstream's minimal command, would you prefer documenting prerequisites / removing broken combinations (e.g., 0install has no native ARM64 standalone binary on macOS or Linux aarch64), rather than adding shell glue here?

@ovflowd ovflowd left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing as the author is clearly not abiding by our AI policy -- It is clear that the author is not humanly reviewing our pushbacks and not understanding the gist of the issue. Author, feel free to reopen when ack'ing humanly.

@ovflowd ovflowd closed this Nov 29, 2026

This branch was successfully deployed

1 active deployment
Preview — 4cd44d25 Deployed Nov 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants