This topic will help users who are upgrading the Java version on AWS Ubuntu servers. The first 1024 ports on a Linux server are considered privileged, so it is important that you ensure that Java can access common ports. This topic assumes you have enough familiarity with Linux, Ubuntu, and installation of Java generally to make any adjustments needed to the example commands shown here. All commands are expressed assuming root privileges, but feel free to use the sudo versions if needed.

Check Java Version

Determine supported versions of the JDK using this topic: Supported Technologies.

See what version of Java the server is running on. Run this (or similar):

java -version

Run this (or similar) to install the default JDK:

apt-get install default-jdk

Recheck the Java version again. If it's showing the desired version of Java, then you can skip to the section about privileged ports below. If this does not update to the desired Java version, move to the next section.

Download and Install a New JDK Version

Run the appropriate commands to download and install the supported newer version of Java.

The example here is for OpenJDK 12, which is no longer in use, but these commands will give you an idea of the steps needed:

wget https://download.java.net/java/GA/jdk12/GPL/openjdk-12_linux-x64_bin.tar.gz -O /tmp/openjdk-12_linux-x64_bin.tar.gz

tar xfvz /tmp/openjdk-12_linux-x64_bin.tar.gz --directory /usr/lib/jvm

rm -f /tmp/openjdk-12_linux-x64_bin.tar.gz

Update Alternatives

Confirm that the new version is present by accessing it via it's full path:

/full/path/to/new/JDK/bin/java -version

Update the alternatives so in the future you can simply type `java -version`. In this example, we show a path for OpenJDK12, which is no longer supported. Adapt these lines to your version:

sh -c 'for bin in /usr/lib/jvm/jdk-12/bin/*; do update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 100; done'

sh -c 'for bin in /usr/lib/jvm/jdk-12/bin/*; do update-alternatives --set $(basename $bin) $bin; done'

Run this again to confirm the correct version:

java -version

Allow Access to Privileged Ports

If your EC2 Ubuntu box is locked down port-wise, you might need to adjust the bind service via the setcap command so Java can access common ports. The command to use will be similar to this:

setcap 'cap_net_bind_service=+ep' 'readlink -f \'which java\''

There are other methods of providing this access, such as including a setting in the service file that runs LabKey.

Related Topics

Was this content helpful?

Log in or register an account to provide feedback


previousnext
 
expand allcollapse all