Thursday, July 26, 2012

Oracle Java on Ubuntu 12.04 (32 & 64 Bits)

Ubuntu Linux no longer distributes Oracle's (formerly Sun) Java JDK and JRE. Ubuntu (and Linux Mint) 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 Ubuntu, we cannot use the Synaptic Package Manager or Ubuntu Software Center 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 Ubuntu:

  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 Ubuntu, 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

    NOTE: If you cannot download it using wget as shown above (ERROR 404: not found), go to this website and click on the file to download it:

    http://code.google.com/p/webupd8/downloads/detail?name=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.

Sunday, July 22, 2012

OpenJDK on Ubuntu 12.04 (Precise Pangolin)

On a fresh install of Ubuntu 12.04, you might be surprised to find out that there is no Java installed as part of a standard installation! This can be easily verified by executing the following command in a terminal:

java -version

You should see the following response:

  The program 'java' can be found in the following packages:
   * default-jre
   * gcj-4.6-jre-headless
   * openjdk-6-jre-headless
   * gcj-4.5-jre-headless
   * openjdk-7-jre-headless
  Try: sudo apt-get install

Running update-alternatives on Java also results in the message:

  update-alternatives: error: no alternatives for java.

You can also confirm this using the Synaptic Package Manager - which is NOT installed by default on Ubuntu 12.04. Install this package by running:

sudo apt-get install synaptic

The following is a screen-shot of the result of an 'openjdk' search.



Since the purpose of this article is to get Java working on Ubuntu 12.04, we need to get all 'flavors' of Java installed - starting with OpenJDK. Follow the steps outlined below to start installing.

(NOTE: The procedure below is for the 32-bit version of Ubuntu 12.04, but they also applies to the 64-bit version - just replace the 'i386' part,  whenever they occur, with 'x64' for the 64-bit version.)

  1. Start Synaptic and mark the following packages for installation:


    openjdk-6-jdk
    openjdk-6-doc
    openjdk-6-demo
    openjdk-6-dbg
    openjdk-7-jdk
    openjdk-7-doc
    openjdk-7-demo
    openjdk-7-dbg





    Press the 'Apply' button and wait for the download and install process to finish.

  2. Use the update-alternatives command again to see which OpenJDK is set as the 'default' Java - you should see:





    It's clear from the screen that OpenJDK 6 is the 'default' Java and you could use the 'java -version' command to verify this - the output should show:

    java version "1.6.0_24"
    OpenJDK Runtime Environment (IcedTea6 1.11.3)
       (6b24-1.11.3-1ubuntu0.12.04.1)

    OpenJDK Server VM (build 20.0-b12, mixed mode)


  3. To switch between the OpenJDK versions (6 or 7), you can either use the command line 'update-alternatives' utility or the graphical front-end for the same command - 'galternatives'. To use 'galternatives', you need, of course, to install it first by executing:

    sudo apt-get install galternatives

    Alternatively, you could use the Synaptic Package Manager to install this. Once installed, open the dash (if you are using Unity) or the menu (if you are using gnome-shell) and locate the 'Alternative Configurator' utility. Start it, enter your password (the utility requires root privileges), and you should see the following screen:





    Scroll down the left-hand pane until you see the 'java' entry (see figure below) - note that OpenJDK 6 is set as the default. You can use the galternatives utility to change OpenJDK versions by clicking on the radio-button under the 'Choice' column. You should also remember to change the other Java related items (those that starts with the letter 'j') whenever you change versions.




  4. A faster way to switch between OpenJDK versions at one go, is to use the 'update-java-0.5b' utility. This utility can be downloaded by executing:

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

    Once the script file has been downloaded, execute:

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

    You should see a dialog box (as shown) pop-up:





    Note that the entry '/usr/lib/jvm/java-1.6.0-openjdk-i386' and '/usr/lib/jvm/java-1.7.0-openjdk-i386' are links to the actual directories 'usr/lib/jvm/java-6-openjdk-i386' and 'usr/lib/jvm/java-7-openjdk-i386' respectively - so it really does not matter which one you select - they mean the same thing. Do not select the 'usr/lib/jvm/java-6-openjdk-common' or the 'usr/lib/jvm/java-7-openjdk-common' entries. First select the 'usr/lib/jvm/java-7-openjdk-i386' entry and click 'OK'. The utility will make all necessary changes for you at one go. To verify run 'galternatives' again and you should see:





    You can verify that the 'update-java' utility has made other changes by selecting the Java related items on the left-hand pane and seeing the result in the right-hand pane.

    Now run the sudo 'update-java-0.5b' utility again - this time select the 'usr/lib/jvm/java-6-openjdk-i386' entry and click 'OK'. Again, the utility will make all necessary changes for you at one go. To verify run 'galternatives' and you should see:



That's it, you can now choose freely and easily between versions of OpenJDK Java. Enjoy!

Wednesday, July 18, 2012

Eclipse+Android on Linux Mint 13 (Maya)

