I installed Docker via snap while setting up Ubuntu Server 18.10.

If I have a systemd unit file that references the docker command, I get this error:

Executable "docker" not found in path "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

I'm not sure where it is getting this search path. It does not match what is found in /etc/environment.

Without modifying the unit file, can I globally change the search path used by systemd to include /snap/bin?

On an Ubuntu 18.04 system, just using docker without the full path resulted in the error Executable path is not absolute. I ideally want the same service file to work with both snap's Docker and apt's docker-ce packages.

  • If it complained about the relative path even when it found the command in its PATH, it really sounds like the better solution is to modify the unit file. That's also the more portable solution since you'll then be able to copy the unit file to another machine without needing to change systemd's path. Is that really not an option for you?
    – terdon
    Feb 26, 2019 at 23:37

3 Answers 3


According to the systemd documentation, its PATH is set on compilation (see section "Command lines"):

If the command is not a full (absolute) path, it will be resolved to a full path using a fixed search path determinted at compilation time. Searched directories include /usr/local/bin/, /usr/bin/, /bin/ on systems using split /usr/bin/ and /bin/ directories, and their sbin/ counterparts on systems using split bin/ and sbin/. It is thus safe to use just the executable name in case of executables located in any of the "standard" directories, and an absolute path must be used in other cases. Using an absolute path is recommended to avoid ambiguity. Hint: this search path may be queried using systemd-path search-binaries-default.

The command to query the path on my Ubuntu 18.04 was sudo systemd-path search-binaries (on Arch, it was systemd-path search-binaries-default):

$ sudo systemd-path search-binaries

So, you have the following options:

The good: Edit the unit file so that it uses absolute paths. Assuming you have access to it, this is by far the best solution. It makes the file conform to the specification, it allows you to copy it to other machines, it even silences the warning messages.

The bad: Recompile systemd from source, and change the path. This is time consuming, complicated and an all around bad idea unless you really know what you're doing. Even if you do, this seems like a bad solution. You're not going to be able to recompile systemd every time you setup a new machine.

The ugly: If you really can't fix the unit file, you can always create a symlink in /usr/bin pointing to docker

sudo ln -s /snap/bin/docker /usr/bin/docker
  • 1
    Thanks. Editing the unit file isn't ideal because I want to distribute my unit file without caring how the system installed Docker (apt or snap, or whatever future package system is dreamt up). But it seems far less intrusive than asking end users to re-compile systemd!
    – rgov
    Feb 27, 2019 at 18:10
  • 2
    Actually, systemd-path search-binaries reveals /snap/bin is in that list. It does not match the error from systemd.
    – rgov
    Feb 27, 2019 at 18:18
  • @rgov I have never touched systemd's unit files, so I don't know if this is possible, but perhaps you could do something like if $snapDocker; else $aptDocker? But if you're getting the error even if the dir is in the PATH then it sounds like a proper bug and worth reporting.
    – terdon
    Feb 27, 2019 at 18:24
  • Sym-linking the executable (aka «The ugly») does not work. It will result in executing the snap executable (/usr/bin/snap). You should use the snap alias command instead. E.g to alias nvim as vim: sudo snap alias nvim vim.
    – Joachim
    Jun 28, 2022 at 14:15
  • @Joachim yes, that is the objective, isn't it? To run /snap/bin/docker when running the command /usr/bin/docker? Aliases won't work here, this is for a docker setup. Did I misunderstand you?
    – terdon
    Jun 28, 2022 at 14:41

This is the way to fix this.

To check the value of the variable PATH :

echo $PATH

To add /snap/bin

export PATH="$PATH:/snap/bin"

If this does not work, there is a file called /etc/environment

  • 2
    Please read the question more carefully. The OP knows about /etc/environment and the question specifically states this must be fixed without editing the unit file.
    – terdon
    Aug 24, 2019 at 11:30
  • 2
    I’ll probably make a question and answer with this answer. That was how I got here. I actually had a problem with a different district but we all use Ubuntu for help...:) Aug 25, 2019 at 19:22
  • 1
    Yes, please ask a new question. This answer is about adding snap to a regular user's path, it won't help in the situation the OP describes. It might be a fine answer for another question though!
    – terdon
    Aug 25, 2019 at 22:58

Since systemd version 250, you can use the ExecSearchPath= option:


Takes a colon separated list of absolute paths relative to which the executable used by the Exec*= (e.g. ExecStart=, ExecStop=, etc.) properties can be found. ExecSearchPath= overrides $PATH if $PATH is not supplied by the user through Environment=, EnvironmentFile= or PassEnvironment=. Assigning an empty string removes previous assignments and setting ExecSearchPath= to a value multiple times will append to the previous setting.

Instead of modifying the unit file, you may use a drop-in config file, e.g.: /etc/systemd/system/foo.service.d/bar.conf.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .