How to install Java on Fedora 30
Requirements: user with root privileges or non-root user with sudo privileges.
OpenJDK 8 / 11 installation
$ sudo dnf update
$ sudo dnf install java-1.8.0-openjdk-devel
# or
$ sudo dnf install java-11-openjdk-devel
$ java -version
OpenJDK 12 installation
$ cd /tmp
$ wget -c https://download.java.net/java/GA/jdk12.0.2/e482c34c86bd4bf8b56c0b35558996b9/10/GPL/openjdk-12.0.2_linux-x64_bin.tar.gz
$ sudo cp openjdk-12.0.2_linux-x64_bin.tar.gz /opt
$ cd /opt
$ sudo tar -xvf openjdk-12.0.2_linux-x64_bin.tar.gz
$ sudo /opt/jdk-12.0.2/bin/java -version
Setting the JAVA_HOME environment variable
# Setting default Java version using alternatives
$ sudo alternatives --config java
$ java -version
# javac switching
$ sudo alternatives --config javac
$ javac -version
Setting Java version for applications via JAVA_HOME variable
Add the following line in the file /etc/environment (example for OpenJDK 12):
export JAVA_HOME=/opt/jdk-12.0.2/
Then source it as follows:
$ sudo source /etc/environment
If you check the value of the JAVA_HOME environment variable, it should point to the JRE installation directory:
$ echo $JAVA_HOME
/opt/jdk-12.0.2/