So far, my previous blogs on Linux Mint 13 has described how to install Java and the Android SDK. If you have followed the blogs, you will now be ready for the next step towards Android software development and that is to install a Java programming environment called Eclipse. Of course, first we have to install this (if it has not been installed yet). The install process is very simple - you can use either Synaptic or the command line to carry out this job.

  1. To use Synaptic, start Synaptic, enter your password, then type 'eclipse' into the search box. The entry for Eclipse will appear - mark it for installation, and the rest of the additional items, and then click on the 'Apply' button. Wait for download and install process to finish, close Synaptic and you are done!

    To use the command line, start a terminal, and type:

    sudo apt-get install eclipse

    Type 'Enter' when prompted, wait for the packages to be downloaded and installed, close the terminal and you are done!

  2. Before you start Eclipse, you need to determine whether the necessary SWT (Standard Widget Toolkit) libraries link are set properly - else Eclipse will complain that it cannot start because it cannot find the swt library. Check the following location in you home directory for 32-bit Linux Mint by typing the following command in a terminal:

    ls ~/.swt/lib/linux/x86/

    For a 64-bit Linux Mint, the command is:

    ls ~/.swt/lib/linux/x86_64/

    If you see a message like that shown below, then the swt directory does not exist.

    ls: cannot access /home//.swt/lib/linux/x86/: No such file or directory

    To create the swt directory on a 32-bit Mint, execute:

    mkdir -p ~/.swt/lib/linux/x86/

    To create the directory on a 64-bit Mint, execute:

    mkdir -p ~/.swt/lib/linux/x86_64/

    On the other hand, if the swt directory exist, but nothing is listed (ie, no file links in that directory), then the necessary links are not set. if this is so, execute the following command:

    For 32-bit Mint:

    ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86/

    For 64-bit Mint:

    ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86_64/

    Verify that the file links are set using the ls command again - if set, you should see the following file links:

    libswt-atk-gtk-3740.so    libswt-cairo-gtk-3740.so
    libswt-gnome-gtk-3740.so  libswt-pi-gtk-3740.so
    libswt-awt-gtk-3740.so    libswt-glx-gtk-3740.so
    libswt-gtk-3740.so        libswt-webkit-gtk-3740.so


  3. Start Eclipse, then answer the prompt (see below) to set a workspace - I use '/home/<username>/Projects/Android (where username is your login name) but you can place it anywhere you like or accept the default of /home/<username>/workspace - then click OK.





    Eclipse will start loading and you will then see a screen like the one shown below.





    Click on 'Workbench' (near top right corner of the screen) and the main workbench screen will appear (see below).




  4. Click on Help (on the top menu bar), then on select 'Install New Software'. A new window called 'Available Software' will pop-up (see below) - click the ‘Add’ button at the top of the window. An “Add Repository” window will pop up. Pick a name, (I chose ‘ADT Plugin’ - ADT stands for Android Development Tools), then enter the following URL in the ‘Location’ box and click OK.

    https://dl-ssl.google.com/android/eclipse/

    NOTE: If you have trouble acquiring the plugin, try using "http" in the URL, instead of "https". For security reasons, https is preferred.







    The window will close and a 'Pending' message will appear on the Available Software window - this indicates that the software is checking the URL for the plug-ins. When this is complete, you will see the 2 items listed (see below).





    Select the checkbox next to Developer Tools and click Next. In the next window, you'll see a list of the tools to be downloaded (see below) - click Next. Read and accept the license agreements (see below), then click Finish. The plug-ins will be downloaded and installed.









    NOTE: Click OK if you get a security warning saying that the authenticity or validity of the software can't be established.

    At the end of this process, you will be prompted to restart Eclipse - do so. When you arrive at the main workbench, you will see a window (see below) welcoming you to Android development - here you will have to configure the Android SDK.





    Since we have already downloaded and installed the Android SDK (see my previous blog), all we need to do here is specify the location of the SDK which happens to be '/home/<username>/android-sdk-linux'. Then click 'Next' - the next screen (see below) will ask you whether you want to contribute to Google's usage statistics - select 'Yes' or 'No' and then press 'Finish'



That's it - you are now ready to start developing Android software on your Linux Mint 13. My next blog will show you a simple 'Hello, World' project, a few sample projects and will also describe some of the resources you can use to start program development on Android.

Sunday, July 15, 2012

Android SDK on Linux Mint 13 (Maya)

