Setting a JAVA HOME Path in Ubuntu

Notes from reconfiguring JAVA_HOME while switching from OpenJDK 8 to 11

1. Install

sudo apt-get install openjdk-11-jdk
  • This command also installs the openjdk-11-jre package which contains the Java runtime environment!

2. Check the version

chloe@chloe-XPS-15-9570 ~
$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)

3. Find where JDK is installed

  • You can find the installed JDKs by navigating to the /usr/lib/jvm/ path

    chloe@chloe-XPS-15-9570 ~
    $ cd /usr/lib/jvm/
    
    chloe@chloe-XPS-15-9570 /usr/lib/jvm
    $ ls
    default-java     java-11-openjdk-amd64     java-8-openjdk-amd64
    java-1.11.0-openjdk-amd64  java-1.8.0-openjdk-amd64  openjdk-11
    

4. Set environment variable

Open /etc/environment with vim

Add the following environment variable

Apply the modified values immediately using the source command

5. Check the environment variable

5-1. Check the configured environment variable using the echo command

5-2. Check using the printenv command

  • Using grep allows you to search for a specific string!

    • Here we are searching for "java"!

Done!

+

When you want to switch between alternatives and build with a specific version

  • You can change to the desired version by entering its number

Last updated