Tuesday, July 10, 2012

Oracle Java on Linux Mint 13 (32 & 64 Bits)

Linux Mint (which is based on Ubuntu) no longer distributes Oracle's (formerly Sun) Java JDK and JRE. Linux Mint & Ubuntu officially supports OpenJDK implementation of Java which is the base for Oracle's own implementation. However, if you want to use Oracle's Java 6 and/or 7, you can download them from Oracle's website. This article shows you how to install and configure both Java 6 and 7 alongside the OpenJDK versions 6 and 7 previously installed. I will also show you how to switch between the versions of Java installed.

Note that since Oracle Java is not officially part of Linux Mint, we cannot use the Synaptic Package Manager to search for and install the necessary packages (i.e., it is not part of the repository). We have to resort to using the command line to carry out installation. This also means that notifications on new versions (or updates) are to be done manually by visiting Oracle's website once a while to check for new updates.

To download Oracle's Java, visit their website at:

  http://www.oracle.com/technetwork/java/javase/downloads/index.html

Navigate the site and download the following files for 32-bit Mint:

  jdk-6u33-linux-i586.bin
  jdk-6u30-apidocs.zip
  jdk-6u33-linux-i586-demos.tar.gz
  jdk-7u5-linux-i586.tar.gz
  jdk-7u4-apidocs.zip
  jdk-7u5-linux-i586-demos.tar.gz

For 64-bit Mint, the following files need to be downloaded:

  jdk-6u33-linux-x64.bin
  jdk-6u30-apidocs.zip
  jdk-6u33-linux-x64-demos.tar.gz
  jdk-7u5-linux-x64.tar.gz
  jdk-7u4-apidocs.zip
  jdk-7u5-linux-x64-demos.tar.gz

These are the latest versions (as of July 2012) available on the website. Note that the Java 6 JDK files are supplied in bin format while the Java 7 JDK files are supplied in tar.gz format. This means that we have to use different methods for installing them.

To install both the JDK 6 and JDK 7, follow the steps below. Note that the steps are for the 32-bit version of Mint. Replace the 'i586' portion of the filename with 'x64' for the 64-bit version.

  1. Open a terminal and change to the 'Downloads' directory:

    cd Downloads/

  2. Make the JDK 6 bin file executable by executing:

    chmod a+x jdk-6u33-linux-i586.bin

  3. Execute the JDK 6 bin file:

    ./jdk-6u33-linux-i586.bin

    This will create a 'jdk1.6.0_33' directory and all the files will be unzipped there.

  4. Unzip the JDK 7 file by executing:

    tar -xvf jdk-7u5-linux-i586.tar.gz

    This will create a 'jdk1.7.0_05' directory and all the files will be unzipped there.

  5. Unzip the JDK 6 and JDK 7 docs files by executing:

    unzip jdk-6u30-apidocs.zip -d jdk1.6.0_33/
    unzip jdk-7u4-apidocs.zip -d jdk1.7.0_05/

  6. Unzip the JDK 6 and JDK 7 demo & sample files:

    tar -xvf jdk-6u33-linux-i586-demos.tar.gz
    tar -xvf jdk-7u5-linux-i586-demos.tar.gz

  7. Now move the JDK 6 and JDK 7 directories to /usr/lib/jvm - it's 'proper' place.

    sudo mv jdk1.6.0_33 /usr/lib/jvm
    sudo mv jdk1.7.0_05 /usr/lib/jvm

  8. Now we need to tell the system that we have Oracle's JDK 6 and JDK 7 as alternatives to the OpenJDK. Of course, we can do this manually by using the 'update-alternatives --install xxx' commands for each item, but a far simpler method is to run a ready-made script to do this. The script can be downloaded by executing:

    wget http://webupd8.googlecode.com/files/update-java-0.5b

  9. Once the script file has been downloaded, execute:

    chmod +x update-java-0.5b
    sudo ./update-java-0.5b

    A dialog box will pop-up showing all the possible candidates - first, select JDK 6 and press 'OK'. The script will run, and make all the necessary changes for you. Now run the script again - this time select JDK 7 and press 'OK'. That's it - you now have OpenJDK versions 6 and 7 as well as Oracle JDK6 and JDK7 as alternatives. To check which Java is set as 'default', run the 'galternatives' utility. The display will look like the figure shown below.

Saturday, July 7, 2012

OpenJDK on Linux Mint 13 - Part 2


Part 2: Installing & Configuring OpenJDK via GUI

This article outlines an alternative method of installing and configuring OpenJDK versions 6 and 7 using GUI programs instead of executing commands in a terminal. Choosing and installing the OpenJDK's will be carried out using the Synaptic Package Manager and switching between versions of OpenJDK will be done using the 'galternatives' utility. Note that the Synaptic Package Manager has been already installed as part of the standard packages during installation of Linux Mint 13 and does not have to be re-installed. The 'galternatives' utility, however, has to be installed. So, start up the Synaptic Package Manager (using Menu > Administration > Synaptic Package Manager) and type 'galternatives' into the search box as shown in the figure below and press Enter.



Click on the box besides the package name to select it and then press the Apply button. Press the Enter key at the confirmation screen that appears next. An installation status will then appear - close it when the installation is complete.

