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

Published on 2026-10-20 by frfrand

Variables de entorno explicadas: PATH, PORT, claves de API, archivos .env, seguridad y configuración de aplicaciones en producción.

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

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 look for executable programs.

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

What does exporting a variable mean?

In Bash, export NOMBRE=valor 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 that are 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.

In addition, the exact format may vary between tools. It is not advisable to assume that any line valid in one implementation will be valid in all of them.

Is it safe to store passwords there?

An environment variable can be used to provide secrets, but it does not equal 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 that 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 did not 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 should not 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?

Git deployments and applications running on ArduMaker VPS may need environment variables to connect to databases or configure services. The platform facilitates deployment, but each project must define which values are public, which are secret, and how they reach the process.

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

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