Discussion on the method of modifying and and setting environment variable JAVA_HOME under Linux

  • 2021-08-17 01:49:41
  • OfStack

1. Permanently modified, valid for all users

# vi /etc/profile

//Press the keyboard [Shift + g] and add the following at the end of the profile file:


JAVA_HOME=/usr/local/java/jdk1.7.0_25
JRE_HOME=$JAVA_HOME/jre
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME JRE_HOME CLASSPATH
 Or 
export JAVA_HOME = /home/myuser/jdk1.7.0_03
export PATH = $JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

#oracle Related variable 
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export PATH=/u01/app/oracle/product/11.2.0/dbhome_1/bin:/bin:/usr/bin:/usr/sbin:/usr
/local/bin:/usr/X11R6/bin
export PATH=$ORACLE_HOME/bin:$PATH:/sbin/

[Note]: If you want to take effect immediately after modifying the file, you must run it #source /etc/profile

2. Permanently modified, valid for single 1 users


// Under the user directory .bash_profile Documents 
$ vi /home/myuser/.bash_profile
// Add the following at the end of the file 
export JAVA_HOME = /home/myuser/jdk1.7.0_03
export PATH = $JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

[Note]: If you want to take effect immediately after modifying the file, you must run it #source /home/myuser/.bash_profile

3. Effective for current bash/shell only


$ export JAVA_HOME = /home/myuser/jdk1.7.0_03
$ export PATH = $JAVA_HOME/bin:$PATH
$ export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

Related articles: