Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A script fails with /usr/bin/env: node: No such file or directory

Error/usr/bin/env: node: No such file or directory

Short answer

The script starts with #!/usr/bin/env node, so env searches your PATH for a program named node and finds none. Either Node.js is not installed, or it is installed through nvm and the shell running the script never loaded it. Install Node.js system-wide, or load nvm in that environment.

  • Applies to Node.js 22, Ubuntu 24.04, nvm 0.40
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the same shell that fails whether it can see node at all. If the command prints nothing, the cause is PATH or a missing install.

    command -v node
    echo "$PATH"
  2. 2Match what you see, then jump to its fix

    1. 1command -v node prints nothing in every shell, including a fresh login.Node.js is not installed on this machineFix
    2. 2node works in your terminal, but a cron job, a script run by another user or a service says env cannot find it.Node.js lives in nvm, and this shell never loaded nvmFix
    3. 3Git hooks (for example Husky ones) pass on the command line but fail with this message when you commit from a GUI.A Git app or editor was started without a shellFix

What does the error look like?

  • /usr/bin/env: node: No such file or directory
  • /usr/bin/env: 'node': No such file or directory

Cause 1 of 3

Node.js is not installed on this machine

1Check

Look for any Node.js installation on the disk.

node -v
ls /usr/bin/node /usr/local/bin/node

2Fix

Install Node.js from the NodeSource repository, with the setup script for the release line you want (22.x here).

sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs

3Verify

Check the version in a new shell.

node -v

Confirmed by github.com

Did this fix it?

Cause 2 of 3

Node.js lives in nvm, and this shell never loaded nvm

1Check

nvm is a shell function loaded from your profile, not a program on the system PATH. Confirm that it is loaded in this shell. which does not work for it.

command -v nvm

2Fix

Make sure the profile has the two lines that load nvm, then open a new terminal. For a non-interactive job, source nvm.sh at the top of the script before the command that needs node.

# ~/.bashrc, ~/.profile or ~/.zshrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

# then pick the version for new shells
nvm alias default node

3Verify

A new terminal should find both.

command -v nvm
node -v

Confirmed by github.com

Did this fix it?

Cause 3 of 3

A Git app or editor was started without a shell

1Check

Apps launched outside a terminal may not load version managers such as nvm, so node is not on PATH for the hook.

cat ~/.config/husky/init.sh

2Fix

For Husky hooks, put the version manager's start-up lines in ~/.config/husky/init.sh, which Husky reads before each hook.

# ~/.config/husky/init.sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

3Verify

Commit again from the GUI.

git commit --allow-empty -m "hook test"

Confirmed by typicode.github.io

Did this fix it?

How do I stop it coming back?

  • Pick one way to install Node.js on a server (package repository or nvm) and write it in the server notes.
  • In cron and service files, give the full path to node instead of relying on PATH.
  • After an install, open a new shell and run node -v before you trust it.

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

Servers

nginx gives up waiting for the app and returns 504

upstream timed out (110: Connection timed out) while reading response header from upstream

nginx returns 504 when the app behind it takes the request but sends nothing back within proxy_read_timeout (60 seconds by default), or when the connection cannot be opened in time.

5 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.