Where is My Environment Variables? Journey to Linux Service

Monday, September 1, 2025
This is a repost from my old blog. First posted in 3/29/2019.

Ok, I had a .NET Core Web App running in Ubuntu behind Nginx. Everything else is fine except I can't retrieve the value of the environment variables that I put in /etc/environment.


After hours of googling, turns out systemd service strips all out except some variables. Two ways to fix this:

  1. Put the environment variable in the .service config file
[Service]
Environment=MY_ENV_VAR=thevalue
  1. Include /etc/environment in the service. (I don't think this is a good idea, especially for my use case).
[Service]
EnvironmentFile=/etc/environment