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.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
ha9u63a7
  • 230

2 Answers2

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.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
-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.

AdminBee
  • 22,803