Ubuntu jdk 8 and 6 switch (installation and configuration)

 

 

  1. Switch To Oracle JDK8

 

1 Switch To Oracle JDK8 
1.1 Switch Oracle JDK in the Unbuntu 14.04 

Step1 :  Download a .tar.gz from Oracle(here i will be using jdk-8u91-linux-x64.tar.gz)    http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Step2 :   Extract it to directory /usr/lib/jvm
 After extract it and set the permission 
$sudo chmod -R 777 /usr/lib/jvm/jdk1.8.0_91/

Step3 : Update the new JAVA environment , run below command one by one 

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_91/bin/java" 1

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_91/bin/javac" 1

sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0_91/bin/javaws" 1


Step 4: Run below command to update the JAVA environment 
sudo update-alternatives --config java


root@icilubuntu-HP-Compaq-6000-Pro-MT-PC:/usr/lib/jvm/oracle-jdk-6u35# sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                               Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java      1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java      1061      manual mode
  2            /usr/lib/jvm/jdk1.8.0_91/bin/java   1         manual mode

Press enter to keep the current choice[*], or type selection number: 

Select the number of  new /usr/lib/jvm/jdk1.8.0_91/bin/java and press Enter . 

Now confirm that java command is the new installed one 
Type: java -version
Should show:
java version "1.8.0_91"

Java(TM) SE Runtime Environment (build 1.8.0_91-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)







Step 5:sudo gedit /etc/profile  

Then add the following to it
1. export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_91  
2. export JRE_HOME=/usr/lib/jvm/jdk1.8.0_91/jre  
3. export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin  
4. export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH  

Save and exit, enter the following command to make the above settings take effect
1. source /etc/profile  


Step 6: Set the Eclipse default JAVA environment 

Open Eclipse to menu Window-> Preferences-Installed JREs , set it to the new JDK path 
View Code

Switch To Oracle JDK6

 

 

Switch To  Oracle JDK6

1. Install the oracle JDK as below 
Step1 :  Create “oracle-jdk-6u35”  under “usr/lib/jvm/
Step2 :   Put the  jdk-6u35-linux-x64.bin to “/usr/lib/jvm/oracle-jdk-6u35” and install the JDK
 Type : $/usr/lib/jvm/oracle-jdk-6u35# ./jdk-6u35-linux-x64.bin 
*  jdk-6u35-linux-x64.bin      http://192.168.18.224:8888/svn/Work_Space/Prototype/Integration_Workspace/software_env/jdk-6u35-linux-x64.bin
2. Set /etc/alternatives which ensure all the java related programs are using the
same one, if not, will get the peer not authenticated error as below

12:32:07,877 WARN [PortalImpl:4898] com.liferay.portal.kernel.exception.SystemException: org.jets3t.service.S3ServiceException: Request Error: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated 

  Step1: copy /usr/lib/jvm/.java-6-openjdk.jinfo to /usr/lib/jvm/.oracle-jdk-6u35.jinfo 
          Type:  cp .java-6-openjdk.jinfo .oracle-jdk-6u35.jinfo 

Step 2: Register new alternatives in update-alternatives mechanism. Type:
cat .oracle-jdk-6u35.jinfo | grep -E '^(hl|jre|jdk)' | awk '{print "/usr/bin/" $2 " " $2 " " $3 " 30 \n"}' | xargs -t -n4 sudo update-alternatives --verbose --install 


Step3 : Check if successful registered, type:
update-java-alternatives -l
Then should show:
oracle-jdk-6u35 30 /usr/lib/jvm/oracle-jdk-6u35 


Step4 :  Set chosen option , type:
           sudo update-java-alternatives -s oracle-jdk-6u35
update-alternatives: error: no alternatives for mozilla-javaplugin.so <<ignore it>>
Now confirm that java command is the new installed one 
Type: java -version
Should show:
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)


Step5 :  Copy the certificates from openjdk directory to oracle sun directory
Type: ls -l /etc/alternatives/keytool
Should show: /etc/alternatives/keytool -> /usr/lib/jvm/oracle-jdk-6u35/jdk1.6.0_35/jre/bin/keytool

Type: sudo cp /usr/lib/jvm/java-6-openjdk/jre/lib/security/jssecacerts /usr/lib/jvm/oracle-jdk-6u35/jdk1.6.0_35/jre/lib/security
sudo cp /usr/lib/jvm/java-6-openjdk/jre/lib/security/cacerts /usr/lib/jvm/oracle-jdk-6u35/jdk1.6.0_35/jre/lib/security

Step6 : set JAVA_HOME in tomcat's startup script /etc/init.d/tomcat6
export JAVA_HOME=/usr/lib/jvm/oracle-jdk-6u35/jdk1.6.0_35
View Code

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325571712&siteId=291194637