CentOS 6.5 - bash: service: command not found

10

2

So I can't type service on my CentOS 6.5 server. I'm logged in as root. When typing service I get this error:

bash: service: command not found

I have also tried to type sudo service, but with no luck. And then I get this error:

sudo: service: command not found

user3524823

Posted 2014-06-27T20:42:32.570

Reputation: 185

in my case, cd /sbin/; ./service gave me what I was looking for. – Greenish – 2017-08-04T14:07:48.740

Answers

10

As discovered in the extended discussion through comments, your system is broken. I suggest reinstalling the system completely or at least the broken packages.

To have /sbin/service again run yum reinstall initscripts.

I don't recommend it, but if you want to reinstall all the packages that fail verification, run:

yum reinstall $(rpm -q --qf '%{NAME}\n' -a | while read rpm; do rpm -V $rpm >/dev/null || echo $rpm; done)

Take note that even a modified configuration file or changed mtime might trigger a reinstall. Though the new configuration files should come up with the .rpmnew extension if you changed the original.

Cristian Ciupitu

Posted 2014-06-27T20:42:32.570

Reputation: 4 515

I think I would be better just reinstalling the whole system. Do you have an idea how the problem occured? (My last command before it happend was tmux a -t scripts and now today when I logged in I did yum install httpd and yum install php-mysql and then service httpd start, and then I could not) – user3524823 – 2014-06-27T21:25:03.313

Maybe someone broke into your server. Perhaps you were running a vulnerable PHP application. Have a look at How do I deal with a compromised server? from Server Fault. Anyway don't forget to save the logs before reinstalling for further analysis.

– Cristian Ciupitu – 2014-06-27T21:31:19.323

Okay. Thanks for the help so fare. I have not ran any PHP applications. Only java jars. I dont know if they can make trouble. – user3524823 – 2014-06-27T21:32:54.913

The Java browser plugin is infamous for its security vulnerabilities, but I'm not familiar with its server side if that's your case. – Cristian Ciupitu – 2014-06-27T21:45:11.470

7

The service command resides in the sbin directory - make sure it exists at /sbin/service

If you are root, then according to this mailing list, you may need to make sure it's on your path: Centos5 - Service Command Not Present.

You may also check out a similar function called chkconfig, since it can activate services as well. CentOS - chkconfig

The links attached are for CentOS 5, but they don't seem to differ in CentOS 6.5

macilath

Posted 2014-06-27T20:42:32.570

Reputation: 81

2

I was able to fix this by adding /sbin to my PATH in CentOS 5.2

export PATH=$PATH:/sbin

CommonCoreTawan

Posted 2014-06-27T20:42:32.570

Reputation: 121

This duplicates another answer and adds no new content. Please don't post an answer unless you actually have something new to contribute. – DavidPostill – 2015-12-26T15:32:28.973

sbin should only be in the path of the root user. – Xyon – 2015-12-26T15:48:59.730