Troubleshooting Guide

Cron Command Not Found: How to Fix PATH Issues

Your command works in terminal but cron says "command not found." Here's why and how to fix it.

Why This Happens

When you open a terminal, your shell loads configuration files (.bashrc, .profile) that set up your PATH with directories like /usr/local/bin, /home/user/.local/bin, etc.

Cron doesn't load these files. It uses a minimal PATH:

/usr/bin:/bin

So when you run node script.js in terminal, bash finds node at /usr/local/bin/node. But cron can't find it because /usr/local/bin isn't in its PATH.

Solution 1: Use Absolute Paths (Recommended)

The simplest fix: use the full path to every command.

# Find the full path to your command
which node
# /usr/local/bin/node

which python3
# /usr/bin/python3

# Use the full path in crontab
0 * * * * /usr/local/bin/node /home/user/app/script.js
0 * * * * /usr/bin/python3 /home/user/scripts/backup.py

This is the most reliable approach and works across different systems.

PATH issues cause cron jobs to fail silently, you won't know until it's too late. CronSignal alerts you the second a job doesn't run, so you can fix it fast.

Start free →

Solution 2: Set PATH in Crontab

Add a PATH declaration at the top of your crontab:

# Edit your crontab
crontab -e

# Add PATH at the top
PATH=/usr/local/bin:/usr/bin:/bin:/home/user/.local/bin

# Now your jobs can use short command names
0 * * * * node /home/user/app/script.js

This sets PATH for all jobs in your crontab.

Solution 3: Set PATH in Your Script

Export PATH at the start of your script:

#!/bin/bash
export PATH=/usr/local/bin:/usr/bin:/bin:$PATH

# Now commands work normally
node /home/user/app/script.js
npm run build

Solution 4: Source Your Profile

Load your shell configuration in the script:

#!/bin/bash
source ~/.bashrc  # or ~/.profile

# Your commands here
nvm use 18
node script.js

Use this if you need environment managers like nvm, pyenv, or rbenv.

Common Commands and Their Paths

# Find paths on your system with 'which'
which node      # /usr/local/bin/node or /usr/bin/node
which npm       # /usr/local/bin/npm
which python3   # /usr/bin/python3
which pip3      # /usr/bin/pip3
which ruby      # /usr/bin/ruby
which php       # /usr/bin/php
which docker    # /usr/bin/docker
which aws       # /usr/local/bin/aws

Debugging Tips

Log the environment:

# Add this to see what cron's environment looks like
* * * * * env > /tmp/cron-env.txt

Test with cron's environment:

# Simulate cron's minimal environment
env -i PATH=/usr/bin:/bin /bin/sh -c 'your-command-here'

If this fails but running normally works, you've confirmed it's a PATH issue.

Related Resources

Never debug silent cron failures again

CronSignal alerts you the moment a job doesn't run. Know about failures before they become disasters.

Start free →

Explore More