Note: It is best to perform the following operations under the root permission:
All the background colors are terminal commands.
JDK
- Download JDKStarting from which version of ubuntu apt-Get install is installed by default with openjdk. Although there is little difference, to prevent unexpected errors, download and install sun-JDK. Download the latest JDK http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.htm to Oracle official website.
- Decompress the fileGeneral direct download .tar.gz format files, manually or terminal commands extract tar-xzf jdk-7-linux-i586.tar.gz, get the folder jdk1.7.0.
- Move the JDK folderYou are free to choose. Generally, the development habits are put under the/usr/local/folder, and some people prefer to put it under/opt, you can also place the JDK address/usr/lib/JVM/in the system by default. This address also contains different versions of openjdk, if there is no JVM folder, create a mkdir/usr/lib/JVM. The root permission is required to move to these two addresses, MV jdk1.7.0/usr/lib/JVM. Generally in order to facilitate the configuration of environment variables, JDK file rename, the general online JDK file rename jdk-7-sun, MV/usr/lib/JVM/jdk1.7.0/usr/lib/JVM/Java-7-sun.
- Configure Environment VariablesIf Vim is installed, run Vim ~ /. Bashrc. If no, run gedit directly ~ /. Bashrc
export JAVA_HOME=/usr/lib/jvm/java-7-sunexport JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/libexport PATH=${JAVA_HOME}/bin:$PATHSave the environment variable, exit the editor, and enter the command to make it take effect. Source ~ /. Bashrc. Enter the Env command to check whether the setting is successful.
- Configure the default JDKConfigure the JDK you installed as the default JDK. Enter the following command:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-sun/bin/java 300sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-7-sun/bin/javac 300sudo update-alternatives --config java
If another JDK is installed in the system, you will be prompted to select the corresponding JDK 7.
- Test the JDK version.Enter the Java-version command to view the JDK version. If the result is similar to the following, the configuration is successful.
java version "1.7.0" Java(TM) SE Runtime Environment (build 1.7.0-b147) Java HotSpot(TM)
In the last step, an error may occur,
Bash:/usr/lib/JVM/Java-7-sun/bin/Java: the file or directory does not exist.
This is because the lack of 32-bit Runtime Library ia32-libs, 64-bit system installed 32-bit JDK, install this Runtime Library can solve
sudo apt-get install ia32-libs
After the installation is complete, the original openjdk does not need to be deleted. You can change it later.