Reputation: 131
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.
Upvotes: 1
Views: 215
Reputation: 15550
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
Upvotes: 0
Reputation: 263
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.
Upvotes: 0
Reputation: 11117
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?
Upvotes: 3
Reputation: 121710
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.
Upvotes: 0