Home/Guides/How to manage Node versions with nvm or fnm on a remote Mac mini

How to manage Node versions with nvm or fnm on a remote Mac mini

Updated · airankrush

What this guide covers

When you finish, each project switches to its own Node version when you enter its directory, and background jobs can find node too. You need: the command line tools installed, plus Homebrew if you choose fnm.

Steps

  1. Pick one: nvm or fnm

    Both install Node inside your own user directory. Neither needs an administrator password or touches system directories, which suits a rented machine. nvm has more users and fuller documentation, and it is a set of shell functions. fnm is a single executable that you can install and upgrade with Homebrew. Install only one, because two tools managing PATH at the same time will fight each other. We do not recommend brew install node as your only source of Node: brew upgrade would replace Node for every project at once.

  2. Installing nvm: copy the command from the official README

    The nvm install command contains the current version tag, which changes with each release, so we do not paste it here. Copy the latest line from the official nvm README. The README has two notes that matter on macOS: install the Xcode Command Line Tools first, and because the system has no ~/.zshrc by default, run touch ~/.zshrc before the install script, otherwise it has nowhere to write its config. The README also states that installing nvm through Homebrew is not supported.

  3. Or install fnm

    Following the official fnm README:

    brew install fnm
    echo 'eval "$(fnm env --use-on-cd --shell zsh)"' >> ~/.zshrc

    --use-on-cd switches versions automatically when you enter a directory that has a version file. Open a new terminal window after writing this before you continue.

  4. Install the LTS release and make it the default

    nvm: nvm install --lts, then nvm alias default node. fnm: fnm install --lts, then set the default with fnm default <version>. After that, node -v and npm -v should each print a version. We give no specific version number here: use whichever major version your project's own documentation asks for.

  5. Put a version file in every project

    Put a .nvmrc at the top level of the project (its content is just the version number) and commit it. With nvm, run nvm use after entering the directory to read it. fnm with --use-on-cd reads .nvmrc or .node-version automatically. Your own computer and the remote Mac then run the same version, which removes one variable when you are working out why something runs locally but not remotely.

  6. Use the full path to node in background jobs

    nvm and fnm both take effect through ~/.zshrc. Scheduled jobs and jobs that start at login do not read that file, so they report that node cannot be found. Most jobs on a remote machine run unattended, so you are more likely to hit this than on your own computer. The fix: run which node in the terminal and write the full path into the job config, or have the job start through zsh -lic 'your command'. The path changes when you upgrade Node, so remember to update it.

  7. Keep global packages in your user directory

    With a Node installed by a version manager, the global package directory belongs to your own account. npm install -g does not need elevated privileges and should not be run with them. If you get a permissions error, the Node in use is not the one from the version manager. Check with which node first instead of changing the ownership of system directories. Global packages are separate for each version, so you need to reinstall them after switching.

FAQ

Package installs fail with "too many requests" or download errors. Why?

The public exit of this machine may be shared with other machines, so anonymous requests can hit upstream rate limits sooner, and speed also depends on the line and its load. Retry first. For private registries, log in with your own token and then install.

How do I install pnpm or yarn?

Corepack, which ships with Node, and each tool's official docs explain how; follow the official docs. The principle is the same: install into your user directory, and do not change system directories to install a package manager.

Should I remove old Node versions?

Yes. Every version takes disk space, along with its global packages. Review them with nvm ls or fnm list, and remove the ones you no longer use with nvm uninstall <version> or fnm uninstall <version>.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All guides