Languages
[Edit]
EN

Ubuntu - set JAVA_HOME environment variable

7 points
Created by:
Sylvie-Justice
490

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/bin at the end:
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME/bin"
    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

     

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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.

❤️💻 🙂

Join