What is the difference between /etc/environment and /etc/profile?

54,166

Solution 1

Extract from The Ubuntu help

/etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.

/etc/profile - This file gets executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the DisplayManager when the desktop session loads.

I think all this is just a convention but not far from a standard (I don't know about RedHat like systems ).

Solution 2

/etc/environment is not part of POSIX, it belongs to PAM (Pluggable Authentication Module), and only programs compiled with PAM support are able to use it (primarily login systems, which subsequently start the shell or user environment). This means it isn't even read by your shell.

You can see the programs using /etc/environment with grep -l pam_env /etc/pam.d/*.

So /etc/environment is used for setting variables for programs which are usually not started from a shell.

Share:
54,166

Related videos on Youtube

Xandrmoro
Author by

Xandrmoro

I could tell you about myself but I don't think it would tell you anything about myself. I think it's best for now if I just let my questions and answers speak for me.

Updated on September 18, 2022

Comments

  • Xandrmoro
    Xandrmoro almost 2 years

    I understand that the former is loaded prior to the latter, but what is the difference in their purpose and otherwise? Are there any good reasons I should set some variables in one and not in other? Except the fact that /etc/environment seems to exist to set up environment for all processes run by the system, while /etc/profile is for setting up environment used and propagated from the login shell, correct?

    Also, on a side note, which program traditionally reads /etc/environment? Is it related to POSIX, or just a convention?

  • Dmitriy Korobskiy
    Dmitriy Korobskiy about 5 years
    It works on RedHat (as of 7.6). The '/etc/environment' is empty was my server and setting VAR=value took effect in a shell (after re-login).
  • simohe
    simohe over 3 years
    according to man enviroment.d, systemd uses /etc/environment.d/, and for bc compatibility, a link to /etc/environment is created . With systemd, all processes get the variables. man7.org/linux/man-pages/man5/environment.d.5.html
  • Hiran Chaudhuri
    Hiran Chaudhuri over 2 years
    I think one of the most important differences is that /etc/environment is not interpreted by bash - therefore expressions or external system calls just do not work.