Installing Oracle Java: Difference between revisions

From Alpine Linux
m (Categorized: Programming)
m (Mark page as obsolete.)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
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.
{{Obsolete|Alpine has not used grsec for a while now...}}
 
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.
This guide assumes you're running as root.
Line 10: Line 12:
  sudo tar -zxvf XXX-XXX-linux-x64.tar.gz  
  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:
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
  ln -s /opt/java/jdk1.8.0_121 /opt/java/current
Line 21: Line 23:
  sh /etc/profile.d/java.sh
  sh /etc/profile.d/java.sh


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


Line 28: Line 30:
  apk add paxctl
  apk add paxctl


Now in your /opt/java/XXX/bin folder let it execute:
Now in your /opt/java/XXX/bin folder, execute:
  paxctl -c java
  paxctl -c java
  paxctl -m java
  paxctl -m java
Line 38: Line 40:
You can do this for any other binary you need to use.
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):
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" java
  setfattr -n user.pax.flags -v "mr" javac
  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.
= =
* [https://blog.overops.com/author/shahar_valiano/ Native Java Debugging on Alpine Linux: GDB, OpenJDK and the Mysterious Unknown Signal] Shahar Valiano 2019


[[Category:Programming]]
[[Category:Programming]]

Latest revision as of 09:46, 19 January 2024

This material is obsolete ...

Alpine has not used grsec for a while now... (Discuss)

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.