Update November 2019: The correct way to install Oracle JDK on Ubuntu

In Ubuntu or Linux Mint you can check if you have installed Java and JDK in several different ways. For new users which are not experience they can check and install JDK by following command:

sudo apt-get update
sudo apt-get install default-jre
sudo apt-get install default-jdk

The second command should return result like:

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

While the third one should ask you for installation of new package SDK. The output will be something like:

$ sudo apt-get install default-jdk
Reading package lists... Done
Building dependency tree       
Reading state information... Done

Setting up default-jdk-headless (2:1.10-63ubuntu1~02) ...
Setting up default-jdk (2:1.10-63ubuntu1~02) ...

Once Java is installed you can set it up in IntelliJ as Project SDK by:

  • menu
  • Project Structure
  • Platform Settings
  • SDKs
  • Plus
  • JDK
  • Select Location - for Ubuntu 18 and Linux Mint - /usr/lib/jvm/java-1.11.0-openjdk-amd64
  • OK

Ubuntu 18 SDK new

For the advanced users you can search for Java installed versions by next steps:

whereis java


java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz

Then view location: /usr/bin/java

ls -l /usr/bin/java


lrwxrwxrwx 1 root root 22 Aug 18 19:33 /usr/bin/java -> /etc/alternatives/java

which is a sym link. And finally chech the java alternatives by:

ls -l /usr/bin/java


lrwxrwxrwx 1 root root 43 Aug 18 19:33 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java

In order to ensure that you hava JDK you can check if javac is included in the programs there or simply test it in the terminal by:

The result would be something like:

Usage: javac <options> <source files>
where possible options include:
  @<filename>                  Read options and filenames from file
  -Akey[=value]                Options to pass to annotation processors
  --add-modules <module>(,<module>)*
        Root modules to resolve in addition to the initial modules, or all modules
        on the module path if 

Then you can add it to IntelliJ.

Otherwise you will see result like(if you don't have jdk or it's not properly set up):

 $ javac
 The program 'javac' can be found in the following packages: