Skip to content

Java Development Kit (JDK)

alejandrort edited this page Aug 21, 2019 · 16 revisions

We will use the Java SE Development Kit 8u distribution due to current compatibility issues between the most recent version of JDK and the Java EE GlassFish application server.

Download

To get the Java JDK version go to the official Java SE Development Kit 8 Downloads. Accept the License Agreement and download it.

Installation and configuration

Windows

Double-click on the downloaded .exe file and follow the steps to install it. It is recommended to keep the default path suggested for the installation.

Next step is to configure the JAVA_HOME environment variable.

Press WinKey + Pause or navigate Control Panel > System and Security > System.

Click on Advanced system settings, Advanced tab, Environment Variable.

Create a new variable as shown in the picture below. Be sure to set the value of the variable to the path where your previously installed the JDK.

There was an error with the image

We need also to update the PATH variable. Click edit and new to add %JAVA_HOME%\bin (see picture below).

There was an error with the image

Open a new command prompt and run the following commands:

java -version

java version "1.8.0_161"

Java(TM) SE Runtime Environment (build 1.8.0_161-b12)

Java HotSpot(TM) Client VM (build 25.161-b12, mixed mode, sharing)

javac -version

javac 1.8.0_161

If your output is similar it indicates that Java was successfully installed.

Mac OS installation

Double click on the the downloaded .dmg file.

Note:

In some cases, a Destination Select window appears. This is a bug, as there is only one option available. If you see this window, select Install for all users of this computer to enable the Continue button.

Now go to System Preferences > Java it should show the version just installed.

Go to a terminal and type java -version. It should show a result similar to

java version "1.8.0_131"

Java(TM) SE Runtime Environment (build 1.8.0_131-b11)

Java HotSpot (TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Mac OSX 10.5 or later

In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/. bash_profile or ~/.profile. To do this, run following command in a terminal to start the nano editor:

nano .bash_profile

Add the following line to the file: export JAVA_HOME=$(/usr/libexec/java_home)

source .bash_profile

echo $JAVA_HOME

This should prompt something similar to

/Library/Java/JavaVirtualMachines/1.8.0_131.jdk/Contents/Home

Older Mac OSX installation

For older Mac OSX, the /usr/libexec/java_home does not exists, so, we should set JAVA_HOME directly to the installation path

nano .bash_profile

Add the following (or similar) line to the file: export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.8.0_131.jdk/Contents/Home

source .bash_profile

echo $JAVA_HOME

The output should be similar to

/System/Library/Java/JavaVirtualMachines/1.8.0_131.jdk/Contents/Home

Ubuntu Linux installation

Add the Oracle Java PPA to Apt with the following command:

sudo add-apt-repository ppa:webupd8team/java

Next, update your Apt package database with the following command:

sudo apt-get update -y

Install the latest stable version of Oracle Java 8.

sudo apt-get install oracle-java8-installer

Verify the Java version by running the following command:

java -version

The output should be similar to

java version "1.8.0_161"

Java(TM) SE Runtime Environment (build 1.8.0_91-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

The last thing is to check that the JAVA_HOME environment variable is set and points to your JDK installation:

  1. Check the register path of the JDK:

    sudo update-alternatives --config java

  2. Copy the path and then open /etc/environment using nano or another text editor.

    sudo nano /etc/environment

  3. At the end of this file, add the next line (be sure to replace the path we copied before).

    JAVA_HOME="/usr/lib/jvm/java-8-oracle"

  4. Save the file, close it and reload it.

    source /etc/environment

  5. Check that the environment variable has been correctly established:

    echo $JAVA_HOME