Where to declare environment variables?












55















What are correct places for:




  1. Global environment variables meant to affect all users?

  2. User-specific environment variables?










share|improve this question





























    55















    What are correct places for:




    1. Global environment variables meant to affect all users?

    2. User-specific environment variables?










    share|improve this question



























      55












      55








      55


      32






      What are correct places for:




      1. Global environment variables meant to affect all users?

      2. User-specific environment variables?










      share|improve this question
















      What are correct places for:




      1. Global environment variables meant to affect all users?

      2. User-specific environment variables?







      command-line environment-variables






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 5 '12 at 22:26









      Christopher Kyle Horton

      10.4k1269142




      10.4k1269142










      asked Sep 24 '10 at 3:39









      IvanIvan

      21.1k59128197




      21.1k59128197






















          4 Answers
          4






          active

          oldest

          votes


















          16














          I think the community wiki page on environment variables will help you sort out






          share|improve this answer





















          • 2





            The problem is that the linked document is confused and/or plain wrong in the part of user-specif variables. I still am trying to find a shell-agnostic way to do it. $HOME/.profile is probably the best bet...

            – Rmano
            Jan 19 '12 at 15:49






          • 16





            Please paste text or take a snapshot of the linked content - it may not be available in the future!

            – Nam G VU
            Oct 30 '14 at 8:06






          • 4





            Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

            – Thomas Ward
            Jul 17 '16 at 19:45



















          70














          To add to sagarchalise's answer, I can summarize what the link suggests as appropriate places for settings.



          For global settings, system-wide environment variables




          • Use /etc/environment

          • Don't use /etc/profile or /etc/bash.bashrc


          From the page:




          /etc/environment [...] 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.




          Using /etc/profile is a very Unix-y way to go, but its functionality is greatly reduced under Ubuntu. It exists only to point to /etc/bash.bashrc and to collect entries from /etc/profile.d.



          On my system, the only interesting entry entry in profile.d is /etc/profile.d/bash_completion.sh.



          For local or per-user settings



          A previous version of the Ubuntu page recommended ~/.pam_environment, but the page currently suggests that if that doesn't work, you should use





          • ~/.profile - This is probably the
            best file for placing environment
            variable assignments in, since it gets
            executed automatically by the
            DisplayManager during the startup
            process desktop session as well as by
            the login shell when one logs-in from
            the textual console.



          • ~/.bash_profile or ~./bash_login - If one of these exists, bash executes it instead of ~/.profile when bash is started as a login shell. Bash will prefer ~/.bash_profile to ~/.bash_login. [...] These files won't influence a graphical session by default."



          • ~/.bashrc - "... may be the easiest place to set variables".






          share|improve this answer





















          • 1





            Which programs read /etc/environment and when? It doesn't seem to work with cron, even when using SHELL=/bin/bash

            – SystemParadox
            Mar 11 '13 at 10:49








          • 1





            It appears that /etc/environment is part of PAM, which means that it should set the default environment for all processes. cron is special (that is, broken) in specifically overwriting this environment with it's own.

            – SystemParadox
            Mar 12 '13 at 9:32











          • so how does .bashrc behave? after bash_profile? instead of .profile?

            – opensas
            Aug 1 '13 at 18:50






          • 1





            @opensas You probably should ask as a separate question, referencing this one or the answer.

            – belacqua
            Aug 1 '13 at 21:21











          • @belacqua lets say I need to add 2 or more environment variables to /etc/environment like JAVA_HOME="/opt/java" and ANT_HOME="/opt/ant" how to do it

            – Kasun Siyambalapitiya
            Nov 16 '16 at 4:53



















          7














          You've got:




          /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
          and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).




          which in Lucid and Maverick run



          /etc/profile.d/*.sh


          if present, and if the user's shell is bash:



          /etc/bash.bashrc


          For user environment, there is a confusing array specific to the shell and whether it is considered a "login shell". If the shell is bash:



             ~/.bash_profile
          The personal initialization file, executed for login shells
          ~/.bashrc
          The individual per-interactive-shell startup file


          for sh/dash:



          $HOME/.profile


          for zsh, I'm not even going to try to make sense of this.






          share|improve this answer































            5














            As recommended on https://help.ubuntu.com/community/EnvironmentVariables:




            1. Global environment variables meant to affect all users should go in /etc/environment.


            2. User-specific environment variables should be set in ~/.pam_environment.



            Avoid the profile and rc files for setting environment variables on Ubuntu. They have caused me more headaches than they are worth.



            This is easier said than done however ;)



            It is possible that you may run into the same configuration gap that existed for me. See the workaround for encrypted home below.



            My ~/.pam_environment:



            PATH            DEFAULT=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${HOME}/bin
            IDEA_JDK DEFAULT=${HOME}/Applications/jdk


            Why the ugly static path? ${PATH} would not work for me. I bricked my login several times trying to work around it so I am sticking with the ugly static copy of the defaults :)



            Workaround for Encrypted Home Folders



            In Ubuntu releases up to and including Precise 12.04 Beta 2, if you are using an encrypted home directory you will need to modify /etc/pam.d/common-session to get it to load ~/.pam_environment. This solution apparently works for earlier releases, but I have not tested it.



            Guenther Montag (g-montag) wrote on 2010-08-19:




            This seems to be an issue with encrypted home directories. I added



            session required pam_env.so



            at the end of /etc/pam.d/common-session and now ~/.pam_environment gets read. On another system without encrypted home directories (also 10.04) the work around is not needed. Perhaps in my case the system tries to read ~/.pam_environment before it is decrypted.




            Adapted from my answer on Super User: https://superuser.com/a/408373/66856






            share|improve this answer


























            • This is still wrong: ${HOME} won't work either. There is no expansion in .pam_environment.

              – detly
              Aug 7 '14 at 3:47






            • 2





              @detly there is expansion in .pam_environment, but HOME isn't set that early usually. If that line had read DEFAULT=${PATH}/Applications/jdk, you'd have seen the value of PATH inserted in it.

              – muru
              Jun 8 '16 at 19:54











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f4667%2fwhere-to-declare-environment-variables%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            16














            I think the community wiki page on environment variables will help you sort out






            share|improve this answer





















            • 2





              The problem is that the linked document is confused and/or plain wrong in the part of user-specif variables. I still am trying to find a shell-agnostic way to do it. $HOME/.profile is probably the best bet...

              – Rmano
              Jan 19 '12 at 15:49






            • 16





              Please paste text or take a snapshot of the linked content - it may not be available in the future!

              – Nam G VU
              Oct 30 '14 at 8:06






            • 4





              Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

              – Thomas Ward
              Jul 17 '16 at 19:45
















            16














            I think the community wiki page on environment variables will help you sort out






            share|improve this answer





















            • 2





              The problem is that the linked document is confused and/or plain wrong in the part of user-specif variables. I still am trying to find a shell-agnostic way to do it. $HOME/.profile is probably the best bet...

              – Rmano
              Jan 19 '12 at 15:49






            • 16





              Please paste text or take a snapshot of the linked content - it may not be available in the future!

              – Nam G VU
              Oct 30 '14 at 8:06






            • 4





              Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

              – Thomas Ward
              Jul 17 '16 at 19:45














            16












            16








            16







            I think the community wiki page on environment variables will help you sort out






            share|improve this answer















            I think the community wiki page on environment variables will help you sort out







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 10 at 18:30









            wjandrea

            8,49742259




            8,49742259










            answered Sep 24 '10 at 3:49









            sagarchalisesagarchalise

            17.8k105874




            17.8k105874








            • 2





              The problem is that the linked document is confused and/or plain wrong in the part of user-specif variables. I still am trying to find a shell-agnostic way to do it. $HOME/.profile is probably the best bet...

              – Rmano
              Jan 19 '12 at 15:49






            • 16





              Please paste text or take a snapshot of the linked content - it may not be available in the future!

              – Nam G VU
              Oct 30 '14 at 8:06






            • 4





              Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

              – Thomas Ward
              Jul 17 '16 at 19:45














            • 2





              The problem is that the linked document is confused and/or plain wrong in the part of user-specif variables. I still am trying to find a shell-agnostic way to do it. $HOME/.profile is probably the best bet...

              – Rmano
              Jan 19 '12 at 15:49






            • 16





              Please paste text or take a snapshot of the linked content - it may not be available in the future!

              – Nam G VU
              Oct 30 '14 at 8:06






            • 4





              Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

              – Thomas Ward
              Jul 17 '16 at 19:45








            2




            2





            The problem is that the linked document is confused and/or plain wrong in the part of user-specif variables. I still am trying to find a shell-agnostic way to do it. $HOME/.profile is probably the best bet...

            – Rmano
            Jan 19 '12 at 15:49





            The problem is that the linked document is confused and/or plain wrong in the part of user-specif variables. I still am trying to find a shell-agnostic way to do it. $HOME/.profile is probably the best bet...

            – Rmano
            Jan 19 '12 at 15:49




            16




            16





            Please paste text or take a snapshot of the linked content - it may not be available in the future!

            – Nam G VU
            Oct 30 '14 at 8:06





            Please paste text or take a snapshot of the linked content - it may not be available in the future!

            – Nam G VU
            Oct 30 '14 at 8:06




            4




            4





            Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

            – Thomas Ward
            Jul 17 '16 at 19:45





            Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

            – Thomas Ward
            Jul 17 '16 at 19:45













            70














            To add to sagarchalise's answer, I can summarize what the link suggests as appropriate places for settings.



            For global settings, system-wide environment variables




            • Use /etc/environment

            • Don't use /etc/profile or /etc/bash.bashrc


            From the page:




            /etc/environment [...] 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.




            Using /etc/profile is a very Unix-y way to go, but its functionality is greatly reduced under Ubuntu. It exists only to point to /etc/bash.bashrc and to collect entries from /etc/profile.d.



            On my system, the only interesting entry entry in profile.d is /etc/profile.d/bash_completion.sh.



            For local or per-user settings



            A previous version of the Ubuntu page recommended ~/.pam_environment, but the page currently suggests that if that doesn't work, you should use





            • ~/.profile - This is probably the
              best file for placing environment
              variable assignments in, since it gets
              executed automatically by the
              DisplayManager during the startup
              process desktop session as well as by
              the login shell when one logs-in from
              the textual console.



            • ~/.bash_profile or ~./bash_login - If one of these exists, bash executes it instead of ~/.profile when bash is started as a login shell. Bash will prefer ~/.bash_profile to ~/.bash_login. [...] These files won't influence a graphical session by default."



            • ~/.bashrc - "... may be the easiest place to set variables".






            share|improve this answer





















            • 1





              Which programs read /etc/environment and when? It doesn't seem to work with cron, even when using SHELL=/bin/bash

              – SystemParadox
              Mar 11 '13 at 10:49








            • 1





              It appears that /etc/environment is part of PAM, which means that it should set the default environment for all processes. cron is special (that is, broken) in specifically overwriting this environment with it's own.

              – SystemParadox
              Mar 12 '13 at 9:32











            • so how does .bashrc behave? after bash_profile? instead of .profile?

              – opensas
              Aug 1 '13 at 18:50






            • 1





              @opensas You probably should ask as a separate question, referencing this one or the answer.

              – belacqua
              Aug 1 '13 at 21:21











            • @belacqua lets say I need to add 2 or more environment variables to /etc/environment like JAVA_HOME="/opt/java" and ANT_HOME="/opt/ant" how to do it

              – Kasun Siyambalapitiya
              Nov 16 '16 at 4:53
















            70














            To add to sagarchalise's answer, I can summarize what the link suggests as appropriate places for settings.



            For global settings, system-wide environment variables




            • Use /etc/environment

            • Don't use /etc/profile or /etc/bash.bashrc


            From the page:




            /etc/environment [...] 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.




            Using /etc/profile is a very Unix-y way to go, but its functionality is greatly reduced under Ubuntu. It exists only to point to /etc/bash.bashrc and to collect entries from /etc/profile.d.



            On my system, the only interesting entry entry in profile.d is /etc/profile.d/bash_completion.sh.



            For local or per-user settings



            A previous version of the Ubuntu page recommended ~/.pam_environment, but the page currently suggests that if that doesn't work, you should use





            • ~/.profile - This is probably the
              best file for placing environment
              variable assignments in, since it gets
              executed automatically by the
              DisplayManager during the startup
              process desktop session as well as by
              the login shell when one logs-in from
              the textual console.



            • ~/.bash_profile or ~./bash_login - If one of these exists, bash executes it instead of ~/.profile when bash is started as a login shell. Bash will prefer ~/.bash_profile to ~/.bash_login. [...] These files won't influence a graphical session by default."



            • ~/.bashrc - "... may be the easiest place to set variables".






            share|improve this answer





















            • 1





              Which programs read /etc/environment and when? It doesn't seem to work with cron, even when using SHELL=/bin/bash

              – SystemParadox
              Mar 11 '13 at 10:49








            • 1





              It appears that /etc/environment is part of PAM, which means that it should set the default environment for all processes. cron is special (that is, broken) in specifically overwriting this environment with it's own.

              – SystemParadox
              Mar 12 '13 at 9:32











            • so how does .bashrc behave? after bash_profile? instead of .profile?

              – opensas
              Aug 1 '13 at 18:50






            • 1





              @opensas You probably should ask as a separate question, referencing this one or the answer.

              – belacqua
              Aug 1 '13 at 21:21











            • @belacqua lets say I need to add 2 or more environment variables to /etc/environment like JAVA_HOME="/opt/java" and ANT_HOME="/opt/ant" how to do it

              – Kasun Siyambalapitiya
              Nov 16 '16 at 4:53














            70












            70








            70







            To add to sagarchalise's answer, I can summarize what the link suggests as appropriate places for settings.



            For global settings, system-wide environment variables




            • Use /etc/environment

            • Don't use /etc/profile or /etc/bash.bashrc


            From the page:




            /etc/environment [...] 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.




            Using /etc/profile is a very Unix-y way to go, but its functionality is greatly reduced under Ubuntu. It exists only to point to /etc/bash.bashrc and to collect entries from /etc/profile.d.



            On my system, the only interesting entry entry in profile.d is /etc/profile.d/bash_completion.sh.



            For local or per-user settings



            A previous version of the Ubuntu page recommended ~/.pam_environment, but the page currently suggests that if that doesn't work, you should use





            • ~/.profile - This is probably the
              best file for placing environment
              variable assignments in, since it gets
              executed automatically by the
              DisplayManager during the startup
              process desktop session as well as by
              the login shell when one logs-in from
              the textual console.



            • ~/.bash_profile or ~./bash_login - If one of these exists, bash executes it instead of ~/.profile when bash is started as a login shell. Bash will prefer ~/.bash_profile to ~/.bash_login. [...] These files won't influence a graphical session by default."



            • ~/.bashrc - "... may be the easiest place to set variables".






            share|improve this answer















            To add to sagarchalise's answer, I can summarize what the link suggests as appropriate places for settings.



            For global settings, system-wide environment variables




            • Use /etc/environment

            • Don't use /etc/profile or /etc/bash.bashrc


            From the page:




            /etc/environment [...] 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.




            Using /etc/profile is a very Unix-y way to go, but its functionality is greatly reduced under Ubuntu. It exists only to point to /etc/bash.bashrc and to collect entries from /etc/profile.d.



            On my system, the only interesting entry entry in profile.d is /etc/profile.d/bash_completion.sh.



            For local or per-user settings



            A previous version of the Ubuntu page recommended ~/.pam_environment, but the page currently suggests that if that doesn't work, you should use





            • ~/.profile - This is probably the
              best file for placing environment
              variable assignments in, since it gets
              executed automatically by the
              DisplayManager during the startup
              process desktop session as well as by
              the login shell when one logs-in from
              the textual console.



            • ~/.bash_profile or ~./bash_login - If one of these exists, bash executes it instead of ~/.profile when bash is started as a login shell. Bash will prefer ~/.bash_profile to ~/.bash_login. [...] These files won't influence a graphical session by default."



            • ~/.bashrc - "... may be the easiest place to set variables".







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 17 '18 at 4:52









            wjandrea

            8,49742259




            8,49742259










            answered Feb 14 '11 at 21:32









            belacquabelacqua

            15.7k1473103




            15.7k1473103








            • 1





              Which programs read /etc/environment and when? It doesn't seem to work with cron, even when using SHELL=/bin/bash

              – SystemParadox
              Mar 11 '13 at 10:49








            • 1





              It appears that /etc/environment is part of PAM, which means that it should set the default environment for all processes. cron is special (that is, broken) in specifically overwriting this environment with it's own.

              – SystemParadox
              Mar 12 '13 at 9:32











            • so how does .bashrc behave? after bash_profile? instead of .profile?

              – opensas
              Aug 1 '13 at 18:50






            • 1





              @opensas You probably should ask as a separate question, referencing this one or the answer.

              – belacqua
              Aug 1 '13 at 21:21











            • @belacqua lets say I need to add 2 or more environment variables to /etc/environment like JAVA_HOME="/opt/java" and ANT_HOME="/opt/ant" how to do it

              – Kasun Siyambalapitiya
              Nov 16 '16 at 4:53














            • 1





              Which programs read /etc/environment and when? It doesn't seem to work with cron, even when using SHELL=/bin/bash

              – SystemParadox
              Mar 11 '13 at 10:49








            • 1





              It appears that /etc/environment is part of PAM, which means that it should set the default environment for all processes. cron is special (that is, broken) in specifically overwriting this environment with it's own.

              – SystemParadox
              Mar 12 '13 at 9:32











            • so how does .bashrc behave? after bash_profile? instead of .profile?

              – opensas
              Aug 1 '13 at 18:50






            • 1





              @opensas You probably should ask as a separate question, referencing this one or the answer.

              – belacqua
              Aug 1 '13 at 21:21











            • @belacqua lets say I need to add 2 or more environment variables to /etc/environment like JAVA_HOME="/opt/java" and ANT_HOME="/opt/ant" how to do it

              – Kasun Siyambalapitiya
              Nov 16 '16 at 4:53








            1




            1





            Which programs read /etc/environment and when? It doesn't seem to work with cron, even when using SHELL=/bin/bash

            – SystemParadox
            Mar 11 '13 at 10:49







            Which programs read /etc/environment and when? It doesn't seem to work with cron, even when using SHELL=/bin/bash

            – SystemParadox
            Mar 11 '13 at 10:49






            1




            1





            It appears that /etc/environment is part of PAM, which means that it should set the default environment for all processes. cron is special (that is, broken) in specifically overwriting this environment with it's own.

            – SystemParadox
            Mar 12 '13 at 9:32





            It appears that /etc/environment is part of PAM, which means that it should set the default environment for all processes. cron is special (that is, broken) in specifically overwriting this environment with it's own.

            – SystemParadox
            Mar 12 '13 at 9:32













            so how does .bashrc behave? after bash_profile? instead of .profile?

            – opensas
            Aug 1 '13 at 18:50





            so how does .bashrc behave? after bash_profile? instead of .profile?

            – opensas
            Aug 1 '13 at 18:50




            1




            1





            @opensas You probably should ask as a separate question, referencing this one or the answer.

            – belacqua
            Aug 1 '13 at 21:21





            @opensas You probably should ask as a separate question, referencing this one or the answer.

            – belacqua
            Aug 1 '13 at 21:21













            @belacqua lets say I need to add 2 or more environment variables to /etc/environment like JAVA_HOME="/opt/java" and ANT_HOME="/opt/ant" how to do it

            – Kasun Siyambalapitiya
            Nov 16 '16 at 4:53





            @belacqua lets say I need to add 2 or more environment variables to /etc/environment like JAVA_HOME="/opt/java" and ANT_HOME="/opt/ant" how to do it

            – Kasun Siyambalapitiya
            Nov 16 '16 at 4:53











            7














            You've got:




            /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
            and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).




            which in Lucid and Maverick run



            /etc/profile.d/*.sh


            if present, and if the user's shell is bash:



            /etc/bash.bashrc


            For user environment, there is a confusing array specific to the shell and whether it is considered a "login shell". If the shell is bash:



               ~/.bash_profile
            The personal initialization file, executed for login shells
            ~/.bashrc
            The individual per-interactive-shell startup file


            for sh/dash:



            $HOME/.profile


            for zsh, I'm not even going to try to make sense of this.






            share|improve this answer




























              7














              You've got:




              /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
              and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).




              which in Lucid and Maverick run



              /etc/profile.d/*.sh


              if present, and if the user's shell is bash:



              /etc/bash.bashrc


              For user environment, there is a confusing array specific to the shell and whether it is considered a "login shell". If the shell is bash:



                 ~/.bash_profile
              The personal initialization file, executed for login shells
              ~/.bashrc
              The individual per-interactive-shell startup file


              for sh/dash:



              $HOME/.profile


              for zsh, I'm not even going to try to make sense of this.






              share|improve this answer


























                7












                7








                7







                You've got:




                /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
                and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).




                which in Lucid and Maverick run



                /etc/profile.d/*.sh


                if present, and if the user's shell is bash:



                /etc/bash.bashrc


                For user environment, there is a confusing array specific to the shell and whether it is considered a "login shell". If the shell is bash:



                   ~/.bash_profile
                The personal initialization file, executed for login shells
                ~/.bashrc
                The individual per-interactive-shell startup file


                for sh/dash:



                $HOME/.profile


                for zsh, I'm not even going to try to make sense of this.






                share|improve this answer













                You've got:




                /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
                and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).




                which in Lucid and Maverick run



                /etc/profile.d/*.sh


                if present, and if the user's shell is bash:



                /etc/bash.bashrc


                For user environment, there is a confusing array specific to the shell and whether it is considered a "login shell". If the shell is bash:



                   ~/.bash_profile
                The personal initialization file, executed for login shells
                ~/.bashrc
                The individual per-interactive-shell startup file


                for sh/dash:



                $HOME/.profile


                for zsh, I'm not even going to try to make sense of this.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 24 '10 at 3:53









                mswmsw

                4,19611826




                4,19611826























                    5














                    As recommended on https://help.ubuntu.com/community/EnvironmentVariables:




                    1. Global environment variables meant to affect all users should go in /etc/environment.


                    2. User-specific environment variables should be set in ~/.pam_environment.



                    Avoid the profile and rc files for setting environment variables on Ubuntu. They have caused me more headaches than they are worth.



                    This is easier said than done however ;)



                    It is possible that you may run into the same configuration gap that existed for me. See the workaround for encrypted home below.



                    My ~/.pam_environment:



                    PATH            DEFAULT=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${HOME}/bin
                    IDEA_JDK DEFAULT=${HOME}/Applications/jdk


                    Why the ugly static path? ${PATH} would not work for me. I bricked my login several times trying to work around it so I am sticking with the ugly static copy of the defaults :)



                    Workaround for Encrypted Home Folders



                    In Ubuntu releases up to and including Precise 12.04 Beta 2, if you are using an encrypted home directory you will need to modify /etc/pam.d/common-session to get it to load ~/.pam_environment. This solution apparently works for earlier releases, but I have not tested it.



                    Guenther Montag (g-montag) wrote on 2010-08-19:




                    This seems to be an issue with encrypted home directories. I added



                    session required pam_env.so



                    at the end of /etc/pam.d/common-session and now ~/.pam_environment gets read. On another system without encrypted home directories (also 10.04) the work around is not needed. Perhaps in my case the system tries to read ~/.pam_environment before it is decrypted.




                    Adapted from my answer on Super User: https://superuser.com/a/408373/66856






                    share|improve this answer


























                    • This is still wrong: ${HOME} won't work either. There is no expansion in .pam_environment.

                      – detly
                      Aug 7 '14 at 3:47






                    • 2





                      @detly there is expansion in .pam_environment, but HOME isn't set that early usually. If that line had read DEFAULT=${PATH}/Applications/jdk, you'd have seen the value of PATH inserted in it.

                      – muru
                      Jun 8 '16 at 19:54
















                    5














                    As recommended on https://help.ubuntu.com/community/EnvironmentVariables:




                    1. Global environment variables meant to affect all users should go in /etc/environment.


                    2. User-specific environment variables should be set in ~/.pam_environment.



                    Avoid the profile and rc files for setting environment variables on Ubuntu. They have caused me more headaches than they are worth.



                    This is easier said than done however ;)



                    It is possible that you may run into the same configuration gap that existed for me. See the workaround for encrypted home below.



                    My ~/.pam_environment:



                    PATH            DEFAULT=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${HOME}/bin
                    IDEA_JDK DEFAULT=${HOME}/Applications/jdk


                    Why the ugly static path? ${PATH} would not work for me. I bricked my login several times trying to work around it so I am sticking with the ugly static copy of the defaults :)



                    Workaround for Encrypted Home Folders



                    In Ubuntu releases up to and including Precise 12.04 Beta 2, if you are using an encrypted home directory you will need to modify /etc/pam.d/common-session to get it to load ~/.pam_environment. This solution apparently works for earlier releases, but I have not tested it.



                    Guenther Montag (g-montag) wrote on 2010-08-19:




                    This seems to be an issue with encrypted home directories. I added



                    session required pam_env.so



                    at the end of /etc/pam.d/common-session and now ~/.pam_environment gets read. On another system without encrypted home directories (also 10.04) the work around is not needed. Perhaps in my case the system tries to read ~/.pam_environment before it is decrypted.




                    Adapted from my answer on Super User: https://superuser.com/a/408373/66856






                    share|improve this answer


























                    • This is still wrong: ${HOME} won't work either. There is no expansion in .pam_environment.

                      – detly
                      Aug 7 '14 at 3:47






                    • 2





                      @detly there is expansion in .pam_environment, but HOME isn't set that early usually. If that line had read DEFAULT=${PATH}/Applications/jdk, you'd have seen the value of PATH inserted in it.

                      – muru
                      Jun 8 '16 at 19:54














                    5












                    5








                    5







                    As recommended on https://help.ubuntu.com/community/EnvironmentVariables:




                    1. Global environment variables meant to affect all users should go in /etc/environment.


                    2. User-specific environment variables should be set in ~/.pam_environment.



                    Avoid the profile and rc files for setting environment variables on Ubuntu. They have caused me more headaches than they are worth.



                    This is easier said than done however ;)



                    It is possible that you may run into the same configuration gap that existed for me. See the workaround for encrypted home below.



                    My ~/.pam_environment:



                    PATH            DEFAULT=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${HOME}/bin
                    IDEA_JDK DEFAULT=${HOME}/Applications/jdk


                    Why the ugly static path? ${PATH} would not work for me. I bricked my login several times trying to work around it so I am sticking with the ugly static copy of the defaults :)



                    Workaround for Encrypted Home Folders



                    In Ubuntu releases up to and including Precise 12.04 Beta 2, if you are using an encrypted home directory you will need to modify /etc/pam.d/common-session to get it to load ~/.pam_environment. This solution apparently works for earlier releases, but I have not tested it.



                    Guenther Montag (g-montag) wrote on 2010-08-19:




                    This seems to be an issue with encrypted home directories. I added



                    session required pam_env.so



                    at the end of /etc/pam.d/common-session and now ~/.pam_environment gets read. On another system without encrypted home directories (also 10.04) the work around is not needed. Perhaps in my case the system tries to read ~/.pam_environment before it is decrypted.




                    Adapted from my answer on Super User: https://superuser.com/a/408373/66856






                    share|improve this answer















                    As recommended on https://help.ubuntu.com/community/EnvironmentVariables:




                    1. Global environment variables meant to affect all users should go in /etc/environment.


                    2. User-specific environment variables should be set in ~/.pam_environment.



                    Avoid the profile and rc files for setting environment variables on Ubuntu. They have caused me more headaches than they are worth.



                    This is easier said than done however ;)



                    It is possible that you may run into the same configuration gap that existed for me. See the workaround for encrypted home below.



                    My ~/.pam_environment:



                    PATH            DEFAULT=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${HOME}/bin
                    IDEA_JDK DEFAULT=${HOME}/Applications/jdk


                    Why the ugly static path? ${PATH} would not work for me. I bricked my login several times trying to work around it so I am sticking with the ugly static copy of the defaults :)



                    Workaround for Encrypted Home Folders



                    In Ubuntu releases up to and including Precise 12.04 Beta 2, if you are using an encrypted home directory you will need to modify /etc/pam.d/common-session to get it to load ~/.pam_environment. This solution apparently works for earlier releases, but I have not tested it.



                    Guenther Montag (g-montag) wrote on 2010-08-19:




                    This seems to be an issue with encrypted home directories. I added



                    session required pam_env.so



                    at the end of /etc/pam.d/common-session and now ~/.pam_environment gets read. On another system without encrypted home directories (also 10.04) the work around is not needed. Perhaps in my case the system tries to read ~/.pam_environment before it is decrypted.




                    Adapted from my answer on Super User: https://superuser.com/a/408373/66856







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 20 '17 at 10:18









                    Community

                    1




                    1










                    answered Apr 4 '12 at 4:16









                    Alain O'DeaAlain O'Dea

                    53156




                    53156













                    • This is still wrong: ${HOME} won't work either. There is no expansion in .pam_environment.

                      – detly
                      Aug 7 '14 at 3:47






                    • 2





                      @detly there is expansion in .pam_environment, but HOME isn't set that early usually. If that line had read DEFAULT=${PATH}/Applications/jdk, you'd have seen the value of PATH inserted in it.

                      – muru
                      Jun 8 '16 at 19:54



















                    • This is still wrong: ${HOME} won't work either. There is no expansion in .pam_environment.

                      – detly
                      Aug 7 '14 at 3:47






                    • 2





                      @detly there is expansion in .pam_environment, but HOME isn't set that early usually. If that line had read DEFAULT=${PATH}/Applications/jdk, you'd have seen the value of PATH inserted in it.

                      – muru
                      Jun 8 '16 at 19:54

















                    This is still wrong: ${HOME} won't work either. There is no expansion in .pam_environment.

                    – detly
                    Aug 7 '14 at 3:47





                    This is still wrong: ${HOME} won't work either. There is no expansion in .pam_environment.

                    – detly
                    Aug 7 '14 at 3:47




                    2




                    2





                    @detly there is expansion in .pam_environment, but HOME isn't set that early usually. If that line had read DEFAULT=${PATH}/Applications/jdk, you'd have seen the value of PATH inserted in it.

                    – muru
                    Jun 8 '16 at 19:54





                    @detly there is expansion in .pam_environment, but HOME isn't set that early usually. If that line had read DEFAULT=${PATH}/Applications/jdk, you'd have seen the value of PATH inserted in it.

                    – muru
                    Jun 8 '16 at 19:54


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f4667%2fwhere-to-declare-environment-variables%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    數位音樂下載

                    When can things happen in Etherscan, such as the picture below?

                    格利澤436b