Cron Has No PATH or Environment Variables
Cron runs jobs with a bare environment — a short PATH (usually /usr/bin:/bin) and none of your ~/.bashrc or ~/.profile variables. Commands that work in your shell fail in cron with 'command not found'. Fix it by using absolute paths or setting the variables in the crontab.
Set variables at the top of the crontab
Run crontab -e and add lines before your jobs:
PATH=/usr/local/bin:/usr/bin:/binHOME=/home/youSHELL=/bin/bash
These apply to every job below them.
Or use absolute paths
Instead of node app.js, write /usr/local/bin/node /home/you/app.js. Find the full path with which node.
Source your profile for a full env
If a job needs your login environment, run it through a shell that sources it: * * * * * /bin/bash -lc 'source ~/.profile && myscript'. The -l makes bash a login shell.
Why cron differs from your terminal
Interactive shells read ~/.bashrc and ~/.profile. Cron does not — it uses a minimal, non-interactive environment, which is why 'it works when I run it manually' but fails on schedule.
FAQ
Why is PATH empty in cron?
Cron uses a minimal environment and does not source ~/.bashrc or ~/.profile. Its default PATH is usually just /usr/bin:/bin, so commands elsewhere aren't found.
How do I set environment variables for cron?
Add them at the top of the crontab (e.g. PATH=..., HOME=...) with crontab -e. They apply to all jobs below. Or source your profile inside the command.
Why does my script work manually but fail in cron?
Your interactive shell loads env vars and PATH that cron doesn't. Use absolute paths to binaries or set the needed variables in the crontab.