mail command not found. How to Install Mail command

mail command not found. How to Install Mail command on CentOS / RHEL 7 server

Follow the below steps to install mail command on your Linux server.
 

[root@server /]# mail -s “Test Email” user@example.com
-bash: mail: command not found

 
I got the above error message ‘-bash: mail: command not found’ while trying to send an email from the server.

Mail command is used on linux servers to send and receive emails from terminal. You must install mailx package on the server to fix the above error.

On CentOS and Redhat servers, mail command is provided by mailx package.
 

How to Install Mail command on CentOS / RHEL servers

1. Log into your Linux Server via SSH as ‘root’ user

2. Type command ‘rpm -qa | grep mailx’ to check whether mailx package is installed or not
 

[root@server /]# rpm -qa | grep mailx
[root@server /]#

 

mailx package is not installed on the above server.

3. Run the command ‘yum install mailx’ to install mailx package

4. Yum might ask for confirmation while installing the package, enter ‘y’ to confirm.
 

[root@server /]# yum install mailx

—> Package mailx.x86_64 0:12.5-12.el7_0 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================================
Installing:
mailx x86_64 12.5-12.el7_0 base 244 k

Transaction Summary
========================================================================================================================================================================
Install 1 Package

Total download size: 244 k
Installed size: 466 k
Is this ok [y/d/N]: y
Downloading packages:
mailx-12.5-12.el7_0.x86_64.rpm
Installing : mailx-12.5-12.el7_0.x86_64 1/1
Verifying : mailx-12.5-12.el7_0.x86_64 1/1

Installed:
mailx.x86_64 0:12.5-12.el7_0

Complete!

 

Install mail command

Install mail command


 

How to download and install mailx package on CentOS / Redhat server

1. Log into CentOS 7 / RHEL 7 server as ‘root’ user

2. Download mailx package from CentOS website using wget command

# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/mailx-12.5-19.el7.x86_64.rpm

3. Install mailx package using yum command or rpm command

# yum install mailx-12.5-19.el7.x86_64.rpm

Yum will install mailx and the required dependencies.

# rpm -ivh mailx-12.5-19.el7.x86_64.rpm

You must install the required dependencies before installing with rpm command.

The below dependencies are required:

glibc
nss
nspr