Installing Oracle Java

From Alpine Linux
Jump to: navigation, search

Using java requires having grsec play nice with the binaries. You may also want to install the JDK instead of the JRE depending on your use case.

This guide assumes you're running as root.

Download XXX-XXX-linux-x64.tar.gz from either the JRE or JDK section here: https://www.oracle.com/technetwork/java/javase/downloads/index.html

mkdir -p /opt/java
cd /opt/java
sudo tar -zxvf XXX-XXX-linux-x64.tar.gz 

Note down the directory, e.g. /opt/java/jdk1.8.0_121, create a symbol link as the current version:

ln -s /opt/java/jdk1.8.0_121 /opt/java/current

Create a file in /etc/profile.d/java.sh:

export JAVA_HOME=/opt/java/current
export PATH=$PATH:$JAVA_HOME/bin

Execute this script or restart your shell:

sh /etc/profile.d/java.sh

Now we need manage grsec with paxctl use this command to check if its installed:

which paxctl

If nothing comes up install it:

apk add paxctl

Now in your /opt/java/XXX/bin folder let it execute:

paxctl -c java
paxctl -m java

If you have the JDK, you need to do the same to javac:

paxctl -c javac
paxctl -m javac

You can do this for any other binary you need to use.

NOTE: I read online that some people required using this command to get it working (and it may be a better alternative):

setfattr -n user.pax.flags -v "mr" java
setfattr -n user.pax.flags -v "mr" javac