Languages
[Edit]
EN

Ubuntu - set JAVA_HOME environment variable

4 points
Created by:
AnnLen
1798

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

    Output: 

    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:
    JAVA_HOME="/usr/lib/jvm/default-java"
    Update PATH line adding :$JAVA_HOME at the end:
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME"
    Press ctrl+o and ctrl+x to save file and exit program.
    Screenshot:
    /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
    Output:
    /usr/lib/jvm/default-java

     

Hey ūüĎč
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.