Ubuntu - set JAVA_HOME environment variable

4 points
Created by:

In this short article we would like to show how to set JAVA_HOME environment variable in Ubuntu.

Simple steps:

  1. check where Java JDK is installed
    Run command:
    ls -al /usr/lib/jvm


    total 16
    drwxr-xr-x   3 root root 4096 sie 18 09:56 .
    drwxr-xr-x 141 root root 4096 sie 19 10:26 ..
    lrwxrwxrwx   1 root root   25 lut 20  2019 default-java -> java-1.11.0-openjdk-amd64
    lrwxrwxrwx   1 root root   21 sty 15  2020 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64
    -rw-r--r--   1 root root 2044 lip 15 22:45 .java-1.11.0-openjdk-amd64.jinfo
    drwxr-xr-x   7 root root 4096 sie 18 09:56 java-11-openjdk-amd64
    so, Java JDK path is: /usr/lib/jvm/default-java
  2. add JAVA_HOME to /etc/environment
    Run command:
    sudo nano /etc/environment
    Add following line over PATH:
    Update PATH line adding :$JAVA_HOME at the end:
    Press ctrl+o and ctrl+x to save file and exit program.
    /etc/environment file with JAVA_HOME environment variable - Ubuntu
    /etc/environment file with JAVA_HOME environment variable - Ubuntu
  3. request to reload environment variables (optional operation)
    Run command:
    source /etc/environment
    Note: it will reload currently used terminal variables only! So, run it for different terminals if it is necessary, re-login users or restart Linux.
  4. verify JAVA_HOME configuration
    Run command:
    echo $JAVA_HOME


Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