【Linux】「sudo: service: command not found」というエラーが出た場合の対処法

$ sudo service mysqld start
sudo: service: command not found

というエラーが出た。

CentOS 5.xだとsudo時にsbinにパスが通ってないよう。

パスを追加する方法は2つあるので好きな方で設定してください。

.bash_profile にパスを追加する方法

以下行を追加する。

# ~/.bash_profile

PATH=$PATH:$HOME/bin
PATH=$PATH:/sbin # 追加
$ source ~/.bash_profile

/etc/sudoers にパスを追加する方法

$ sudo visudo

以下行を追加する。

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

参考

http://www.sssg.org/blogs/naoya/archives/2096