2

I added the following in /etc/profile so that all my users can see the path

export JAVA_HOME=/opt/jdk11
export PATH=$PATH:$JAVA_HOME/bin

But after restarting my laptop, I cannot see the changes using echo $JAVA_PATH. I thought there is an order for how the scripts are loaded. and Also, If I was to add this changes into a separate sh file in /etc/profile.d, it's supposed to do the same. So why is it that it's failing to see the path changes.

5
  • 1
    JAVA_PATH or JAVA_HOME? You assign one but mention the other in the echo.
    – ilkkachu
    Commented Mar 13, 2019 at 22:15
  • @ilkkachu thanks for correcting the typo
    – ha9u63a7
    Commented Mar 13, 2019 at 22:16
  • 1
    Just asking to verify that you didn't accidentally set the wrong variable. You could edit your question to clarify it, just so that no-one else makes the wrong interpretation.
    – ilkkachu
    Commented Mar 13, 2019 at 22:21
  • See wiki.debian.org/EnvironmentVariables for the official stance. Commented Mar 14, 2019 at 8:36
  • All users might enjoy of variables, settings, aliases and other stuff which is places in /etc/profile. Commented Dec 16, 2021 at 7:32

2 Answers 2

1

Perhaps you are testing in a non-interactive shell. For interactive shells, both /etc/profile and /etc/bash.bashrc are sourced, but for non-interactive shells, only /etc/bash.bashrc is sourced. You might try putting your variables in that file.

/etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile and related files on other shells are discussed at length in this answer.

1
  • I think it's the latter. Thanks for explaining the interactive shell concept. Appreciated!
    – ha9u63a7
    Commented Mar 13, 2019 at 22:41
-1

First lines in /etc/bash.bashrc state this:

System-wide .bashrc file for interactive bash(1) shells.

To enable the settings / commands in this file for login shells as well,
this file has to be sourced in /etc/profile.

So, system wide additional environment variables, to use in any user terminal, should be located in it. Even root environment will use these.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.