1. Installation
Download the Sun Java package, then unzip the file tar-zxvf xxx.tar.gz, then MV JDK folder/usr/local/jdk
Then set the environment variable
sudo gedit/etc/profile
- Java_home=/usr/local/jdk
- export jre_home=/usr/local/jdk /JRE
- export CLASSPATH=.:$JAVA _home/lib:$JRE _home/lib:$CLASSPATH
- export PATH=$JAVA _home/bin:$JRE _home/bin:$PATH
2. Configuration
If you set the Global environment variable (for the user you are using):
[Email protected]:/opt$sudogedit/etc/Profile
export java_home=/opt/jdk1.6.0_26
Export path= $JAVA _home/bin:$PATH
Export classpath= $CLASSPATH: $JAVA _home/lib
Add the above, unchanged copy to the end of the file (after umask022).
(Ps,linux's path delimiter is a colon ":", we know that win is a semicolon ";", here should not be left in the semicolon before and after the blank, I have to look at some of the people to add a few before and after the space, the results can be imagined, all orders can not be used, the consequences are very serious ah! Open shell, also reported: Bash:export: '/opt/jdk1.6.0_26/bin: ': Not a valid identifier)
Of course, you can set environment variables for the current user only, based on security considerations:
[Email protected]:~$ GEDIT.BASHRC
Copy the above three lines of the export statement to the end of the file.
-Set Default JDK
SUNJDK has been installed, but when we use java-version found, is still used by the old openjdk.
We need to change the system's default JDK settings:
[email protected]:/opt$sudoupdate-alternatives--install/usr/bin/java Java/opt/jdk1.6.0_26/bin/java 300
[Email protected]:/opt$ sudoupdate-alternatives--install/usr/bin/javac Javac/opt/jdk1.6.0_26/bin/javac -
Update-alternatives:using/opt/jdk1.6.0_26/bin/javac to Provide/usr/bin/javac (JAVAC) Inauto mode.
Next, let's look at the JDK that already exists in the system:
[Email protected]:/opt$ sudoupdate-alternatives--list java
/opt/jdk1.6.0_26/bin/java
/usr/lib/jvm/java-6-openjdk/jre/bin/java
Configuration:
[Email protected]:/opt$ sudoupdate-alternatives--config java
There is 2 choices for thealternative Java (Providing/usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
*0/usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 Auto Mode
1/opt/jdk1.6.0_26/bin/java Manual Mode
2/usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 Manual Mode
Press ENTER to keep thecurrent choice[*], or type selection number:1
Update-alternatives:using/opt/jdk1.6.0_26/bin/java to Provide/usr/bin/java (Java) in Manualmode.
* Indicates the current default JDK, which can be seen as OPENJDK, and you can see the sunjdk that you just installed, the sequence number is 1, and the status value 300 that was previously set.
Here you need to enter the default number of the set, here of course we choose 1.
Here, you can execute the command again to see if our settings are OK:
[Email protected]:/opt$ sudoupdate-alternatives--config java
There is 2 choices for thealternative Java (Providing/usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0/usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 Auto Mode
*1/opt/jdk1.6.0_26/bin/java Manual Mode
2/usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 Manual Mode
Press ENTER to keep thecurrent choice[*], or type selection number:1
since the SUNJDK has been successfully set up here, there is no effect after repeating the selection here.
-Verify default JDK
Log off and re-login, using the command java-version
[email protected]:~$ java-version
javaversion "1.6.0_26"
Java (TM) SE runtimeenvironment (build 1.6.0_26-b03)
Java HotSpot (TM) 64-bitserver VM (build 20.1-b02, Mixed mode)
As you can see, it's already the default sun jdk.
Installation and configuration of Sun Java under Ubuntu