Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Fix "mail: command not found" on Linux

This guide shows you how to install the mail command on Ubuntu, Debian, CentOS and Red Hat.

Web Hosting2 min read8 steps

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

  1. Log in to the server by SSH as root. SSH is a way to type commands on a server from your computer.
  2. Update the software list.
    apt update
    This refreshes the list of available software.
  3. Install the mail tools.
    apt install mailutils -y
    This installs the mail command.
  4. 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

  1. Log in as root.
  2. Install the package.
    yum install mailx -y
    This installs the mail command. On newer systems, use dnf 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

  1. Send yourself a test email.
    echo "Test body" | mail -s "Test subject" you@example.com
    This sends a short message. Use your own email address.
  2. 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 mail program is missing.
  • Ubuntu and Debian: apt install mailutils.
  • CentOS and Red Hat: yum install mailx.
  • Test with a short message to your own address.