Java is a very popular programming language developed by Sun Micro systems. Now Java is used to create various desktop programs, web applications, server applications and much more. The main feature of this language is maximum cross-platform. This tutorial focuses on how to install java on ubuntu, A program written for one system will work without problems in another. But for programs written in Java, you need a special Java-machine. That is what we will install today.

In this article we will look at how to install Java in Ubuntu for different versions of the program. And also try to sort out all its diversity. and the second we will instill java in Ubuntu VPS
What version of java to install?
Now Java is developing the company Oracle. Until recently, there were two main versions of the Java virtual machine:
- Old seventh version;
- New eighth, used in most programs.
The platform was distributed in two formats:
- Proprietary (Oracle Java) – with additional features and support;
- Open (JDK) – fully open version.
Both platforms were produced by Oracle, but the second was supported by the developer community, and the first by the company itself. Now the situation has changed a bit. Now the company releases a new version of Java every half year. First, Java 9, 10 was released, and then 11, and the duration of support for these versions is also short — only seven months. Therefore, most programs remained to work on Java 8, which will be officially supported until 2020. That it should be installed in most cases.
If you are a developer and you want to get the latest version of Java, then you should install Java 11. This is an LTS version that will be supported until 2026. It had a lot of improvements and changes, both in terms of syntax and distribution. Now the proprietary version is available for free only for non-commercial use. For commercial purposes, you must pay or install OpenJDK.
In Ubuntu, and in other Java distributions, it comes in two editions:
- JDK or Java Development Kit – contains the full version of Java required for development in this language;
- JRE or Java Runtime Environment – contains only the environment for running programs.
Here, I think, you need to choose what you need. If there is no need to compile something in Java, then the JRE will suffice. Now for the installation.
Installing Java in Ubuntu
how to install java in ubuntu using openjdk
If you want to install OpenJDK in Ubutnu, then you do not need any third-party repositories. The eighth version of the platform is in the official repository Ubuntu 18.04. To install jdk on Ubuntu use:
sudo apt install openjdk-8-jdk
To install JRE in Ubuntu, run:
sudo apt install openjdk-8-jre
After that you can check the Java version:
java -version
install java in ubuntu using oracle java
To install a proprietary version of Oracle Java 11, you need to use a webupd8 PPA repository. To add it, use the command:
sudo add-apt-repository ppa:webupd8team/java
While adding, the PPA repository will display an informational message with a list of supported systems and programs. You must press Enter . Then it is only possible to install Oracle Java in Ubuntu.
sudo apt install oracle-java8-installer
During the installation process you will need to accept the license agreement.
After that, we can check the installation by viewing the version:
java --version
installing Java 11 in ubantu 19.04
1.Installing openjdk11
Java 11 is the latest version of Java. This is a long-term support version, so it will be supported until 2026. The free version is in the official repositories, so you can install it from there without any problems:
sudo apt install openjdk-11-jdk
Alternatively, you can install the JRE edition only for running programs:
sudo apt install openjdk-11-jre
Next you can see the version:
java -version
2.Installing oracle Java 11
To install this version of the program, you need to add another repository:
sudo add-apt-repository ppa:linuxuprising/java
Then run the installer script. It downloads the package from the site and installs it on your computer. You will only need to accept the license:
sudo apt install oracle-java11-installer
Check java version:
java -version
Java version selection
If you installed several versions of Java in the system, then you need to choose which one will be used by default. To do this, use the update-java-alternatives utility. To view a list of versions run:
sudo update-java-alternatives --list
Then install the required version using the –set option :
sudo update-java-alternatives --set oracle-java-8
Remove Java from Ubuntu
To remove an unnecessary version of Java, use the same command that was used for installation, only with the purge option:
sudo apt purge oracle-java11-installer
sudo apt purge oracle-java8-installer
sudo apt purge openjdk-11*
sudo apt purge openjdk-8*
Then you can delete the PPA repository:
sudo add-apt-repository --remove ppa:linuxuprising/java
sudo add-apt-repository ppa:webupd8team/java
FINDINGS
In this article we covered how to install Java on Ubuntu 19.04. I think, now you know which version you need and how to install everything correctly. Let’s move on on how to install java on Ubuntu VPS
In this guide, we will show how to install Java on a VPS running under Ubuntu . We will also see how to set the home variable in Java and a number of basic initial setup steps.
Method 1 – Install Java on Ubuntu from the standard package
The first method to install Java on Ubuntu will be – from the standard packages by default. Let’s start the process by updating the current packages to the latest version:
apt-get update && apt-get upgrade
Upon completion, install the latest version of the Java Runtime Environment (JRE) by running the command:
apt-get install default-jre
You can also install the Java Development Kit (JDK) instead. It will be needed to develop specific software or used to compile Java programs. The JDK includes a JRE, so you can choose this installation method.
apt-get install default-jdk
Everything! Java is ready for use on your Ubuntu machine. You can double-check if the installation is correct with these commands:
java -version
javac -version
Method 2 – Install Java on Ubuntu with Oracle JDK
Another possible option for installing Java on Ubuntu is to use the official Oracle JDK. We start by updating your current packages to the latest version:
apt-get update && apt-get upgrade
For example, we will use a third-party library from WebUpd8. To make it easier, install this package:
apt-get install software-properties-common
Next, to get Java PPA, run the command:
sudo add-apt-repository ppa:linuxuprising/java
Note: This repository is not managed by Oracle and does not contain Java files.But it can let us get the Oracle Java software installation.Finally, you can install Java on your Ubuntu OS with the command:
sudo apt-get install oracle-java10-installer
The command above will install Java version 10. For earlier versions,you can change the syntax from java10 to java8, and so on.It’s all! Java has been successfully installed. You can check the installation version by running the commands:
java -version
javac -version
A similar output will be displayed on your screen:
Java setup
There can be multiple versions of Java installations on the same server. You can choose the default version with this command:
update-alternatives --config java
Here is what you see on the output:
There are 3 choices for the alternative java (providing/usr/bin/java).
Selection Path Priority Status
-------------------------------------------------- ----------
0 /usr/lib/jvm/java-7-oracle/bin/java 1071 auto mode
1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/ java 1081 manual mode
2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/java-9-oracle/bin/java 1091 manual mode
Press <enter> to keep the current choice [*], or type selection number number:
Enter the number from the proposed menu that you want to use by default. You can also do this with other Java commands, such as:
- Compiler – javac
- Document Generator – javadoc
- JAR Signature Tool – jarsigner
Use the following syntax:
update-alternatives --config javac
update-alternatives --config javadoc
update-alternatives --config jarsigner
Setting the Java Home Environment Variable
Another useful point to know is how to set the JAVA_HOME variable . Most applications need to know the location of your Java installation. The previously used command will help you find the path to the Java installation:
update-alternatives --config java
Once you copy the installation path, you need to edit the environment file located in the etc directory :
nano /etc/environment
Add this line at the end and set the value to JAVA_HOME :
JAVA_HOME = "/usr/lib/jvm/java-10-oracle/bin/java"
Do not forget to change the path to installing Java to the actual for you.
Press CTRL + X to complete and save the changes. Next, verify that the changes were applied by running the command:
source/etc/environment
You can double-check whether a variable is active like this:
echo $JAVA_HOME
If you followed the instructions on the screen, you will get the JAVA_HOME value that you entered.
Conclusion
Now you know how to install Java on Ubuntu 19.04. In addition, you learned about such useful and important points as determining the default Java version and setting the JAVA_HOME variable.
If this article was helpful to you, share it with others. And, if you have any tips, suggestions or ideas, we will be happy and grateful if you leave them in the comments below!
Leave a Reply