3

I'm trying to start ssh using:

service sshd start

but the service command can't be found, so it gives me an error:

zsh: command not found: service

What should I do?

EDIT: I added /usr/sbin to

PATH=/bin:/usr/bin:/usr/local/bin:${PATH}
export PATH

in ~/.zshrc file and it worked

  • 4
    Which version of Ubuntu are you running? – fkraiem Jul 18 '16 at 17:19
  • 2
    Check your PATH variable. The service command for me is located in /usr/sbin/service so make sure /usr/sbin is added to your PATH – Sergiy Kolodyazhnyy Jul 18 '16 at 17:51
  • 1
    I see you got it. Don't mind if I post it as an answer ? Also , FYI for the future, after you edit .zshrc file or .bashrc ( for bash ) file use source command ( or if that's dash or ksh shell , use . ) . For example, source ~/.bashrc That will reload the configuration – Sergiy Kolodyazhnyy Jul 19 '16 at 6:21
5

command not found typically results from 2 cases:

  1. an executable not having execute permissions for your user or group
  2. an executable not belonging to a folder listed in PATH variable , or the opposite - PATH variable that does not contain the location of your executable.

As have been solved in the comments , your case is #2. For future readers, the solution is as such:

  1. open your shell's configuration file in any text editor. If your shell is bash open ~/.bashrc , if your shell is zsh open ~/.zshrc. Note that ~ refers to your home directory.
  2. Add line export PATH="$PATH:/usr/sbin" . Note, that /usr/sbin is just an example, your location might be different.
  3. Save the file, exit and run source ~/.zshrc or source ~/.bashrc. Note, that for shells such as ksh or dash you will need to use . ~/.bashrc since source command is bashism and is not portable
-1

Can't help much because I use Bash. But here https://stackoverflow.com/questions/18428374/commands-not-found-on-zsh is a question identical to yours about common applications path pointing in the wrong direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.