How to pass custom environment variable in systemd unit file ?

Solution Verified - Updated -

Issue

  • Unable to pass custom environment variable in systemd unit file definition.

    Environment="VAR1=VALUE1"
    Environment="VAR2=$VAR1 VALUE2" 
    
  • The variable $VAR1 does not get resolved with correct value (VALUE1).

  • Use of EnvironmentFile did not resolve the value of the environment variable $VAR1.

Environment

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9
  • Systemd

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content