I am currently working on a deployment tool that will be configuring environment variables across CentOS7 machines. As it stands, my tool is aware of what variables need to be configured, but is not aware of what services will be using them as those services might not even be installed yet.

So the challenges are:

  1. At the point my tool is running, I am unaware of what services are needing what environment variables (and therefore we don't know what .service file to put them into)

  2. Services run as non-interactive non-login as far as I can tell, so the other options of getting a sort of 'global' environment variable don't seem like a solution to this (i.e. profile.d and that sort of thing)

Is there another way to persist these variables without needing to know what service will be referencing them?


In /etc/systemd/system.conf, you can use DefaultEnvironment= to set environment variables passed to all services.

You can read about the details in man systemd-system.conf.

| improve this answer | |
  • This looks like exactly what I was hoping for. The examples I've seen put all the default environment onto one combined line (ex. DefaultEnvironment="VAR1=one" "VAR2=two") even thought it appears you can have multiple DefaultEnvironment= lines. Is there any reason to avoid adding multiple lines? – LAMonday Nov 2 '16 at 16:36

What about this solution: systemctl set-environment LD_LIBRARY_PATH=/usr/local/lib ?

| improve this answer | |

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.