Configuring Java JDK in Ubuntu should be a required skill for every Java developer. Previously, it was always a rough configuration without summary or review. Let's summarize it today!
Some of the content in this article comes from the network, and the configuration process is prepared for use. The most classic part of this article is the switching method between multi-version JDK!
Installation
1. Uninstall the built-in OpenJdk
$ sudo apt-get purge openjdk*
2. After the JDK is installed and downloaded, the 64-bit Linux version officially provided by Oracle has the tar.gz format for JDK 1.7, but JDK 1.6 has the bin format. This document will record it in the. bin format.
$ Chmod + x jdk-6u45-linux-x64.bin # Add execution permissions $./jdk-6u45-linux-x64.bin # after running the JDK will be decompressed to the local directory
3. Check the result. Currently, there are two JDK versions in this directory, and 1.7 is installed previously.
$ lldrwxr-xr-x 8 john john 4096 Mar 27 2013 jdk1.6.0_45/drwxr-xr-x 8 john john 4096 Apr 4 2013 jdk1.7.0_51/
4. Create a JDK soft link and direct it to JDK 1.7.0 _ 51. You need to soft link that!
$ ln -s jdk1.7.0_51 currentjohn@ubuntu:Jdk$ lllrwxrwxrwx 1 john john 11 Feb 9 18:29 current -> jdk1.7.0_51/drwxr-xr-x 8 john john 4096 Mar 27 2013 jdk1.6.0_45/drwxr-xr-x 8 john john 4096 Feb 9 18:27 jdk1.7.0_51/
Configure Environment Variables
1. Modify system-level environment variables
$ sudo vim /etc/environment
2. Add the following content and modify it according to your own situation.
JAVA_HOME="/home/john/Developer/Jdk/current"CLASSPATH=".:$JAVA_HOME/lib"
3. Make the environment variable effective immediately after modification.
$ source /etc/environment
Set the default Java parser
1. view the current default Java parser
$ update-alternatives --display java java - auto mode link currently points to /usr/bin/gij-4.6/usr/bin/gij-4.6 - priority 1046 slave java.1.gz: /usr/share/man/man1/gij-4.6.1.gzCurrent 'best' version is '/usr/bin/gij-4.6'.
2. Add a Java parser
$ sudo update-alternatives --install /usr/bin/java java ~/Developer/Jdk/current/bin/java 300
3. Configure the default Java parser. Pay attention to the permissions. Select project 1 on the local machine for configuration.
$ sudo update-alternatives --config javaThere are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status------------------------------------------------------------* 0 /usr/bin/gij-4.6 1046 auto mode 1 /home/john/Developer/Jdk/current/bin/java 300 manual mode 2 /usr/bin/gij-4.6 1046 manual modePress enter to keep the current choice[*], or type selection number: 1update-alternatives: using /home/john/Developer/Jdk/current/bin/java to provide /usr/bin/java (java) in manual mode.
4. Check whether the configuration options are correct after finishing the job!
The alternative mode has changed from automatic to manual!
$ update-alternatives --display java java - manual mode link currently points to /home/john/Developer/Jdk/current/bin/java/home/john/Developer/Jdk/current/bin/java - priority 300/usr/bin/gij-4.6 - priority 1046 slave java.1.gz: /usr/share/man/man1/gij-4.6.1.gzCurrent 'best' version is '/usr/bin/gij-4.6'.
View Java version
$ java -versionjava version "1.7.0_51"Java(TM) SE Runtime Environment (build 1.7.0_51-b13)Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
Thanks to the following authors for ranking in no particular order :)
Ubuntu Java installation Configuration
Ubuntu 12.04 uninstall the built-in OpenJDK, manually download the IDK and configure the Java Runtime Environment
Install the Java Development Environment on Ubuntu 12.04 (jdk1.7 + Eclipse)
Update-alternatives learning notes
Update-alternatives custom link pointing usage