1

There are various ways to set the JAVA_HOME variable in ubuntu , simply write the following lines:

JAVA_HOME = / usr/lib/jvm/java-...... 

export JAVA_HOME 

etc ...

but what's the DIFFERENCE if these commands are added:

1] in /etc/profile.d/java.sh 2] in .Profile

Or another way.

Hüseyin BABAL
  • 15,400
  • 4
  • 51
  • 73
Esse
  • 121
  • 1
  • 5

4 Answers4

3

If you only want to change the variable in your terminal windows, set it in .bashrc file, which is sourced each time a new terminal is opened. .profile file is not sourced each time you open a new terminal.

See the difference between .profile and .bashrc in question: What's the difference between .bashrc, .bash_profile, and .environment?

Community
  • 1
  • 1
TheEwook
  • 11,037
  • 6
  • 36
  • 55
  • I have a related question here. Please help me to fix the problem -http://stackoverflow.com/questions/28931383/error-java-home-is-not-defined-correctly-despite-setting-it – stack1 Mar 08 '15 at 20:51
0

The first option will apply to all users.

The second (I suppose you mean $HOME/.profile) applies only to you.

Note that system wide, if you have several JDKs installed with your package manager, you may want to use the update-alternatives command.

Note however that .profile only applies to login shells; you had better put these lines into .bashrc instead.

fge
  • 119,121
  • 33
  • 254
  • 329
0

The first method keeps JAVA_HOME environment variable active only till the time the terminal session is active. If you close the terminal type $JAVA_HOME again it will fail.

The second option adds it to the profile of the user making it like a permanent environment variable which will persist even after a restart.

Mobility
  • 263
  • 2
  • 5
0

Let say that, you want to add an environment variable on current terminal like JAVA_HOME, or HTTP_PROXY you can directly set it with export command. When you close terminal, that assignment will be lost. Simply, it is instant assignment for that running operation.

In second option, if you define an entry to .bashrc, it will be available to logged in user that has .bashrc. If you want to set permanent variables for specific user, you can define it in .bashrc in user's home folder.

Additionally, if you put export commant in /etc/environment, it will be available to all users

Hüseyin BABAL
  • 15,400
  • 4
  • 51
  • 73
  • I have a related question here. Please help me to fix the problem -http://stackoverflow.com/questions/28931383/error-java-home-is-not-defined-correctly-despite-setting-it – stack1 Mar 08 '15 at 20:55