Install JDK 7 u5 on Ubuntu 12.04 LTS (as a secondary JDK)

Introduction

I had installed JDK 6.0 update 31 in an earlier post. However, I now need to write a Java application that requires the features available in JDK 7.

In this post, I will install JDK 7 update 5 as a secondary JDK, while JDK 6.0 u31 will be the primary JDK. It’s perfectly normal to have multiple JDKs on a single machine to support the requirements of different applications. Fortunately, it’s easy to use a different JDK on a per application basis.

Download

I have a 64 bit version of Ubuntu 12.04 LTS installed, so the instructions below only apply to this OS.

  1. Download the Java JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1637583.html.
  2. Click Accept License Agreement
  3. Click dk-7u5-linux-x64.tar.gz
  4. Login to Oracle.com with your Oracle account
  5. Download the JDK to your ~/Downloads directory
  6. After downloading, open a terminal, then enter the following commands.

Installation

Open a terminal, then enter the following commands:

cd ~/Downloads
tar -xzf jdk-7u5-linux-x64.tar.gz

Note:
The jvm directory is used to organize all JDK/JVM versions in a single parent directory. As this is our 2nd JDK, we’ll assume that the jvm directory already exists.

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

The next 3 commands are split across 2 lines per command due to width limits in the blog’s theme.

sudo update-alternatives --install "/usr/bin/java" "java"  \
	"/usr/lib/jvm/jdk1.7.0_05/bin/java" 2
sudo update-alternatives --install "/usr/bin/javac" "javac"  \
	"/usr/lib/jvm/jdk1.7.0_05/bin/javac" 2
sudo update-alternatives --install "/usr/bin/javaws" "javaws"  \
	"/usr/lib/jvm/jdk1.7.0_05/bin/javaws" 2
sudo update-alternatives --config java

You will see output similar to the following (although it’ll differ on your system). Read through the list and find the number for the Oracle JDK installation (/usr/lib/jvm/jdk1.7.0_05/bin/java)

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                               Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/jdk1.7.0_05/bin/java   2         auto mode
  1            /usr/lib/jvm/jdk1.6.0_31/bin/java   1         manual mode
  2            /usr/lib/jvm/jdk1.7.0_05/bin/java   2         manual mode

Press enter to keep the current choice[*], or type selection number:

On my system I did entered 1 to keep JDK 1.6.0 u31 as my primary JDK (change the number that is appropriate for your system). To enter 1, press 1 on the keyboard, then press Enter.

sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/jdk1.7.0_05/bin/javac   2         auto mode
  1            /usr/lib/jvm/jdk1.6.0_31/bin/javac   1         manual mode
  2            /usr/lib/jvm/jdk1.7.0_05/bin/javac   2         manual mode

Press enter to keep the current choice[*], or type selection number:

I entered 1 then pressed Enter to keep JDK 1.6.0 u31 as my primary javac command.

sudo update-alternatives --config javaws
There are 2 choices for the alternative javaws (providing /usr/bin/javaws).

  Selection    Path                                 Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/jdk1.7.0_05/bin/javaws   2         auto mode
  1            /usr/lib/jvm/jdk1.6.0_31/bin/javaws   1         manual mode
  2            /usr/lib/jvm/jdk1.7.0_05/bin/javaws   2         manual mode

Press enter to keep the current choice[*], or type selection number:

I entered 1 then pressed Enter to keep JDK 1.6.0 u31 as my primary javaws command.

As a final step, let’s test each of the commands to ensure everything is setup correctly.

java -version

The output should be:
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

javac -version

The output should be:
javac 1.6.0_31

javaws -version

The output should be:
Java(TM) Web Start 1.6.0_31, which is followed by a long usage message.

That’s it, the JDK 7 u5 is installed.

Advertisements

Uninstall Java from Ubuntu Linux

Introduction

Hopefully you won’t need these instructions due to a botched install, but there may come a time where you need to uninstall a version of the JDK/JVM.

These instructions are for the Oracle JDK 1.7.0 Update 4 on Ubuntu 12.04 LTS. If you are using a different version of the JDK, then change the version numbers listed below.

I have also included instructions for removing the OpenJDK at the bottom of this post.

Uninstall Java

Let’s check the current setup before we uninstall Java.

sudo update-alternatives --display java

The output from the command will be something like:

