Installing Oracle Java

From Alpine Linux
Revision as of 10:19, 18 May 2022 by Androb (talk | contribs)

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 needs.

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 

Take note of the directory, e.g. /opt/java/jdk1.8.0_121, create a symbolic 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, 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: some users have reported they had to use this command to get it working:

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


Alternative installation of Oracle Java on Linux Alpine

1. Run apk update && apk upgrade 2. Edit vim /etc/profile, add the value before the string: append_path "/user/local/sbin", value: append_path "/opt/java/current/bin" 3. Download XXX-XXX-linux-x64.tar.gz and jce_policy-8.zip from official oracle suite. 4. Сreate a directory in the root: mkdir -p /opt/java 5. Copy XXX-XXX-linux-x64.tar.gz in the java directory: scp /home/username/XXX-XXX-linux-x64.tar.gz /opt/java/ 6. Let's go to the catalog java: cd /opt/java and unpack the file: XXX-XXX-linux-x64.tar.gz, tar -zxvf XXX-XXX-linux-x64.tar.gz 7. Create simlink: ln -s /opt/java/jdkX.X.X_XXX /opt/java/current 8. Download and install the certificate: wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub 9. Download glibc: wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-2.34-r0.apk 10. Install glibc: apk add glibc-2.34-r0.apk 11. Download glibc-bin: wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-bin-2.34-r0.apk 12. Install glibc-bin: apk add glibc-bin-2.34-r0.apk 13. Install the license jce_policy-8.zip, сopy the file: scp /home/username/jce_policy-8.zip /opt/java/current/jre/lib/security/ 14. Let's go to the folder /opt/java/current/jre/lib/security/: cd /opt/java/current/jre/lib/security/ and unpack it: unzip -o -j jce_policy-8.zip UnlimitedJCEPolicyJDK8/*.jar 15. Delete the archive file: rm -f jce_policy-8.zip 16. Restart the computer or virtual machine: reboot 17. Let's check the version of Java installed: java -version 18. If it displays: java version "X.X.X_XXX", then we did everything correctly.