setting JAVA_HOME & CLASSPATH in CentOS 6

后端 未结 7 2523
无人共我
无人共我 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:55

    I had to change /etc/profile.d/java_env.sh to point to the new path and then logout/login.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-15 04:57

    Instructions:

    1. Click on the Terminal icon in the desktop panel to open a terminal window and access the command prompt.
    2. Type the command which java to find the path to the Java executable file.
    3. Type the command su - to become the root user.
    4. Type the command vi /root/.bash_profile to open the system bash_profile file in the Vi text editor. You can replace vi with your preferred text editor.
    5. Type export JAVA_HOME=/usr/local/java/ at the bottom of the file. Replace /usr/local/java with the location found in step two.
    6. Save and close the bash_profile file.
    7. Type the command exit to close the root session.
    8. Log out of the system and log back in.
    9. Type the command echo $JAVA_HOME to ensure that the path was set correctly.

    set java_home in centos

    0 讨论(0)
  • 2020-12-15 04:59

    Providing javac is set up through /etc/alternatives/javac, you can add to your .bash_profile:

    JAVA_HOME=$(l=$(which javac) ; while : ; do nl=$(readlink ${l}) ; [ "$nl" ] || break ; l=$nl ; done ; echo $(cd $(dirname $l)/.. ; pwd) )
    export JAVA_HOME
    
    0 讨论(0)
  • 2020-12-15 05:16

    Do the following steps:

    1. sudo -s
    2. yum install java-1.8.0-openjdk-devel
    3. vi .bash_profile , and add below line into .bash_profile file and save the file.

    export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/

    Note - I am using CentOS7 as OS.

    0 讨论(0)
  • 2020-12-15 05:17

    It seems that you dont have any problem with the environmental variables.

    Compile your file from src with

    javac a/A.java

    Then, run your program as

    java a.A

    0 讨论(0)
提交回复
热议问题