Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

fnm is installed but node does not work in a new terminal

Errornode: command not found

Short answer

fnm only changes your PATH when your shell runs fnm env at startup. Add the setup line for your shell (PowerShell, cmd, bash or zsh), open a new terminal, then install a version and set it as default so every new terminal gets it. A missing PATH entry for fnm itself is the other cause.

  • Applies to fnm 1.x, Windows 11 PowerShell 7, bash, zsh
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check that fnm itself runs, then list the versions it has installed.

    fnm --version
    fnm list
  2. 2Match what you see, then jump to its fix

    1. 1fnm --version works, fnm list shows a version, but node is not found in a new terminalThe shell never runs fnm envFix
    2. 2On Windows, you cannot find the file to put the line in, or the setup line has no effectThe PowerShell profile file does not exist yetFix
    3. 3node works after fnm use in one terminal but is missing in the next oneNo version is set as the defaultFix
    4. 4Can't find version in dotfiles. Please provide a version manually to the command.fnm use is run in a folder with no version fileFix

What does the error look like?

  • node: command not found
  • 'node' is not recognized as an internal or external command
  • Can't find version in dotfiles. Please provide a version manually to the command.

Cause 1 of 4

The shell never runs fnm env

1Check

fnm sets up node by printing shell commands that your shell must evaluate at startup. Look for the line in your profile.

# bash / zsh
grep -n "fnm env" ~/.bashrc ~/.zshrc
# PowerShell
Select-String "fnm env" $profile

2Fix

Add the line for your shell. With --use-on-cd you only need to cd into a folder to switch versions. The README recommends passing --shell explicitly.

# ~/.bashrc
eval "$(fnm env --use-on-cd --shell bash)"
# ~/.zshrc
eval "$(fnm env --use-on-cd --shell zsh)"
# PowerShell profile
fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression

3Verify

Open a new terminal window (or reload the profile) and ask for the version.

node -v

Confirmed by github.com

Did this fix it?

Cause 2 of 4

The PowerShell profile file does not exist yet

1Check

A PowerShell profile is a file that may not exist. Its path differs between Windows PowerShell 5 and PowerShell 6+.

$profile
Test-Path $profile

2Fix

Create the profile if it is missing, open it and add the fnm line at the end.

if (-not (Test-Path $profile)) { New-Item $profile -Force }
Invoke-Item $profile

3Verify

Start a new PowerShell window and run node -v.

node -v

Confirmed by github.com

Did this fix it?

Cause 3 of 4

No version is set as the default

1Check

fnm use only changes the current terminal. A default version is what every new shell starts with.

fnm list

2Fix

Install a version and set it as default. fnm default is shorthand for fnm alias VERSION default.

fnm install 22
fnm default 22

3Verify

Open a new terminal and check the version.

node -v

Confirmed by github.com

Did this fix it?

Cause 4 of 4

fnm use is run in a folder with no version file

1Check

fnm use with no argument looks for a version in dotfiles of the project.

ls -a

2Fix

Pass the version, or add a version file to the project. The --install-if-missing option installs it when absent.

fnm use --install-if-missing 22

3Verify

Confirm the active version.

node -v

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Put the fnm setup line in your dotfiles repo so a new machine gets it with the rest.
  • Always set a default version right after installing fnm.
  • Commit a Node.js version file in each project so fnm use needs no argument.
  • On Windows, prefer PowerShell: the fnm README says cmd support is not entirely covered.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

npm install worked but the command is not found

bash: vite: command not found

npm puts a local install's command in the project's node_modules/.bin, which is not on your shell PATH, so run it with npx or from an npm script.

3 causes, each with a fix

Back end

npm or a script fails in WSL with /usr/bin/env: 'bash\r'

/usr/bin/env: 'bash\r': No such file or directory

The \r in the message is a Windows line ending at the end of a script's first line, so Linux looks for a program called bash followed by a carriage return.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.