CentOS 6でmailコマンドをパッケージインストールする方法

Linux(CentOS 6)でメールを送信しようと思ってmailコマンドを実行すると、

mail: command not foundといったエラーになることがある。

《例》
# echo "test" | mail test@nobuneko.com
-bash: mail: command not found

そんな時は、以下のようにmailコマンドのインストール状況を確認すると、インストールされていないことが分かる。

# rpm -qa | grep mail

以下のように、闇雲に「yum install mail」としても、「No package mail available.」というエラーになってしまう。

# yum install mail
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
No package mail available.
Error: Nothing to do

仕方がないので、「yum search」で「mail」のパッケージを探す。

# yum search mail
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
===================================================================== N/S Matched: mail =====================================================================
ant-javamail.x86_64 : Optional javamail tasks for ant
classpathx-mail.noarch : GNU JavaMail(tm)
classpathx-mail-javadoc.noarch : Javadoc for classpathx-mail
fetchmail.x86_64 : A remote mail retrieval and forwarding utility
git-email.noarch : Git tools for sending email
libreoffice-emailmerge.x86_64 : Email mail-merge component for LibreOffice
libreport-plugin-mailx.x86_64 : libreport's mailx reporter plugin
mailman.x86_64 : Mailing list manager with built in Web access
mailx.x86_64 : Enhanced implementation of the mailx command
perl-Mail-DKIM.noarch : Sign and verify Internet mail with DKIM/DomainKey signatures
perl-MailTools.noarch : Various mail-related perl modules
procmail.x86_64 : Mail processing program
sendmail.x86_64 : A widely used Mail Transport Agent (MTA)
sendmail-cf.noarch : The files needed to reconfigure Sendmail
sendmail-doc.noarch : Documentation about the Sendmail Mail Transport Agent program
sendmail-milter.i686 : The sendmail milter library
sendmail-milter.x86_64 : The sendmail milter library
cyrus-imapd.x86_64 : A high-performance mail server with IMAP, POP3, NNTP and SIEVE support
dmraid-events-logwatch.x86_64 : dmraid logwatch-based email reporting
evolution.i686 : Mail and calendar client for GNOME
evolution.x86_64 : Mail and calendar client for GNOME
ksig.x86_64 : A graphical application to manage multiple email signatures
libc-client.i686 : C-client mail access routines for IMAP and POP protocols
libc-client.x86_64 : C-client mail access routines for IMAP and POP protocols
logrotate.x86_64 : Rotates, compresses, removes and mails system log files
mailcap.noarch : Helper application and MIME type associations for file types
mutt.x86_64 : A text mode mail user agent
perl-DateTime-Format-Mail.noarch : Convert between DateTime and RFC2822/822 formats
perl-Email-Date-Format.noarch : Produce RFC 2822 date strings
postfix.x86_64 : Postfix Mail Transport Agent
python-twisted-mail.x86_64 : SMTP, IMAP and POP protocol implementation together with clients and servers
sendmail-devel.i686 : Extra development include files and development files
sendmail-devel.x86_64 : Extra development include files and development files
spamassassin.x86_64 : Spam filter for email which can be invoked from mail delivery agents
thunderbird.x86_64 : Mozilla Thunderbird mail/newsgroup client

  Name and summary matches only, use "search all" for everything.

パッケージがいっぱい見つかった。
全部インストールしたらmailコマンドが使えるようになるのだろうけれど、できれば不要なものはインストールしたくない。
しかし、どれを指定してインストールしたらいいのかが分からない。

うーん、と思った時、mailコマンドが既に使える別のCentOS 6環境でどんなパッケージがインストールされているかを確認すればいいや、ということに気づき、別のCentOS 6環境で

# rpm -qa | grep mail

を実行すると、以下のパッケージが表示された。

mailx-12.4-6.el6.x86_64
mailcap-2.1.31-2.el6.noarch
libreport-plugin-mailx-2.0.5-20.el6.x86_64

どうやら、「mailx」というパッケージを入れると良さそうであると分かる。

念のため、以下のサイトを見て確認をする。
http://superuser.com/questions/352545/how-to-get-mail-on-a-centos-6-server-running-postfix

Question:
How to get `mail` on a CentOS 6 server (running postfix)

Answer:
In CentOS, this binary is provided by the mailx package:
yum install mailx

よし、大丈夫そうだ。

早速、「yum install mailx」でmailコマンドをインストールしてみる。

# yum install mailx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mailx.x86_64 0:12.4-6.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                             Arch                                 Version                                   Repository                          Size
=============================================================================================================================================================
Installing:
 mailx                               x86_64                               12.4-6.el6                                base                               234 k

Transaction Summary
=============================================================================================================================================================
Install       1 Package(s)

Total download size: 234 k
Installed size: 452 k
Is this ok [y/N]: y
Downloading Packages:
mailx-12.4-6.el6.x86_64.rpm                                                                                                           | 234 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mailx-12.4-6.el6.x86_64                                                                                                                   1/1

Installed:
  mailx.x86_64 0:12.4-6.el6

Complete!

インストールが完了した!
rpmコマンドで、mailコマンドのインストール状況を確認してみる。

# rpm -qa | grep mail

以下の2パッケージが表示された。(これらのパッケージがインストールされたことを意味する。)

mailx-12.4-6.el6.x86_64
mailcap-2.1.31-2.el6.noarch

以下のようなmailコマンドを実行できるようになった。

# echo "test" | mail test@nobuneko.com

<まとめ>
(1)CentOS 6でmailコマンドをパッケージインストールするには、以下のコマンドを実行してmailxパッケージをインストールすればよいようだ。

yum install mailx

(2)CentOS 6でmailxパッケージをインストールすると、以下の2パッケージがインストールされる。
mailx-12.4-6.el6.x86_64
mailcap-2.1.31-2.el6.noarch

※CnetOS 6のマイナーバージョンの違いにより、mailxパッケージのバージョン、一緒にインストールされるパッケージの種類が変わる可能性がある。

前へ

CentOS 6でlocateコマンドをパッケージインストールする方法

次へ

CentOS 5起動時にPostfixサービスも自動起動にする設定