debian 10 用 root 执行提示 bash: service: command not found(找不到 service 命令)解决方法
问题
想要执行 service,发现找不到命令,原因是没有把 /sbin 的目录路径(系统用户目录)添加到 $PATH 变量中。
root@debian:/home/biao# service ssh start
bash: service:command not found
查看当前 $PATH
root@debian:/home/biao# echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
解决
方法一
出错的用户是用 su root
切换到 ROOT 用户下,这个命令没有也不会把环境带过去!用如下命令就不会出错了:su - root
su root
的话只是将当前身份转为 root,用户 shell 并没有改变,所以有些系统命令不能使用。 su -
或者 su -l
或者 su -l root
可以完全的将当前环境转为 root 环境。(service 的路径为/sbin/service)