---
title: "Cron environment variables and PATH explained"
url: "https://cronmissed.com/learn/cron-environment-and-path.md"
canonical_url: "https://cronmissed.com/learn/cron-environment-and-path"
last_updated: "2026-10-22"
type: "conceptual"
summary: "Cron runs jobs with a small environment. Learn what it sets, why commands that work in your shell fail, and how to set PATH and SHELL."
related: ["https://cronmissed.com/learn.md", "https://cronmissed.com/learn/cron-job-not-running.md", "https://cronmissed.com/learn/cron-logs.md", "https://cronmissed.com/guides/linux-crontab.md", "https://cronmissed.com/guides/rails-whenever.md"]
---

# Cron environment variables and PATH explained

> **For AI agents:** the complete index of CronMissed pages is [llms.txt](https://cronmissed.com/llms.txt). Every page is also served as markdown at its URL plus .md.

Cron runs jobs with a small environment. Learn what it sets, why commands that work in your shell fail, and how to set PATH and SHELL.

A cron job does not inherit your login shell. According to the crontab manual, cron sets SHELL to /bin/sh and takes LOGNAME and HOME from the account entry; anything else you need, such as PATH, must be set in the crontab or in the command.

## What does cron set?

| Variable | Value under cron |
| --- | --- |
| SHELL | /bin/sh, unless the crontab sets it |
| LOGNAME | From the account line of the crontab's owner |
| HOME | From the account line, unless the crontab sets it |
| MAILTO | Not set by cron; if set in the crontab it chooses who gets the job output. Empty means no mail. |

The crontab file may start with lines of the form `NAME=value`. They apply to every job below them, and they are not shell commands, so one variable cannot be built from another there.

## Why does a command work in my shell and not in cron?

- The command lives in a directory that only your profile adds to PATH, such as a version manager's shims or /usr/local/bin on a minimal system.
- It reads a variable you export in .bashrc or .profile, which cron never loads.
- It needs a terminal, a display or an ssh agent that a background job does not have.
- It assumes a working directory. Cron starts jobs in the home directory; use `cd /path && command` or absolute paths.

## How do I fix it?

```crontab
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=""

15 3 * * * cd /srv/app && ./bin/nightly && curl -fsS --retry 5 https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10
```

To see the environment cron gives a job, add a temporary line such as `* * * * * env > /tmp/cron-env.txt` and compare the file with the output of `env` in your shell. Remove it once you have the answer.

## Questions

### Should I put source ~/.profile in the cron line?

It works, but it hides which variables the job needs and it breaks when the profile changes. Setting the few variables you need in the crontab keeps the job explicit.

### Does a systemd service have the same problem?

Yes, in a different form: a service gets a clean environment too. Set Environment= or EnvironmentFile= in the unit.

## Sources

- [crontab(5) manual page](https://man7.org/linux/man-pages/man5/crontab.5.html), read 22 October 2026

## Related pages

- [Cron job not running checklist](https://cronmissed.com/learn/cron-job-not-running.md)
- [Cron logs](https://cronmissed.com/learn/cron-logs.md)
- [Linux crontab](https://cronmissed.com/guides/linux-crontab.md)
- [Rails with the whenever gem](https://cronmissed.com/guides/rails-whenever.md)

## Related

- [Cron monitoring explained: concepts and fixes](https://cronmissed.com/learn.md)
- [Cron job not running: a checklist by system](https://cronmissed.com/learn/cron-job-not-running.md)
- [Where to find cron logs and job output](https://cronmissed.com/learn/cron-logs.md)
- [Monitor Linux crontab jobs with curl](https://cronmissed.com/guides/linux-crontab.md)
- [Monitor Rails cron jobs written with whenever](https://cronmissed.com/guides/rails-whenever.md)