Next you need to choose and install the openjdk-6-jdk, openjdk-6-doc, openjdk-6-demo, openjdk-6-dbg, openjdk-7-jdk, openjdk-7-doc, openjdk-7-demo, and openjdk-7-dbg packages. Type 'openjdk' into the Synaptic's search box and press Enter. On the resulting screen as shown below, select all the packages mentioned previously. Then press the Apply button, followed by the Enter key to confirm the installation. Wait for the packages to be downloaded and installed - then close the installation status dialog box when completed.



Next you need to verify that both versions of OpenJDK has been installed using the 'galternatives' utility. To run the 'galternatives' utility, press Alt+F2 and the type galternatives into the box that appears. On the confirmation dialog box that appears next, type in the root password (galternatives requires root privilages) and press Enter. The galternatives utility will start as shown in the figure below.



Navigate to the 'Java' entry on the left-side and you will see a screen similiar to the one shown above. Note that the 64-bit version is shown in the figure - the 32-bit version will display 'i386' instead of 'amd64'. 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 on a terminal. Try switching between versions but remember to reset to OpenJDK version 6 once you have completed your tests.

Friday, July 6, 2012

OpenJDK on Linux Mint 13 - 32 & 64 Bits

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.

Java Flavors on Linux

While composing a new blog on Android programming on Linux, I discovered an interesting fact - there are 6 'flavors' of Java currently available for the latest Linux distributions. To make things simpler, I decided to use the latest versions of Ubuntu and Mint - versions 12.04 LTS (Precise Pangolin) and 13 (Maya) respectively and use these 'flavors' of Java on them. Both the 32-bit and 64-bit versions will be covered in the blog. Why these two? The answer is that these two are considered to be the most popular distributions - at least according to the latest page hit ranking on Distrowatch.

The first portion on my forthcoming blogs is installing and configuring the 6 'flavors' of Java on Linux Mint 13 (32 and 64 bits). The first part is installing and configuring OpenJDK versions 6 and 7 on the same computer plus the ability to switch between the 2 versions of OpenJDK. Two methods will be outlined - using the command line as well as using GUI tools exclusively.

Readers may wonder why both versions are installed. Why not just stick with one? The answer can be summed up in one word - flexibility. With both versions installed on the same computer, it is now possible to test a program on both version (not at the same time, of course) to see if they are error-free. You can also write a program exclusively for one version without having to worry about conflicts and then switch to another version to write another program for that version exclusively. Having the ability to switch between versions makes program development more flexible.

Stay tuned for the first part...

Tuesday, January 10, 2012

This Thin Madness

I really don't understand the 'thin' and 'ultra-thin' craze for notebooks - and it's all Intel's fault - at least for now. If the objective for the 'thin' craze is weight - i.e., the thinner it is, the lighter the resulting notebook, then it is understandable although there are other ways of reducing weight. If the objective is purely aesthetics, then I think the whole thing is crazy. As a direct result of the notebook being very thin, the number of ports (USB or otherwise) tends towards zero; plus the disappearance of the optical drive. Personally, I object to this - so, I will not even consider purchasing an 'ultra-book' (as Intel terms it). I would rather spend my money on a laptop with as many port as possible and with an optical reader/writer built-in.

Saturday, January 7, 2012

Netbook Redux

After reviewing all my previous blogs, I realize that a majority of them involved my 2 netbooks, The Lenovo and the HP Mini. I also realize that I now mostly use the Lenovo as a "download" machine - i.e., whenever I have a download job to carry out (whether via BitTorrent or FTP), I normally use leave it to my netbook and run the jobs overnight. This way I save electricity since the power requirement of the netbook is much less than my desktop PC.

The HP Mini is hardly used at all and remained a "test" machine - i.e., whenever there is a new "designed for netbook" OS comes along, I normally use it to try the OS out. One big flaw in this machine is that the 'lid close detection and sleep' bug is still not resolved for all Linux distributions - so it is useless as a mobile unit - unless I resort to using Windows XP again.

The netbooks also proved to be most cumbersome to use as e-book readers as they are physically awkward to hold in the hands and difficult to use in the 'portrait' orientation. Because of this, and my love of reading books, I succumb to desire and purchased myself an Android tablet (the Acer Iconia A500) which is now in use more often than the netbooks.

The question 'are netbooks dead?' being bandied around the IT industry has now been answered as far as my personal experience goes. I am now left with the question of what to do with the units. Anybody wants to purchase 2 used netbooks? :)

Tuesday, January 3, 2012

A "New" Beginning

As I reflect on the past year activities, I realize that one of the "most forgotten" thing was my blog. Well, it was not totally forgotten - its just that every time I decide to sit down and compose a new blog, something always comes up that require my immediate attention. So, alas, my blog suffered.

This year, however, I resolve (there's that word again :)) to do something about it. I resolve that instead of on giant article every time, I will post snippets on my thoughts on technology and how it affects my life. That's my resolution for 2012.

Speaking of 2012, did the Mayan know something that we don't? Or is it because that their calendar just could not go beyond December 2012 that everyone thinks that is how much time we humans have left. Are we humans going out with a 'bang' or just a 'whimper'?