How to install Java in Ubuntu

In this post, I’ll try to describe how to install Java 11.0.2 to Ubuntu 18.10. By default, this version of Ubuntu has Java 1.8 and it’s JRE only, it isn’t JDK it means we don’t have Java Compiler (javac). Let’s fix it.

In first, download the latest stable version, link. I’ve tried to install .deb, but it didn’t work. My way was through .tar.gz.

Unpack and replace it to the target directory. My choice was “/home/roman/Coding/Java/jdk-11.0.2”. Now we should change file “/etc/environment” with superuser privileges. You can use different text redactors, vi, nano, gedit. My way is VIM.

in opened file we should add in variable PATH our directory with “bin”. And create JAVA_HOME varibale. It will has a view as:



Save changes and close the file. Now we should run some commands for informing Ubuntu about our variable in JRE, JDK locations:

sudo update-alternatives –install “/usr/bin/java” “java” “/home/roman/Coding/Java/jdk-11.0.2/bin/java” 0

sudo update-alternatives –install “/usr/bin/javac” “javac” “/home/roman/Coding/Java/jdk-11.0.2/bin/javac” 0

sudo update-alternatives –set java /home/roman/Coding/Java/jdk-11.0.2/bin/java

sudo update-alternatives –set javac /home/roman/Coding/Java/jdk-11.0.2/bin/javac

Also, we can see a list of alternatives using these commands:

update-alternatives –list java

update-alternatives –list javac

Then we should restart Ubuntu, and check for version of Java:

java -version

6 thoughts on “How to install Java in Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *