What is an environment variable and what is it used for on a server?

Published on 2026-10-20 by frfrand

Environment variables explained: PATH, PORT, API keys, .env files, security, and production application configuration.

What is an environment variable and what is it used for on a server?

Short answer: An environment variable is a name associated with a value that a process can use to configure its behavior. On servers it is used to indicate ports, service names, paths, and other parameters without having to continuously change the source code.

For example, an application can use PORT=8000 on your computer and PORT=5000 in production. The same program responds on different ports because the environment is different.

The example of two branches

Imagine a coffee shop with two branches. The coffee recipe is the same, but each location has a different address, schedule, and phone number.

An application can also use a common base and receive different configurations depending on where it runs.

Environment variables are a way to provide those values. They are not the only configuration system: there are also files, startup parameters, and external services.

Where are they seen in Linux?

You can check some variables with printenv. For example:

printenv HOME
printenv PATH

HOME usually indicates the home directory. PATH contains paths where the shell or certain system functions search for executable programs.

This does not mean that all variables are always defined or that their content is reliable for making security decisions.

What does exporting a variable mean?

In Bash, export NAME=value sets a variable that can be inherited by child processes started from that shell.

This explains a common confusion: you modify a variable in your terminal, but a system service continues using the previous configuration. That service may have started in another environment, perhaps via systemd or a container.

Processes usually receive a copy of the environment configuration when they start; modifying your own terminal does not magically update all services already running.

What is a .env file?

It is a convention used by many tools to store name-value pairs in a text file.

Example:

PORT=8000
LOG_LEVEL=info
APP_MODE=development

But a .env file is not a built-in function of all applications or of Linux. For it to work, a library or tool must read it and pass that configuration to the process.

Also, the exact format can vary between tools. It is not safe to assume that any line valid in one implementation will be valid in all.

Is it safe to store passwords there?

An environment variable can be used to provide secrets, but it is not equivalent to a vault. Variables can appear in logs, memory dumps, or process environments accessible to users with certain permissions.

In production, consider secret managers, strict permissions, and rotation mechanisms. Never publish keys in public repositories or add them to a container image you will share.

Don't upload a .env file with real credentials to Git just to make deployment "easier". There are more appropriate methods.

Why does it work on my PC and fail in production?

Maybe a variable is missing, the value has a different format, or the process didn't inherit the configuration you expected.

Instead of printing a password in the logs to debug, securely check if the variable is defined, if the service receives the expected name, and if the configuration was updated after the restart.

What differences are there between development and production?

In development you can use a local database and enable diagnostic messages. In production you need real addresses, appropriate permissions, and security restrictions.

You shouldn't enable insecure configurations just because they make testing easier. Separating environments helps prevent an accidental change from affecting real users.

How does it fit into ArduMaker?

In GitHub deployments of ArduMaker, environment variables go in the app's deploy configuration: each one is declared for building, for running, or for both, and secrets are stored encrypted and referenced without writing the value in the document. The platform places them in files outside the repository that only the app's Linux user can read, and masks secrets in deploy logs (more detail in the GitHub deploy documentation).

Even so, each project must decide which values are public, which are secret, and who can change them.

In summary: an environment variable configures the behavior of a process. It is useful for separating code and configuration, but it also requires care with secrets and permissions.

Frequently asked questions

If I change a variable, does the running process see it?

No. A process receives its environment at startup; changing the variable afterwards does not affect it. You must restart the service (or redeploy) for it to take the new value.

Can I upload the .env file to Git?

With real values, no. Add it to .gitignore and upload instead a .env.example with the variable names and example values, so that whoever clones the project knows what to configure.

Source: Process Environment according to GNU · Why .env matters.

What is an environment variable and what is it used for on a server?
  • variables de entorno
  • Linux
  • deploy
  • configuración

Keep reading

All articles · VPS plans