Java is one of the most popular language of 21st century. JAVA is used for
- mobile applications (Specifically Android)
- Web Applications, Web Servers
- Desktop applications and much more.
In the year 2020 it completes 25 years of journey. During this journey it evolved over time and gained lots of community support. This article will help you to install JDK and JRE in your system.
- One Ubuntu Desktop / Server.
- One user account who has sudo access.
Step 1: Open your terminal (ctrl + shift +t) and Update your package index.
$ sudo apt-get update
Step 2: Install open JDK and JRE on Ubuntu
$ sudo apt install default-jdk $ sudo apt-get install default-jre
Step 3: Check for java version
$ java -version
Setting the JAVA_HOME variable in environment
It is very important to set JAVA_HOME variable in environment without it JAVA will not be recognize by other applications. To set the JAVA_HOME variable in the ENVIRONMENT you need to edit the environment file and need to add the full java path along with the name JAVA_HOME
$ vi /etc/environment
Press E for edit and add the jdk path to the environment /usr/lib/jvm/default-java
To take effect you need to refresh the environment
$ source /etc/environment
Now check the JAVA_HOME path
$ echo $JAVA_HOME
If JAVA_HOME is not showing the path redo the above steps.
Managing Installed Java versions
If you have multiple jdk installed you can set which one you want to use. To view all the installed jdk versions on ubuntu use this command
$ sudo update-alternatives --config java
Now choose the jdk from the installed list by choose the number to use as a default.
Congratulations you have successfully installed Java in your system. Now you can use other application which runs on java.
To install tomcat in Ubuntu read here. Install tomcat in Ubuntu