Part 1: Installing & Configuring OpenJDK via the Command Line
(NOTE: All the commands shown in this article are typed in a terminal started using either the menu or the Alt-Ctl-T shortcut.)
On a newly installed (and updated) Linux Mint 13, the command:
java -version
would display the following:
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.1)
(6b24-1.11.1-4ubuntu3)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
This would indicate that the OpenJDK JRE version 6 has been installed as part of the 'standard' installation. Just to make sure that this is the only Java installed, the command:
sudo update-alternatives --config java
will display:
There is only one alternative in link group java:
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
Nothing to configure.
Since we are interested in developing software using Java, we need to install the JDK version of OpenJDK. To do this type the command:
sudo apt-get install openjdk-6-jdk
Press Enter when prompted "Do you want to continue [Y/n]?" and the JDK will be installed. Now you have both the JRE and the JDK version 6 installed. To make Java programming easier, it is also recommended that the OpenJDK documentation be installed. This can be done by the command:
sudo apt-get install openjdk-6-doc
If you are interested, you can also install the OpenJDK demo programs by executing:
sudo apt-get install openjdk-6-demo
A debugger is also available and can be installed by executing:
sudo apt-get install openjdk-6-dbg
A quick check using the Synaptic Package Manager (using Menu > Administration > Synaptic Package Manager) shows that the OpenJDK version 7 is also available. Can this be installed alongside the version 6 and can the user select which version to use? The answer is Yes to both. This can be achieved by the command:
sudo apt-get install openjdk-7-jdk openjdk-7-doc openjdk-7-demo openjdk-7-dbg
To select which Java to use, run the command:
sudo update-alternatives --config java
The output is as shown below:
Press the Enter key to keep using OpenJDK version 6 or press '2' to switch to and use OpenJDK version 7. To test the switch, press '2' at the prompt shown above and then run the command:
java -version
should display:
java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre)
(7~u3-2.1.1~pre1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)
Now switch back to using version 6 by executing:
sudo update-alternatives --config java
and type '0' or '1' to switch back. You can verify it by running:
java -version
and you should see:
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.1)
(6b24-1.11.1-4ubuntu3)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
To make switching between different versions of OpenJDK easier, I recommend that the package 'galternatives' be installed. This is a GUI version of update-alternatives and lets you switch versions visually. To install, run:
sudo apt-get install galternatives
and press Enter at the prompt. When installed, you can run the utility by executing:
sudo galternatives
A dialog box (shown below) will appear:
Navigate to the 'Java' entry on the left-side and you will see a screen similiar to the one shown above. The version 6 of OpenJDK is the selected one at the moment. You can change the version to OpenJDK version 7 by clicking on the radio button under the 'Choice' column. Note that if you decide to use version 7, make sure that all the entries related to Java (normally preceeded by the letter 'j') on the left-hand side (for example; jar, jarsigner, javac ... etc) are selected and changed to version 7. The 'galternatives' utility makes switching between different OpenJDK versions easier by doing it in one place rather than having to run sudo update-alternatives --config xxxx (where xxxx is the item to be changed) for each and every Java related items. Once the choices have been made, close the dialog box and you are done switching. Verify by running the commands 'java -version', 'javac -version', etc in a terminal.
For those wondering about the difference between OpenJDK 6 and OpenJDK 7, the following links should clarify the matter:
https://blogs.oracle.com/darcy/entry/openjdk_6_genealogy
and
http://www.infoq.com/news/2007/09/openjdk6
My recommendation is that OpenJDK 6 be used at the moment - that is, if the user decides to use OpenJDK as the Java platform for developing applications.
No comments:
Post a Comment