A script fails with /usr/bin/env: node: No such file or directory
/usr/bin/env: node: No such file or directoryShort 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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
command -v node prints nothing in every shell, including a fresh login.Node.js is not installed on this machineFix - 2
node 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
Git 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
- 1
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/node2Fix
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 nodejs3Verify
Check the version in a new shell.
node -vConfirmed by github.com
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 nvm2Fix
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 node3Verify
A new terminal should find both.
command -v nvm
node -vConfirmed by github.com
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.sh2Fix
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
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
Azure App Service on Linux restarts the container and the site never starts
The container restarts again and again and the site returns an application error
App Service sends a warmup request to the container and restarts it if no HTTP answer comes back in time.
5 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
A native Node.js module fails on AWS Lambda with invalid ELF header
Error: /var/task/node_modules/<package>/build/Release/<name>.node: invalid ELF header
Lambda loads native addons on Linux, so a .node file built on macOS or Windows is not a valid Linux ELF file there.
3 causes, each with a fixServers
nginx 502 Bad Gateway in front of a Node.js app
connect() failed (111: Connection refused) while connecting to upstream
A 502 means nginx reached for your Node.js app and got nothing usable back.
5 causes, each with a fixServers
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 fixServers
Pages load unstyled because /_next/static files return 404 behind nginx
GET https://example.com/_next/static/chunks/main.js 404 (Not Found)
The browser asks for /_next/static/..
3 causes, each with a fix