Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| # 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` | ||
| } |
There was a problem hiding this comment.
Why is this needed? Homebrew's own instructions do not include this.
There was a problem hiding this comment.
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.
| # 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'} |
There was a problem hiding this comment.
This feels rather complex. Why isn't brew adding this to PATH by itself?
There was a problem hiding this comment.
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' : |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| # In lieu of restarting the shell: | ||
| export N_PREFIX="$HOME/n" | ||
| export PATH="$N_PREFIX/bin:$PATH" |
There was a problem hiding this comment.
Not keen on this; I think we should instead advise restarting the shell, or re-sourcing?
There was a problem hiding this comment.
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.
===There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 -vIt'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.
Agreed, and many of these changes seem to go against the installers' own installation guidance... |
|
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. |
|
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:
|
Description
Fixes four broken download snippets discovered while testing the macOS and Linux shell install options end-to-end (see #9350):
fnm.bashfnm's install script defaults toUSE_HOMEBREW="true"and aborts when Homebrew isn't installed, even though macOS already hascurlandunzip. Pass-s -- --force-no-brewon macOS sofnminstalls its native macOS binary directly.fnm's installer places the binary in$HOME/Library/Application Support/fnmrather than Linux's$HOME/.local/share/fnm. Update the macOSPATHexport accordingly soeval "$(fnm env)"works immediately in the same shell.brew.bashcurl -o- ... | bashwith Homebrew's official interactive invocation (/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)") sostdinstays attached to the TTY andsudocan prompt instead of failing withInsufficient permissions to install Homebrew to "/opt/homebrew".brew shellenvimmediately in the current shell AND persist it (idempotently viagrep -qs) to~/.zprofileon Apple Silicon macOS (/opt/homebrew/bin/brew) and~/.bashrcon Linux (/home/linuxbrew/.linuxbrew/bin/brew), matching Homebrew's own "Next steps" instructions sobrewandnodekeep working in newly opened terminals.$(brew --prefix node@<major>)/bintoPATHimmediately AND persist the resolved static path (idempotently viagrep -qs, avoiding runningbrew --prefixon 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.n.bashn-installupdates~/.bashrc/~/.zshrcfor future shells, but does not modify the current shell's environment. As a result, the subsequentnode -vandnpm -vcommands immediately fail withcommand not foundin the same shell on both Linux and macOS (after Xcode CLT).# In lieu of restarting the shell:withexport N_PREFIX="$HOME/n"andexport PATH="$N_PREFIX/bin:$PATH"sonode,npm, andnwork immediately in the current shell.zeroinstall.bash./0install.shto./0install.sh install homeso0installis actually installed into$HOME/bininstead of printing usage help and exiting.aarch64):x86_64(tested inubuntu:24.04 --platform linux/amd64),./0install.sh install homeworks end-to-end (0install 2.18,node v26.13.1,npm 11.20.0).https://get.0install.net/0install-darwin-arm64-latest.tar.bz2performs two302redirects (-> 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 homefails with./0install: Bad CPU type in executable(and because the extractedinstall.shlacksset -e, it still printsOKand installs thex86_64binary into~/bin/0install, so every0install addfails withbad CPU type in executable: 0install). Upstreamhttps://get.0install.net/defaults macOS users tobrew install zero-install(Homebrew provides native Apple Silicon bottles for v2.18).aarch64(tested inubuntu:24.04aarch64),https://get.0install.net/0install-linux-aarch64-latest.tar.bz2redirects tohttps://github.com/0install/0install/releases/download/v2.18/0install-linux-aarch64-2.18.tar.bz2, which returns HTTP 404../0install.sh install home). Happy to also adjustZEROINSTALLcompatibility inapps/site/util/download/constants.json(e.g. dropping"MAC") if maintainers prefer.Validation
fnm.bash,brew.bash,n.bash, andzeroinstall.bashacrossMAC,LINUX, andWINusingapps/site/util/interpreter.ts, plusbash -nandzsh -nsyntax validation on both raw and comment-stripped outputs.~/.zshrc), via real interactive loginzshPTY paste:fnm.bash: testedv26.13.1 + npm,v24.22.3 + npm,v26.13.1 + pnpm, andv26.13.1 + yarn— installs cleanly and persists in a new loginzshsession.brew.bash: confirmed interactivesudoPassword:prompt appears instead ofstdin is not a TTYon clean VM; verifiedbrew --prefix node@26->/opt/homebrew/opt/nodeandbrew --prefix node@24->/opt/homebrew/opt/node@24; tested exact rendered macOSzshpersistence block (clean empty home ->~/.zprofile+~/.zshrccreation, newzsh -l -ilookup, and idempotent re-run deduplication).zeroinstall.bash: reproduced the upstream302redirect tox86_64(Bad CPU type in executable).$HOME, no~/.zshrc, real interactivezshPTY):n.bash: reproducedzsh: command not found: nodebefore this fix; confirmedv26.13.1,11.20.0,n ls, and new-shell persistence all pass after this fix.ubuntu:24.04Docker containers):brew.bash(linux/amd64): tested full from-scratch Linuxbrew (Homebrew 7.0.17) + keg-onlynode@24(v24.22.3,npm 11.19.1) end-to-end — verified same shell, newbash -icshell persistence via~/.bashrc, and idempotent re-run (grep -qsdeduplication).n.bash(aarch64): reproducednode: command not foundbefore this fix; confirmedv26.13.1,11.20.0,n ls, and new-shell persistence all pass after this fix.fnm.bash(aarch64): confirmedv26.13.1,11.20.0, and new-shell persistence pass.zeroinstall.bash: confirmed end-to-end pass onlinux/amd64(0install 2.18,v26.13.1,11.20.0) and confirmed upstream HTTP 404 onlinux/aarch64.pnpm test,pnpm lint,pnpm lint:types, andpnpm prettier— all passed.Related Issues
Refs #9350
Check List
pnpm formatto ensure the code follows the style guide.pnpm testto check if all tests are passing.pnpm buildto check if the website builds without errors.