Install JDK on Linux

Method 1:

#Before you download, please check you Linux version(32bit/64bit)

1. Download the file to the target folder ,for example opt/

32bit

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin"

64bit

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin"

2. sh jdk-6u45-linux-x64.bin

3.  mv jdk1.6.0_45 java

4. Edit /etc/profile  or .bash_profile or .cshrc

  • C shell:(.cshrc)

    setenv JAVA_HOME jdk-install-dir
    
    setenv PATH $JAVA_HOME/bin:$PATH

or

export JAVA_HOME=/usr/java/jdk1.6.0_27
export JAVA_BIN=/usr/java/jdk1.6.0_27/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

5. source /etc/profile

6. java -version

SELECT ALL

JDK 8

    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-arm-vfp-hflt.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-i586.rpm
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-i586.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-x64.rpm
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-x64.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-macosx-x64.dmg
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-solaris-x64.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-solaris-x64.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-solaris-sparcv9.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-solaris-sparcv9.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-windows-i586.exe
    http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-windows-x64.exe

JDK 7u51

    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-arm-vfp-hflt.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-arm-vfp-sflt.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-i586.rpm
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-i586.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.rpm
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-macosx-x64.dmg
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-solaris-i586.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-solaris-i586.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-solaris-x64.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-solaris-x64.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-solaris-sparc.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-solaris-sparc.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-solaris-sparcv9.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-solaris-sparcv9.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-windows-i586.exe
    http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-windows-x64.exe

JDK 7u45

    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-arm-vfp-hflt.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-arm-vfp-sflt.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-i586.rpm
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-i586.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.rpm
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-macosx-x64.dmg
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-solaris-i586.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-solaris-i586.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-solaris-x64.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-solaris-x64.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-solaris-sparc.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-solaris-sparc.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-solaris-sparcv9.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-solaris-sparcv9.tar.gz
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-windows-i586.exe
    http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-windows-x64.exe

JDK 6u45

    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586-rpm.bin
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64-rpm.bin
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-solaris-i586.sh
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-solaris-i586.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-solaris-sparc.sh
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-solaris-sparc.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-solaris-sparcv9.sh
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-solaris-sparcv9.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-solaris-x64.sh
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-solaris-x64.tar.Z
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-windows-i586.exe
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-windows-x64.exe
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-ia64-rpm.bin
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-ia64.bin
    http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-windows-ia64.exe

Method 2: 

1. Download jdk tar.gz file from the link below to the target folder, for example opt/

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-i586.tar.gz"

2. tar -zxvf jdk-7u45-linux-i586.tar.gz

3. mv jdk1.7.0_45 java

4. Edit /etc/profile 

export JAVA_HOME=/usr/java/jdk1.6.0_27
export JAVA_BIN=/usr/java/jdk1.6.0_27/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

5. source /etc/profile

6. Edit default java path

update-alternatives --install /usr/bin/java java /opt/java/bin/java 300

update-alternatives --install /usr/bin/javac javac /opt/java/bin/javac 300

update-alternatives --config java

update-alternatives --config javac

7. java -version


Install  java on the centos

OpenJDK 6
yum install java-1.6.0-openjdk-devel
OpenJDK 7
yum install java-1.7.0-openjdk-devel

  1. Optional: Set the JAVA_HOME environment variable.

    Some applications such as Apache Maven and Apache Ant require you to set the JAVA_HOME environment variable. If you need to do this, follow these steps.
    1. Determine the correct value for JAVA_HOME. Red Hat Enterprise Linux installs OpenJDK 1.6 into either /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/ or /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/, depending on whether your system is a 32-bit or 64-bit architecture. The JAVA_HOME should point to the directory containing a bin/java executable.
    2. As the user who will use OpenJDK, open the shell configuration file. For the Bash shell, this file is /home/username/.bashrc.
    3. At the bottom of the file, type the following line, replacing the hypothetical path with the actual path to use on your own system: export JAVA_HOME="/path/to/java/home"
    4. Save the file, and log out of and back into your session.
  2. Switch between different OpenJDK versions using the alternatives utility.

    Red Hat Enterprise Linux includes a utility called alternatives, which lets you change the default version for applications which allow multiple versions to be installed. OpenJDK is one such application.
    To use the alternatives utility, perform the following steps. Note that setting the environment variables overrides the behavior of the alternatives command. For instance, if you use a script which manually sets $JAVA_HOME and $JAVA variables to a different JDK from the one specified by the alternatives command, the environment variables will override the command.
    • Log in as the root user, or prefix the commands below with the sudo command.
    • The alternatives command is not installed by default, but may already be installed on your system. If not, install the alternatives package by running the following command:
      yum install alternatives
    • Issue the following command:
      /usr/sbin/alternatives --config java
    • Follow the prompts that follow to set the default version of OpenJDK.
Result:
OpenJDK is installed on your server and available for your use. If necessarily, the JAVA_HOMEenvironment variable has been specified as well. If necessary, the default OpenJDK for your system has been set using the alternatives utility.


Edit .cshrc for csh 

setenv JAVA_HOME /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64
set path=($path $JAVA_HOME/bin)
set path=($path $HOME/java/java_scripts)
setenv CLASSPATH $ORACLE_HOME/jdbc/lib/ojdbc14.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章