Set PATH for a systemd unit
The simplest answer is to set the PATH
as part of your ExecStart
command in the systemd Unit file. For example, if you currently have
ExecStart=/bin/mycmd arg1 arg2
then change it to
ExecStart=/bin/bash -c 'PATH=/new/path:$PATH exec /bin/mycmd arg1 arg2'
The expansion of $PATH
will be done by bash, not systemd. Alternatives such as using Environment=PATH=/new/path:$PATH
will not work as systemd will not expand the $PATH
.