如果在 Linux 系统中运行 systemctl
命令时提示 systemctl: command not found
,通常有以下几种原因和解决方法:
systemd
(非 systemd 发行版)systemctl
是 systemd
的管理工具,如果你的 Linux 发行版不使用 systemd
(如 Debian 7(Wheezy)、CentOS 6、Arch Linux(某些最小化安装) 等),则不会有 systemctl
命令。
systemd
:
ps -p 1 -o comm=systemd
,说明系统支持 systemctl
,可能是路径问题(见下文)。init
或其他(如 upstart
),则系统不使用 systemd
,需要改用其他方式管理服务(如 service
或 init.d
脚本)。systemctl
命令未安装(极少数情况)某些最小化安装的 Linux 系统可能没有安装 systemd
相关包(虽然这种情况很少见)。
systemd
(适用于支持 systemd
的系统):systemd
,无法安装。systemctl
不在 $PATH
中如果 systemctl
已安装但不在 $PATH
中,也会导致找不到命令。
systemctl
的位置:find / -name systemctl 2>/dev/null
/usr/bin/systemctl
),可以手动运行:/usr/bin/systemctl <command>$PATH
:export PATH=$PATH:/usr/bin如果 systemctl
存在但提示 Permission denied
,可能是权限问题。
sudo
运行:sudo systemctl <command>root
用户:su - systemctl <command>systemd
未正确安装如果系统原本支持 systemd
但现在无法使用,可能是系统损坏。
systemd
(适用于 Debian/Ubuntu):apt --reinstall install systemdsystemd
(适用于 CentOS/RHEL):yum reinstall systemd领取专属 10元无门槛券
手把手带您无忧上云