Linux 127Medium

Service Command Not Found

[object Object]

5-10 minutes
Easy
FixPedia Team
Применимо к:Ubuntu 18.04 and laterDebian 9 and laterCentOS 7 and later

What Does the 'service: command not found' Error Mean

The service: command not found (or bash: service: command not found) error in Linux occurs when you try to run the service command, but the system cannot find it in the directories listed in the PATH variable. The service command is used to manage system services (start, stop, restart) in distributions with a System V or Upstart init system. In modern systemd-based systems, its role is often fulfilled by systemctl, but service may be retained for backward compatibility.

A typical scenario: you type sudo service nginx start and get an error message instead of managing the service. This does not indicate a problem with the service itself (nginx), but points to the absence of the service utility on your system.

Causes

  1. The sysvinit-utils (or equivalent) package is not installed. In Debian/Ubuntu, the service command is provided by the sysvinit-utils package, which is not installed by default in minimal or cloud images. In CentOS/RHEL, the equivalent functionality is provided by the initscripts package.
  2. The package is corrupted or removed. If the package was accidentally removed or its files are corrupted, the command stops working.
  3. The PATH variable does not include system directories. The service command is usually located in /sbin or /usr/sbin. If these directories are missing from PATH (e.g., in a user environment without administrator privileges), the shell cannot find it.
  4. The system uses a pure systemd without compatibility. Some modern distributions (e.g., a fresh Ubuntu 22.04 install) may not include service by default, assuming the use of systemctl.
  5. Symbolic link error. In systemd systems, service is often a symbolic link to systemctl. If the link is broken, the command fails.

Solutions

Solution 1: Install the package that provides service

This is the most direct approach. Install the package containing the service utility for your distribution.

For Ubuntu/Debian:

sudo apt update
sudo apt install sysvinit-utils

For CentOS/RHEL (versions 7 and below, which use System V):

sudo yum install initscripts

For Fedora or CentOS 8+ (with systemd): The initscripts package may be available, but often service is already present. If not, install sysvinit-tools (if available) or use systemctl.

After installation, verify:

which service

Expected output: /usr/sbin/service or a similar path. The command should now work.

Solution 2: Use systemctl instead of service

If your system runs under systemd (likely for Ubuntu 16.04+, Debian 8+, CentOS 7+), it is recommended to use systemctl—a more modern and functional alternative.

Examples of command replacement:

# Instead of:
sudo service nginx start

# Use:
sudo systemctl start nginx

# To check status:
sudo systemctl status nginx

# To enable autostart:
sudo systemctl enable nginx

systemctl supports all service functions and adds capabilities like unit management, log viewing via journalctl, and dependencies. Switch to systemctl to avoid future issues with a missing service.

Solution 3: Check and fix the PATH variable

If the package is installed but the command is still not found, the issue may be with the PATH variable.

  1. Check the current PATH:
    echo $PATH
    

    Ensure the output includes /sbin and /usr/sbin. They are typically present in PATH for root but may be missing for regular users.
  2. If the directories are missing, add them to PATH temporarily:
    export PATH=$PATH:/usr/sbin:/sbin
    

    This command only affects the current terminal session.
  3. To add them permanently, edit the ~/.bashrc file (for the user) or /etc/profile (for all users):
    nano ~/.bashrc
    

    Add the line:
    export PATH=$PATH:/usr/sbin:/sbin
    

    Then apply the changes:
    source ~/.bashrc
    
  4. Restart the terminal and check which service again.

Solution 4: Reinstall a corrupted package

If the package is installed but the service file is missing or corrupted, reinstall it:

For Ubuntu/Debian:

sudo apt install --reinstall sysvinit-utils

For CentOS/RHEL:

sudo yum reinstall initscripts

After reinstalling, verify the file's integrity:

ls -l /usr/sbin/service

It should be executable (permissions -rwxr-xr-x).

Prevention

To avoid encountering the service command not found error again:

  • Install basic service management packages when deploying minimal systems (e.g., in Docker containers or cloud images). For Debian/Ubuntu, include sysvinit-utils in your package list.
  • Use systemctl in new projects. Since most modern distributions have switched to systemd, get accustomed to systemctl—this ensures compatibility.
  • Update your system regularly. sudo apt update && sudo apt upgrade or sudo yum update will help prevent package conflicts.
  • Check PATH when customizing your environment. If you modify PATH in ~/.bashrc or /etc/environment, ensure you do not remove system directories.
  • Use full paths in scripts. In automated scripts, specify /usr/sbin/service or systemctl instead of just service to avoid PATH dependencies.

F.A.Q.

Why does the 'service command not found' error occur in Linux?
How can I check if the service package is installed on my system?
Can I use systemctl instead of service?
How do I install the service command in Ubuntu?

Hints

Check if the service command exists
Identify your Linux distribution
Install the package that provides the service command
{ "Alternatively": "switch to systemctl", "text": "If you are using systemd, use `systemctl` instead of service. For example, `sudo systemctl start nginx` instead of `sudo service nginx start`. This is recommended for modern systems." }
Update command cache or restart terminal
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community