Create two directories in your Home directory:
mkdir ~/jdk15
mkdir ~/Downloads
Download the latest OpenJDK build and put it to a predetermined location and name for further use:
wget -O ~/Downloads/jdk15.tgz "https://github.com/AdoptOpenJDK/openjdk15-binaries/releases/download/jdk-15.0.2%2B7/OpenJDK15U-jdk_x64_linux_hotspot_15.0.2_7.tar.gz"
The file is a gzipped-tarball (.tgz), so it’s a uncompressed archive of files which has been compressed after creation. We first uncompress it and pipe the uncompressed output to the tar-Command for further extraction of the contained files to a given directory:
gzip -dc ~/Downloads/jdk15.tgz | tar --strip-components=1 -xvf - -C ~/jdk15
Now, here’s a interesting one. Essentially we want to append some lines of text to another file (.profile in your Home directory to set some variables). The cat-Command outputs either a file given or text piped to it. With the <<-Operator (here-document Operator) we can pipe multiple Lines of text to it until a Delimeter is specified (EOF). The >>-Operator appends the output of a command to the given file.
cat << EOF >> ~/.profile
#JDK
export JDK_HOME=${HOME}/jdk15
export JAVA_HOME=\${JDK_HOME}
export PATH=\${PATH}:\${JDK_HOME}/bin
EOF
The variables JDK_HOME and JAVA_HOME are used by the JDK and the Java Runtime to determine it’s location. The PATH Variable is used by the Shells to know where to look for entered commands. We appended the OpenJDK Path to it.