1. Manually install JDK 6
First, download the http://java.sun.com in the jdk-6u12-linux-i586.bin, it is said that this operation is relatively simple, do not need to switch.
Then, you can place it in any folder you like and I will place it under the folder (/usr/lib/JVM/Java.
The command is as follows:
Create a folder: yangliping @ yangliping-LAPTOP:/usr/lib/JVM/Java $ sudo mkdir-P/usr/lib/JVM/Java
Copy the downloaded file to this directory: (the downloaded file is located in/home/yangliping/downloads)
Yangliping @ yangliping-LAPTOP:/usr/lib/JVM/Java $ sudo CP/home/yangliping/downloads/jdk-6u21-linux-i586.bin/usr/lib/JVM/Java/
Go to the new directory: yangliping @ yangliping-LAPTOP:/usr/lib/JVM/Java $ CD/usr/lib/JVM/Java
View JDK installation directory and installation package permissions:
Yangliping @ yangliping-LAPTOP:/usr/lib/JVM/Java $ LS-la
Total 81904
Drwxr-XR-x 3 Root 4096.
Drwxr-XR-x 3 Root 4096 ..
-Rwxrwxrwx 1 Root 83854743 jdk-6u21-linux-i586.bin
If you do not have the preceding permissions, You need to modify the binfile permission to make it executable:
Yangliping @ yangliping-LAPTOP:/usr/lib/JVM/Java $ sudo chmod 777 jdk-6u21-linux-i586.bin
Install JDK as follows:
Yangliping @ yangliping-LAPTOP:/usr/lib/JVM/Java $ Sudo-S./jdk-6u21-linux-i586.bin
After installation, configure the environment variables as follows:
Configure classpath and modify the environment variables of all users
Yangliping @ yangliping-LAPTOP:/usr/lib/JVM/Java $ sudo gedit/etc/environment
Add at the end of the file:
Path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/Games"
# Set Java environment
Java_home =/usr/lib/JVM/Java/jdk1.6.0 _ 21
Export jre_home =/usr/lib/JVM/Java/jdk1.6.0 _ 21/JRE
Export classpath =.: $ java_home/lib: $ jre_home/lib: $ classpath
Export Path = $ java_home/bin: $ jre_home/bin: $ path
PS: The above red part is configured based on the version you decompressed
(When I started Ubuntu again this morning, I found that I was unable to enter the desktop because I loaded the variable at startup and an error occurred. I entered another character in the Java variable, as a result, variables cannot be correctly identified, so the desktop cannot be accessed and the logon interface is stuck. The solution is as follows:
1: boot to the login interface, switch to the character interface: CTRL + ALT + F1 (or CTRL + ALT + F2....) to enter the character mode,
2: Log On As root,
3: At this time, even the VI command cannot be identified. You need to modify and set the path first:
Export Path = $ path:/usr/bin:/usr/sbin:/etc:/usr/sbin:/usr/bin/X11:/sbin
4: Edit VI/etc/environment to save the correct variables and exit.
5: reboot)
The following code must be executed when the default JDK exists in Ubuntu. Add the installed JDK to the Java option:
yangliping@yangliping-laptop:/usr/lib/jvm/java$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java/jdk1.6.0_21 /bin/java 300
update-alternatives: using /usr/lib/jvm/java/jdk1.6.0_21 /bin/java to provide /usr/bin/java (java) in auto mode.
yangliping@yangliping-laptop:/usr/lib/jvm/java$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java/jdk1.6.0_21 /bin/javac 300
update-alternatives: using /usr/lib/jvm/java/jdk1.6.0_21/bin/javac to provide /usr/bin/javac (javac) in auto mode.
Then execute the default JDK code:
sudo update-alternatives --config java
Then execute the code in shell:
yangliping@yangliping-laptop:/var$ java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) Server VM (build 17.0-b16, mixed mode)
In this case, the Java in the system is the Java
To write a helloubuntu test:
yangliping@yangliping-laptop:/var$ sudo gedit HelloUbuntu.java
public class HelloUbuntu{
public static void main(String[] args){
System.out.println("HELLO Ubuntu 10.04 LTS ");
}
}
Run the following Java command:
yangliping@yangliping-laptop:~$ javac HelloUbuntu.java
yangliping@yangliping-laptop:~$ java HelloUbuntu
------------------------------------------------
HELLO Ubuntu 10.04 LTS