![Cover image for Installing Java on Ubuntu 20.04 [ Easy Way ]](/image.pl?url=https%3a%2f%2fmedia2.dev.to%2fdynamic%2fimage%2fwidth%3d1000%2cheight%3d420%2cfit%3dcover%2cgravity%3dauto%2cformat%3dauto%2fhttps%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Farticles%252Fqij6jdt14xj91pdv4h36.png&f=jpg&w=240)
In this guide, we will describe how to install Java on Ubuntu 20.04.
Installing OpenJDK 11
Open Terminal, As always first check for updates
sudoapt-get update
Then type following command in terminal
sudoaptinstallopenjdk-11-jdk
when asked for [ Y/n ], Type Y
Once the installation is complete, you can verify it by checking the Java version:
java-version
The output should look something like this:
openjdk version"11.0.7" 2020-04-14OpenJDK Runtime Environment(build 11.0.7+10-post-Ubuntu-3ubuntu1)OpenJDK 64-Bit Server VM(build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
JAVA_HOME
Environment Variable
TheJAVA_HOME
environment variable is used by some Java applications to determine the Java installation location.
To set theJAVA_HOME
variable, first find the Java installation path withupdate-alternatives
:
sudo update-alternatives --config java
In this example, the installation paths are as follows:
- OpenJDK 11 is located at
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
Once you found the path of your preferred Java installation, open the/etc/environment
file:
sudo nano /etc/environment
Assuming you want to setJAVA_HOME
to point to OpenJDK 11, add the following line, at the end of the file:
/etc/environment
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Copy
For changes to take effect on your current shell you can either log out and log in or run the following[source](https://linuxize.com/post/bash-source-command/)
command:
source /etc/environment
Verify that theJAVA_HOME
environment variable was correctly set:
echo $JAVA_HOME
You should see the path to the Java installation:
That’s it! At this point, you have successfully installed Java on your Ubuntu system!
Now for complete assurance
Open any text editor type following following code
classSimple{publicstaticvoidmain(Stringargs[]){System.out.println("Hello Java");}}
save this code as Simple.java
cd to the folder where the program is saved.
then compile using following command in terminal. ( remember S is capital in Simple )
javacSimple.java
and then run using following command
javaSimple
If you are able to see this output ..... then your java is successfully installed on Ubuntu!
Hello Java
Uninstalling Java
You can uninstall Java like any other package installed with apt .
For example, to uninstall the default-jdk package enter:
sudoapt remove openjdk-11-jdk
Conclusion
OpenJDK 11 and OpenJDK 8 are available in the default Ubuntu 20.04 repositories and can be installed using the apt package manager.
GitHub:https://github.com/G-Sudarshan
Top comments(2)
For further actions, you may consider blocking this person and/orreporting abuse