Installing Oracle Java and Netbeans on Ubuntu

I run Ubuntu Server 12.04 LTS as my web server and Ubuntu Desktop 12.04 LTS as my development environment. This gives me the piece of mind that what I'm building locally will most likely behave the same way once it's been deployed on the server. Ubuntu by default, expects to use OpenJDK as opposed to Oracle's Java. While I'd rather run OpenJDK, it doesn't seem to play well with Netbeans (my IDE od choice). Sadly, Oracle's Java is no longer available via an apt-get repository or in the form of a .deb installer, so we will have to install it by hand. Here is the reference I've come up with tho make this work.

Using your favorite terminal emulator, enter the the following commands. These commands will remove OpenJDK (if installed), and create the directoy into which Oracle's Java will live. This tutorial assumes a previous install of OpenJDK.

## Remove any current Java installs
sudo apt-get purge openjdk-\*
sudo rm /usr/local/java

## Make the directories into which we will be installing Java.
sudo mkdir -p /usr/local/java

Next, go out to the Oracle Java website and download the latest version of Java (this article assumes version 7.11). http://www.oracle.com/technetwork/java/javase/downloads/jdk7u11-downloads-1836413.html if you download a different version, be sure to adjust the commands accordingly. You will want to replace 7.0_11 with 7.0_[your version here] and 7u11 with 7u[your version here]. Now, navigate to your Downlads directory and start getting the Java package ready.

## Move to the your Downloads directory
cd ~/Downloads

## Prep and move the package into tis new location
sudo -s cp -r jdk-7u11-linux-x64.tar.gz /usr/local/java
cd /usr/local/java
sudo -s chmod a+x jdk-7u11-linux-x64.tar.gz
sudo -s tar xvzf jdk-7u11-linux-x64.tar.gz

ls
jdk1.7.0_11  jdk-7u11-linux-x64.tar.gz

Load your profile into an editor

sudo vim /etc/profile

Scroll down to the end of your profile using your arrow keys and add the following lines at the end.

JAVA_HOME=/usr/local/java/jdk1.7.0_11
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
JRE_HOME=/usr/local/java/jre1.7.0_11
PATH=$PATH:$HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

## Make sure the new install is the default version.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_11/bin/java" 1
sudo update-alternatives --set java /usr/local/java/jdk1.7.0_11/bin/java

## Optional
sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_11/bin/javac
sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_11/bin/javaws

Test your install by checking your version of Java.

java -version

Your results should resemble the following.

java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Now we are ready to install Netbeans. Navigate to http://netbeans.org/downloads/ and choose your version (I'm assuming you'll download the full version).

# Move to the downloads directory.
cd ~/Downloads

# Make the install script executable
sudo chmod +x netbeans-7.2-ml-linux.sh

# Install Nebeans
sudo ./netbeans-7.2-ml-linux.sh

WARNING - Do not take this as an endorsement of Java; given recent security concerns I wouldn't recommend installing it unless you absolutely need it. If you have to have Netbeans then this is the only way I've been able to get it running on Ubuntu. Otherwise, try Open-JDK instead of Oracle and avoid installing any Java based browser plugins.