LinuxCommandLibrary

systemctl-import-environment

Import current environment into systemd

TLDR

Import a variable

$ systemctl import-environment [variable]
copy

Import multiple variables
$ systemctl import-environment [variable_1 variable_2 ...]
copy

Import variables for user services
$ systemctl import-environment [variable] --user
copy

SYNOPSIS

systemctl [OPTIONS...] import-environment [VARIABLE...]

PARAMETERS

VARIABLE
    One or more names of environment variables to import from the client’s environment


    If omitted, the full inherited environment block is imported

DESCRIPTION

The systemctl import-environment sub‑command copies environment variables from the client process into the systemd manager’s runtime environment block. When invoked without any arguments it imports the entire environment that the systemctl process inherited, silently ignoring any entries that are not valid environment variable names or contain illegal values. When one or more variable names are supplied, only those variables are imported, and the command will fail if a name or value does not meet systemd’s validation rules. The imported variables become part of the manager’s environment and are merged with any variables defined via DefaultEnvironment= in /etc/systemd/system.conf or Environment= directives in unit files. This environment is then passed to services when they are started. The command was introduced in systemd version 233 and operates only on the in‑memory environment; the changes are lost on reboot unless persisted via configuration files. It is commonly used together with systemctl set-environment and systemctl unset-environment to manage the manager’s environment at runtime.

CAVEATS

Importing the full environment may silently drop invalid entries; only variables that pass systemd’s validation are kept. The command affects only the runtime manager environment and does not modify configuration files, so changes disappear after a reboot. It cannot be used to unset variables that were defined in configuration files or generators.

NOTE ON USAGE

Calling systemctl import-environment without specifying variable names is considered deprecated; explicitly listing the variables you need is recommended for clarity and future compatibility.

TYPICAL WORKFLOW


Export a variable in the shell → systemctl import-environment VAR → start or restart the target service → the service sees VAR in its environment.

HISTORY

The import-environment verb was added to systemd in version 233 (released in 2016) to provide a way for user sessions and scripts to propagate their environment into the systemd manager. It has since been used by desktop environments and tools like dbus-update-activation-environment to ensure that services started by systemd inherit the user’s $PATH, $DISPLAY, and other session variables.

SEE ALSO

systemctl(1), set-environment(1), unset-environment(1), show-environment(1)

Copied to clipboard