In my previous blogs, I showed how to install various 'flavors' of Java on Linux Mint 13 - both 32 and 64 bits versions. Now I will show how to install and configure the Google Android SDK to be used together with Java, for Android software development.

  1. First head over to:

      http://developer.android.com/sdk/index.html

    and download the latest (as of July 2012) file:

    android-sdk_r20-linux.tgz

    IMPORTANT NOTE:
    If you are using 64-bit Linux Mint 13 you MUST download and install the 'ia32-libs' package since the Android SDK is a 32-bit application and requires the 32 bit library to operate properly. To download and install, open a terminal and execute:
       sudo apt-get install ia32-libs

  2. Start a terminal and unzip the downloaded file:

    tar xvf ~/Downloads/android-sdk_r20-linux.tgz

    This will create a new directory 'android-sdk-linux' in your home directory containing all the unzipped files. Why the home directory? The simple answer is 'to avoid file permission problems'. Note that by installing the SDK in the home directory, only the current user can access it - so security is guaranteed.

    If, however, you want the SDK to be accessed by other users, then you may have to install it somewhere else - perhaps the /opt directory. This article will not describe how to do that - it just assumes that the current user is the only one that can access the SDK.

  3. Change directory and execute the android SDK:

    cd android-sdk-linux/tools
    ./android

    TIP: You can set the PATH environment to point to your Android SDK tools directory so that you can start the 'android' program anywhere. Edit the .profile file in your home directory and add the following lines to the end of the file:

      # set PATH so it includes user's Android SDK if it exists
      if [ -d "$HOME/android-sdk-linux" ] ; then
          PATH="$HOME/android-sdk-linux:$HOME/android-sdk-linux/tools:$PATH"
      fi

    This will only take effect on the next logout/login or restart.

    The SDK Manager will start as shown in the screenshot below.



    Notice the progress bar at the bottom of the screen - this indicates that the SDK Manager is querying for updates from Google. Wait this is finished - you will then notice that it automatically selects a set of recommended packages. However it seems to have missed the 'Android SDK Platform-tools' which, according to Google, is required when you install the SDK for the first time. So place a check mark on that item by clicking in the check-box. Also de-select the item 'Google APIs' since this can only be downloaded and installed AFTER all the rest of the marked item has been installed. The final screen will look like the one shown below.



  4. Click on the 'Install 6 packages' button - a window will pop up (shown below) listing all the packages to be installed. Notice that the 'Accept' radio button is selected - so just press the 'Install' button to start the process of downloading and installing the packages. The progress bar at the bottom indicates the status of this process. Also a log screen may appear if there are problems during install - ignore the 'Stopping ADB server failed (code -1)' message if it appears on the log - this seems to be harmless.



    When install is complete, close the log windows (if open) and then place a tick mark on the 'Google APIs' item and press the 'Install 1 package' button. When the package list appears, press 'Accept', then the 'Install' button, and then wait until this package is installed. That's it - you have installed the recommended (and latest) Android packages necessary for software development. As of July 2012 this is Android 4.1(API 16) - codenamed Jelly Baby. Is it necessary to install all the other packages (API 3 to 15)? This is entirely up to you - if you really need to develop software only for an Android version, then, by all means download and install it using the SDK Manager.

  5. Now we need to set up at least one AVD (Android Virtual Device) on which you can test your developed software. The AVD is an emulator which emulates the ARM processor. To set up the AVD we need to invoke the AVD Manager which is part of the SDK Manager. Click on 'Tools' (in the menu bar) and then click on the 'Manage AVDs...' item. You will the screen as shown below.



  6. Click on the 'New' button - a new window will pop-up (see below). Give the new AVD a name - for example 'MyJellyBaby'. Select 'Android 4.1 - API Level 16' as the target for the AVD.

    Then enter the size of the SD card - I use 128 MiB which should be sufficient for testing. Leave the rest at default except for the 'Device ram size' under hardware. To make the AVD load a bit faster and if you have at least 4GB of system RAM, change the size to 768 by clicking on the default '512' and changing it to 768.

    Next to make the emulator perform even faster, enable GPU emulation by clicking the 'New...' button and then click on the double arrow on the 'Property:' button and select 'GPU emulation' from the list. Then click on the value item and change it to 'yes'.

    The final screen will look like the one shown below. Then click on the 'Create AVD' button.If there are no errors, you will see a screen like the one below. Press 'OK' - the AVD list will then show the new AVD - MyJellyBaby in this case (see figure).







  7. To start the AVD, first select it on the list, then click the 'Start' button - a window will pop-up (see below). You can set the display size and wipe the user data from here if you wish - then click on the 'Launch' button. You will see a 'Starting Android Emulator' screen (see below) and then the emulator will start loading as shown. Note the 'flashing' Android sign while the emulator is loading.







  8. While the emulator is loading (may take time depending on the RAM size set and the speed of your system CPU and GPU), a 'thank-you' windows from Google will pop-up (see below) - if you wish you can agree to send usage statistic to Google - then click on 'Proceed' to dismiss the window.



    After a while the Android 4.1 'JellyBaby' emulator will appear (see below). The emulator's screen is blank except for 3 notifications on the top right-hand screen. To 'start' the emulator for the first time, click the 'power' button on the right side (above the keyboard) to switch off and then click on it again to power on. The login screen will appear (see below) - slide (using the mouse) to unlock the device. The 'Home' help screen will appear (see below) - click on 'OK' on the help screen and the actual Home screen will be shown (see below).









  9. You can play with the emulator at this stage - close the main window when done. Then close the 'Starting Android Emulator' screen. To dismiss the AVD list, press the 'Esc' key and you will be beck at the Android SDK Manager window. Close it if you wish.
That's it - you now have a working Android SDK and you are now almost ready to start developing Android software on your Linux Mint 13. The next blog will describe installing Eclipse - a programming environment for developing Java programs - and with the help of several Google plugins for Eclipse - a programming environment for developing Android programs as well.

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...