java - manual mode
link currently points to /usr/lib/jdk1.7.0_04/bin/java
/usr/lib/jdk1.7.0_04/bin/java - priority 1
/usr/lib/jvm/j2sdk1.6-oracle/jre/bin/java - priority 315
slave java.1.gz: /usr/lib/jvm/j2sdk1.6-oracle/man/man1/java.1.gz
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1051
slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
Current 'best' version is '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java'.

Next, we’ll remove each symlink to a Java binary from the Debian alternatives system. I have split the following commands onto multiple lines to ensure that they display correctly on this page. However, you can remove the \ and then type each command on one line in the terminal.

sudo update-alternatives --remove "java" \
"/usr/lib/jvm/jdk1.7.0_04/bin/java"
sudo update-alternatives --remove "javac" \
"/usr/lib/jvm/jdk1.7.0_04/bin/javac"
sudo update-alternatives --remove "javaws" \
"/usr/lib/jvm/jdk1.7.0_04/bin/javaws"

Let’s quickly verify that the commands above remove the symlinks.

java -version
javac -version
which javaws

You should no longer see 1.7.0 u04 for the version of any of the above commands.

IMPORTANT WARNING
You must type the next 2 commands perfectly to avoid permanently destroying your system. If you do this wrong, you could delete important system files, including those that are required by Ubuntu.

cd /usr/lib/jvm
sudo rm -rf jdk1.7.0_04
sudo update-alternatives --config java

Output:
update-alternatives: error: no alternatives for java.

sudo update-alternatives --config javac

Output:
update-alternatives: error: no alternatives for javac.

sudo update-alternatives --config javaws

Output:
update-alternatives: error: no alternatives for javaws.

sudo vi  /etc/environment

Delete the line with JAVA_HOME

Uninstall OpenJDK (if installed)

First we’ll check which OpenJDK packages are installed.

sudo dpkg --list | grep -i jdk

Next, let’s uninstall OpenJDK related packages. Edit the list of packages below if you have additional or different OpenJDK packages installed.

sudo apt-get purge icedtea-* openjdk-*

Let’s check that all OpenJDK packages have been removed.

sudo dpkg --list | grep -i jdk

Install Java JDK 6.0 update 31 on Ubuntu 12.04 LTS

Introduction

The first question is why are we installing an old JDK. The answer is that Oracle JDK 6.0 update 31 is the JDK recommended by Cloudera when installing CDH4 (Cloudera Distribution Hadoop v4).

This is an update to an older version of this post. Mainly I have changed the JDK from 1.6.0_26 to 1.6.0_31 as this is the recommended JDK for CDH4.

Install Java

I have a 64 bit version of Ubuntu 12.04 LTS installed, so the instructions below only apply to this OS.

  1. Download the Java JDK from http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u31-oth-JPR.
  2. Click Accept License Agreement
  3. Click jdk-6u31-linux-x64.bin
  4. Login to Oracle.com with your Oracle account
  5. Download the JDK to your ~/Downloads directory
  6. After downloading, open a terminal, then enter the following commands.
cd ~/Downloads
chmod +x jdk-6u31-linux-x64.bin
./jdk-6u31-linux-x64.bin

Note:
The jvm directory is used to organize all JDK/JVM versions in a single parent directory.

sudo mkdir /usr/lib/jvm
sudo mv jdk1.6.0_31 /usr/lib/jvm

The next 3 commands are split across 2 lines per command due to width limits in the blog’s theme.

sudo update-alternatives --install "/usr/bin/java" "java" \
"/usr/lib/jvm/jdk1.6.0_31/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" \
"/usr/lib/jvm/jdk1.6.0_31/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" \
"/usr/lib/jvm/jdk1.6.0_31/bin/javaws" 1
sudo update-alternatives --config java

You will see output similar to the following (although it’ll differ on your system). Read through the list and find the number for the Oracle JDK installation (/usr/lib/jvm/jdk1.6.0_26/bin/java)

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      auto mode
  1            /usr/lib/jvm/jdk1.6.0_31/bin/java                1         manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual mode

On my system I did the following (change the number that is appropriate for your system):
Press 1 on your keyboard, then press Enter.

sudo update-alternatives --config javac

Follow steps similar to those listed above if you are presented with a list of options. In my case, I had not previously installed the OpenJDK javac binary, so my output looked like the following:

