Skip to content

[Linux] How to install JAVA (JDK)

Last Updated on 2021-07-24 by Clay

Until now, Java is still one of the most used and most popular program language in the world —— Of course, the results calculated by different platforms are not necessarily the same. By the way, most Android applications are still developed by Java.

The biggest advantage of Java is that it can be "compiled across platforms", it means we can use the same code to execute our Java program in different platforms. It's really convenient.

You can do such a great thing because Java is not a compiled programming like C, nor interpreted language like Python. Java has its own unique JVM (Java Virtual Machine) and the Java program will first compile the bit code into language of the target platform through JVM.

This is why Java can be compiled cross-platform with only one set of code. Of course, this will inevitably slow down the execution efficiency.

Okay, if you want to install Java in Windows, you can go to the following website: https://www.java.com/zh_TW/download/


The difference of JDK and JRE

When downloading Java, the most troublesome thing is to confirm whether to download, JDK or JRE ?

JDK (Java Development Kit), mainly used to develop Java applications. JRE (Java Runtime Environment), if we only need to execute the Java program, we only need to download it.

The JRE will contain the JVM, and the JDK will contain the JRE.


Install JDK

Install JDK is very easy in Linux system, but you need to check you have "sudo" first.

First, we update our apt tool.

sudo apt-get update
sudo apt-get upgrade

And then we can use the following command to install JDK.

sudo apt-get install default-jdk

Don't forget to check it in our system.

javac -version

Output:

javac 11.0.4

Environment variables

If we want to use it smoothly, don’t forget to add Java to the environment variables:

sudo vim /etc/environment

Write down the Java path:

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

Save it and exit, and then use "source" command to activate our new settings.

source /etc/environment
echo $JAVA_HOME

Output:

/usr/lib/jvm/java-11-openjdk-amd64 

If you see this line printed, it means that the environment variables have been loaded successfully.


References

Tags:

Leave a Reply