9

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

Jens Erat
  • 18,485
  • 14
  • 68
  • 80
user3524823
  • 195
  • 2
  • 3
  • 15

4 Answers4

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.

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

2

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

export PATH=$PATH:/sbin
0

I had this service: command not found problem after I reinstalled iptables with yum.

The right solution seems to be indeed yum install initscripts.x86_64

But while I tried to reinstall with yum reinstall command I kept getting this error:

Package(s) initscripts.x86_64 available, but not installed.
Error: Nothing to do

Next day I tried with install instead of reinstall and it worked OK, but I didn't do more tests:

yum install initscripts.x86_64

Previous error(s) might have been temporary errors in remote repositories but I am not 100% sure.

This happen on an older Centos 7.x machine, if you see repository errors while installing with yum:

  • edit the files in /etc/yum.repos.d (mostly CentOS-Base.repo and CentOS-fasttrack.repo) and replace instances of http://mirror.centos.org to https://vault.centos.org (note https).
  • comment line mirrorlist= and uncomment line baseurl=, that should force it get from main source and ignore mirrors that might be out of date. Previously it was mirrors enabled and baseurl disabled.

Hopefully I got the details right.

adrianTNT
  • 272
  • 1
  • 6
  • 18