JDK can be installed in multiple ways in Ubuntu, for example, search for "sun-java6-jre" and "sun-java6-jdk" and tag the installation with adept/new software manager, and install with the apt-GET command (SUDO apt-Get install sun-java6-jre, sudo apt- get install sun-java6-jdk), You can also download the JDK installation file from the Java official website for manual installation (I downloaded the file is: jdk-6u20-linux-i586.bin), which is exactly a kind of installation method described in this article.
By default, the installation files downloaded from the official website (such as: jdk-6u20-linux-i586.bin) are not permitted to execute, You can query the relevant information through the $ LS-l command, so the first step is to give the Installation File executable permissions, can be achieved through the command $ sudo chmod U + x/usr/lib/Java/jdk-6u20-linux-i586.bin.
After successfully modifying the permissions of the Installation File, run the command $ CD/usr/lib/Java/to enter the directory where the installation file is located, and then run the command $. /jdk-6u20-linux-i586.bin screen will show JDK installation information, and then press enter until the screen display requires the input YES/NO, then enter y and press enter, the current directory contains an additional JDK 1.6.0 _ 20 Directory, which means JDK has been installed successfully.
After successfully installing the JDK, We will configure the JDK and use the command $ sudo gedit/etc/environment to modify the environment file and add the followingCode:
Java code
- Path ="/Usr/lib/Java/jdk1.6.0 _ 20/bin"
- Classpath ="/Usr/lib/Java/jdk1.6.0 _ 20/lib"
- Java_home ="/Usr/lib/Java/jdk1.6.0 _ 20"
Path = "/usr/lib/Java/jdk1.6.0 _ 20/bin" classpath = "/usr/lib/Java/jdk1.6.0 _ 20/lib" java_home = "/usr/lib/ java/jdk1.6.0 _ 20"
If path already exists, use the colon as the interval to add the bin directory address of JDK, so that the Java environment variable is configured successfully, however, the JDK used by default may not have been installed just now, Because ubuntu may also have a default JDK, such as openjdk; therefore, in order to make the JDK installed by default, you also need to execute the following command:
Java code
- $ sudo Update-alternatives -- install/usr/bin/Java/usr/lib/Java/jdk1. 6 . 0_20/bin/Java 300
-
- $ sudo Update-alternatives -- install/usr/bin/javac/usr/lib/Java/jdk1. 6 . 0_20/bin/javac 300
-
- $ sudo Update-alternatives -- config Java
$ Sudo Update-alternatives -- install/usr/bin/Java/usr/lib/Java/jdk1.6.0 _ 20/bin/Java 300 $ sudo Update-alternatives -- install/usr/bin /javac/usr/lib/Java/jdk1.6.0 _ 20/bin/javac 300 $ sudo Update-alternatives -- config Java
After the command is successfully executed, the JDK we installed is the default one. You can run $ Java-version to view the JDK information, for example:
Java code
- Java version"1.6.0 _ 20"
- Java (TM) se Runtime Environment (build1.6. 0_20-b02)
- Java hotspot (TM) server VM (build16.3-B01, mixed mode)