Installing Cron
Step-by-step guide to install and configure cron on different operating systems.
Good News: Cron comes pre-installed on most Unix-like systems (Linux, macOS, FreeBSD). You likely just need to start the service!
Check Current Installation
First, check if cron is already installed and running on your system:
# Check if cron daemon is running
ps aux | grep cron
# Check cron service status (systemd systems)
systemctl status cron
# Check if crontab command exists
which crontab
Linux Installation
Ubuntu/Debian
# Update package list
sudo apt update
# Install cron (if not already installed)
sudo apt install cron
# Start and enable cron service
sudo systemctl start cron
sudo systemctl enable cron
# Verify status
sudo systemctl status cron
CentOS/RHEL/Rocky Linux
# Install cronie package
sudo yum install cronie
# OR for newer versions
sudo dnf install cronie
# Start and enable crond service
sudo systemctl start crond
sudo systemctl enable crond
# Verify status
sudo systemctl status crond
Arch Linux
# Install cronie package
sudo pacman -S cronie
# Start and enable cron service
sudo systemctl start cronie
sudo systemctl enable cronie
macOS Installation
Note: macOS comes with cron pre-installed, but also includes launchd as the preferred scheduler for newer versions.
Using Built-in Cron
# Check if cron is running
ps aux | grep cron | grep -v grep
# Start cron if not running (usually starts automatically)
sudo launchctl load -w /System/Library/LaunchDaemons/com.vix.cron.plist
Using Homebrew (Alternative)
# Install modern cron via Homebrew
brew install vixie-cron
# Or install dcron
brew install dcron
Docker Installation
Running cron in Docker containers requires special setup:
# Dockerfile example
FROM ubuntu:20.04
# Install cron
RUN apt-get update && apt-get install -y cron
# Add crontab file in the cron directory
COPY crontab /etc/cron.d/my-cron-job
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/my-cron-job
# Apply cron job
RUN crontab /etc/cron.d/my-cron-job
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
# Run cron in foreground
CMD cron && tail -f /var/log/cron.log
Verify Installation
After installation, verify that cron is working correctly:
1. Check Service Status
sudo systemctl status cron
2. Test Crontab Access
crontab -l
Should show "no crontab for user" if no jobs exist yet
3. Create Test Job
# Add a test job
echo "* * * * * echo 'Cron is working!' >> /tmp/cron-test.log" | crontab -
# Wait a minute, then check
cat /tmp/cron-test.log
# Remove test job
crontab -r
Basic Configuration
Important Configuration Files
/etc/crontab- System-wide crontab/etc/cron.allow- Users allowed to use cron/etc/cron.deny- Users denied cron access/var/log/cron- Cron execution logs
Troubleshooting Installation
Common Issues
- Service won't start: Check system logs with
journalctl -u cron - Permission denied: Verify user is in allowed users list
- Jobs don't run: Check cron logs and job syntax
- No crontab command: Package might not be installed correctly
Next Steps
Great! Now that cron is installed, let's create your first cron job: