Setting JAVA_HOME for JDK 11 in Ubuntu for VSCODE

Viewed 6052

How do I set JAVA_HOME for JDK 11 in Ubuntu for Visual Studio Code?

1 Answers

1 - Install jdk-11 or higher lts version via bash terminal:

sudo apt-get install openjdk-11-jdk

2- Find java path via bash terminal:

sudo update-alternatives --config java

Obs.: It will returns you a path like this:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java (copy this path)

3- Edit /.bashrc adding JAVA_HOME to it via bash terminal:

sudo gedit ~/.bashrc

The code above will open the file, insert JAVA_HOME in the end of this, be careful, do not change anything here, just adding this code and SAVE:

JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export JAVA_HOME
export PATH=$PATH:$JAVA_HOME

Obs.: JAVA_HOME= **put your java path without "/bin/java" here **

4- Set Vscode jdk path variable:

-press F1 and type Sttings Sync: Show Settings

-inside serarch settings put @tag:sync

-find and open settings.json like this:

enter image description here

-now you just need to put your JAVA_HOME like this:

    "java.home": "/usr/lib/jvm/java-11-openjdk-amd64",
    
    "java.configuration.runtimes": [
        {
            "name":"JavaSE-11",
            "path": "/usr/lib/jvm/java-11-openjdk-amd64"
        }
    ],

enter image description here

reload vscode window, or just close it and open agin

...and VOALA! now the JDK is visible * -- *

enter image description here

Related