This guide needs root access. Root is the main admin login. VPS and dedicated server owners have it.
What does the error mean?
The mail command lets you send email from the command line. Scripts use it to send alerts. If the server does not have the program, bash says:
bash: mail: command not found
Bash is the program that reads the commands you type. It is telling you that no program called mail is installed.
Ubuntu and Debian
- Log in to the server by SSH as root. SSH is a way to type commands on a server from your computer.
- Update the software list.
This refreshes the list of available software.apt update - Install the mail tools.
This installs theapt install mailutils -ymailcommand. - During install a screen may ask about mail setup. For a simple server, choose Internet Site and accept the name shown.
If you are not root, put sudo before each command.
CentOS, Red Hat, AlmaLinux and Rocky
- Log in as root.
- Install the package.
This installs theyum install mailx -ymailcommand. On newer systems, usednf install mailx -y.
Tip: CentOS 7 and older Ubuntu releases are old. Newer versions work in a similar way, but the package may be called
s-nail on some. The mail command still works.Test it
- Send yourself a test email.
This sends a short message. Use your own email address.echo "Test body" | mail -s "Test subject" you@example.com - Check your inbox and the spam folder.
If the email does not arrive
- The command needs a mail server on the machine, like Postfix or Exim. Check that one is running.
- Some providers block outgoing mail on port 25. Ask Hostvento support.
- Mail from a plain server can land in spam. Use a proper mail account for important mail.
Quick recap
- The error means the
mailprogram is missing. - Ubuntu and Debian:
apt install mailutils. - CentOS and Red Hat:
yum install mailx. - Test with a short message to your own address.