setting JAVA_HOME & CLASSPATH in CentOS 6

后端 未结 7 2529
无人共我
无人共我 2020-12-15 04:45

I have unpacked my jdk in /usr/java/.

and I put CLASSPATH, PATH, JAVA_HOME into /etc/profile like below.

export JAVA_HOME=/usr/java/jdk1.7.0_21
expor         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 04:56

    Search here for centos jre install all users:

    The easiest way to set an environment variable in CentOS is to use export as in

    $> export JAVA_HOME=/usr/java/jdk.1.5.0_12
    
    $> export PATH=$PATH:$JAVA_HOME
    

    However, variables set in such a manner are transient i.e. they will disappear the moment you exit the shell. Obviously this is not helpful when setting environment variables that need to persist even when the system reboots. In such cases, you need to set the variables within the system wide profile. In CentOS (I’m using v5.2), the folder /etc/profile.d/ is the recommended place to add customizations to the system profile. For example, when installing the Sun JDK, you might need to set the JAVA_HOME and JRE_HOME environment variables. In this case: Create a new file called java.sh

    vim /etc/profile.d/java.sh
    

    Within this file, initialize the necessary environment variables

    export JRE_HOME=/usr/java/jdk1.5.0_12/jre
    export PATH=$PATH:$JRE_HOME/bin
    
    export JAVA_HOME=/usr/java/jdk1.5.0_12
    export JAVA_PATH=$JAVA_HOME
    
    export PATH=$PATH:$JAVA_HOME/bin
    

    Now when you restart your machine, the environment variables within java.sh will be automatically initialized (checkout /etc/profile if you are curious how the files in /etc/profile.d/ are loaded).

    PS: If you want to load the environment variables within java.sh without having to restart the machine, you can use the source command as in:

    $> source java.sh
    

提交回复
热议问题