I am trying to use the $HOME environment variable in the ExecStart. I tried many different things like $HOME and ${HOME} but nothing seems to be working


Anyone knows the correct format for this?

  • 2
    This is not allowed in ExecStart=. It must be a full path beginning with a /. – Michael Hampton Aug 4 '16 at 19:37
  • 1
    If you want a service to use things in every user's homes, you want a user service, not a system service. – bviktor Jan 4 '20 at 11:52

I think this is what you're looking for: https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers.

Specifically, %h should expand to the current user's home dir.

  • According to the documentation you have provided, %h is the user home directory. But, in my case, ExecStart still requested the full path so I ended up typing it starting from the root. – Can Sürmeli Nov 15 '19 at 9:06
  • Using %h is probably not what you want. I've posted an alternate answer with details. – pR0Ps Jan 4 '20 at 11:20

The full list of supported variables (called "Specifiers") is here: https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers.

There is no specifier for the home directory of user the service is run as (the one specified by User=). There is only one for the user running the service manager.

From the link:

%h is the home directory of the user running the service manager instance. In case of the system manager this resolves to "/root". Note that this setting is not influenced by the User= setting configurable in the [Service] section of the service unit.

  • Just to be clear, that means if I have a user unit, then %h most definitely is what I want to use because it will give me the equivalent of $HOME. – Cliff Apr 22 '20 at 20:05

You have to define a user this User=foo in the service file to have ${HOME} to work the way you expect.

If you don't set a user, $HOME will be expanded to the home directory of default user used to launch command, so it won't match your $HOME, hence the binary.

Another solution is to use an absolute path for the binary.

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.