There is only one alternative in link group javac: /usr/lib/jvm/jdk1.6.0_31/bin/javac
Nothing to configure.
sudo update-alternatives --config javaws

As with javac, I did not have the OpenJDK version of javaws installed, so my output was simple. However, if you get a list of options, just type in the number of the path to the Oracle javaws command, and press Enter.

There is only one alternative in link group javaws: /usr/lib/jvm/jdk1.6.0_31/bin/javaws
Nothing to configure.

As a final step, let’s test each of the commands to ensure everything is setup correctly.

java -version

The output should be:
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

javac -version

The output should be:
javac 1.6.0_31

javaws -version

The output should be:
Java(TM) Web Start 1.6.0_31
which is followed by a long usage message.

Create the JAVA_HOME environment variable

Open a terminal, then enter the following commands:

sudo vi /etc/environment

WARNING
WordPress displays the quotes around the JAVA_HOME value below as magic quotes. This will cause problems when you try to use your JVM in certain applications.

Do not copy/paste the JAVA_HOME value below. Or if you do, ensure that you change magic quotes to straight quotes in your editor.

Enter the following at the bottom of the file:
JAVA_HOME="/usr/lib/jvm/jdk1.6.0_31"

Type the following commands to finish the setup and verify that everything is setup correctly.

source /etc/environment
echo $JAVA_HOME

You should see the following output:

/usr/lib/jvm/jdk1.6.0_31

Lastly, verify that JAVA_HOME is set correctly for the sudo user:

sudo env | grep JAVA_HOME

That’s it, the JDK 6.0 update 31 is installed.

Install Pentaho BI Server 4.5 on Ubuntu 12.04 LTS Desktop

Overview: What is Pentaho?

Pentaho is an open source Business Intelligence (BI) Suite that comes in with either commercial support (http://www.pentaho.com/) and or community support (http://community.pentaho.com/).

This post provides instructions for the Pentaho community edition suite.

Create a pentaho user and group

Open a terminal and run the following commands:

sudo addgroup pentaho
sudo adduser --system --ingroup pentaho --disabled-login pentaho

Install Java

Follow the JDK installation instructions that are listed in the following post: Install Java JDK 6.0 update 31 on Ubuntu 12.04 LTS

Install the Pentaho BI Server

Now that we have Java installed we can get on with our main task of installing the Pentaho BI Server.

  1. Download the Pentaho BI Server from http://wiki.pentaho.com/display/COM/Latest+Stable+Builds. I’m using the current stable build for x64 Linux which is biserver-ce-4.5.0-stable.tar.gz.
  2. Open a terminal and enter the following commands:
sudo mkdir /opt/pentaho
cd ~/Downloads
gunzip biserver-ce-4.5.0-stable.tar.gz
tar xf biserver-ce-4.5.0-stable.tar
sudo mv biserver-ce /opt/pentaho/biserver-ce-4.5.0
sudo mv administration-console /opt/pentaho/administration-console-ce-4.5.0
cd /opt/pentaho
sudo ln -s biserver-ce-4.5.0 biserver-ce
sudo ln -s administration-console-ce-4.5.0 administration-console
sudo chown -R pentaho:pentaho /opt/pentaho

Start the Pentaho Server

Open a terminal, then enter the following commands:

Note:
The following command is only required if you downloaded a Windows .zip file by accident. If this is the case, then none of the .sh files will be executable.
sudo find /opt/pentaho/ -type f -name '*.sh' -exec chmod 744 '{}' \+

cd /opt/pentaho/biserver-ce
sudo -u pentaho ./start-pentaho.sh

Login to the Pentaho User Console

  1. Open a web browser to http://localhost:8080.
  2. Click Evaluation Login and select a user type to login as.

Login to the Pentaho Administration Console

Open a terminal, then enter the following commands:

cd /opt/pentaho/administration-console
sudo -u pentaho ./start-pac.sh
  1. Open a web browser to http://localhost:8099.
  2. Enter a User Name of admin.
  3. Enter a Password of password.
  4. Click Log In.

That’s it. The core Pentaho BI server is installed and ready for development. However, a good next step is to change the database that Pentaho uses and install the Pentaho Design Studio (PDS), but we’ll leave that for future posts.

Hadoop also port 8080, so you will either need to use a different port for the Pentaho User Console or change the Hadoop MapReduce ShuffleHandler port.