This article shows how to install the latest version of the Java Runtime Environment (JRE) on a computer running Linux.
Steps
Method 1 of 4: Using a Non-RPM Linux Distribution

Step 1. Access the web page to download the Java version for Linux systems
Within this site there are several options.

Step 2. Select the Linux link
It is positioned in the center of the appeared page. This will start the download of the Java installation file.
If the architecture of your Linux system is 64-bit, you can choose to download the version of Java for that system by selecting the link Linux X64.

Step 3. Make a note of the file name
The latest version of Java released to date is number 8, but you will also need to take note of the number of the latest update which is written directly in the name of the installation file after the words "8u".
For example as of today, May 2018, the full file name is the following "jre-8u171", which means that it is update number 171 of version number 8 of Java

Step 4. Open the Linux command line
This step varies depending on the version of the operating system you are using. However, normally just open the "Terminal" window or select the bar at the top or bottom of the screen.

Step 5. Change the installation directory
Type the command cd inside the command console and press the space bar, then type the path where you are going to install the program (for example / usr / java /) and press the Enter key.

Step 6. Run the installation command
Type the tar zxvf command, hit the spacebar once, then enter the full name of the installation file. This last parameter varies based on the version of Java you downloaded.
As of today, May 2018, you will need to type the tar command zxvf jre-8u171-linux-i586.tar

Step 7. Press the Enter key
In this way the Java software will be installed on the computer in the folder named "jre1.8.0_ [update_number]", where the parameter "[update_number]" represents the latest available build of Java version number 8 (for example 171).
Method 2 of 4: Using a Linux RPM Distribution

Step 1. Access the web page to download the Java version for Linux systems
Within this site there are several options.

Step 2. Select the Linux RPM link
It is positioned in the center of the appeared page. This will start the download of the Java installation file.
If the architecture of your Linux system is 64-bit, you can choose to download the version of Java for that system by selecting the link Linux X64 RPM.

Step 3. Make a note of the file name
The latest version of Java released to date is number 8, but you will also need to take note of the number of the latest update which is written directly in the name of the installation file after the words "8u".
For example as of today, May 2018, the full file name is the following "jre-8u171", which means that it is update number 171 of version number 8 of Java

Step 4. Open the Linux command line
This step varies depending on the version of the operating system you are using. However, normally just open the "Terminal" window or select the bar at the top or bottom of the screen.

Step 5. Acquire the access rights of the root user
Type the command sudo su and press the Enter key. You will be asked to enter your user account password.

Step 6. Type your account password and press the Enter key
Now that your user account has system administration rights you are able to perform the Java installation.
If your user account cannot have root access to the system, you will need to type the password of a profile that has that permission

Step 7. Change the installation directory
Type the command cd inside the command console and press the space bar, then type the path where you are going to install the program (for example / usr / java /) and press the Enter key.

Step 8. Run the installation command
Type the command rpm -ivh, press the spacebar once, then enter the full name of the installation file and press the Enter key. This will install the Java software on your computer
The name of the installation file may vary over time based on updates made to the Java version. As of today, May 2018, you will need to type the command rpm -ivh jre-8u171-linux-i586.rpm and press the Enter key
Step 9. Update the program
Type the command rpm -Uvh jre-8u171-linux-i586.rpm and press the Enter key. This will check for updates to the Java package and if so, they will be downloaded and applied.
Method 3 of 4: Using Ubuntu (OpenJDK)

Step 1. Log in to the Ubuntu command line
Press the key combination Ctrl + Alt + T or select the black square icon with the white characters "> _" inside. It is located on the left side of the desktop.

Step 2. Run the update command
Type the command sudo apt-get update && sudo apt-get upgrade -y in the "Terminal" window and press the Enter key. This will update the installation package list and all available updates will be installed automatically.

Step 3. If prompted, enter your user account login password
You may need to type in your login password, if so, and hit the Enter key.

Step 4. Make sure there is no Java version on the system
To check this, type the command java -version and press the Enter key. If you see the text message "The" java "program can be found in the following packages:", it means that no version of Java is currently installed on your computer.
If Java is already present on your computer, you will see a text message showing the installed version

Step 5. Run the installation command
Type the command sudo apt-get install default-jre in the "Terminal" window and press the Enter key. This way the Java software will be automatically installed on Ubuntu within the default directory.
If the given command fails, try using the following sudo apt-get install openjdk-8-jdk
Method 4 of 4: Using the PPA Repository on Ubuntu 16.04

Step 1. It should be noted that in this case a package provided by third parties is used
This means that the administrators of the Linux distribution you are using cannot check and verify its contents, so be very careful. The first step is to open a "Terminal" window by pressing the key combination Ctrl + Alt + T.

Step 2. Make sure your system is up to date
Type the command sudo apt-get update && sudo apt-get upgrade -y in the "Terminal" window and press the Enter key. You may be asked to type in your login password, if so, and hit the Enter key. While typing the password you will not see any characters appear on the screen, do not worry, this is completely normal.
Although technically this step is optional, it is always good to perform it before each installation as it is used to update the system and avoid possible problems in the future

Step 3. Add the PPA repository on the system
Type the command sudo add-apt-repository ppa: webupd8team / java and press the Enter key.

Step 4. Refresh the list of available packages
Type the command sudo apt-get update and wait for the list to be updated.

Step 5. Install the package
Type the command sudo apt-get install oracle-java9-installer -y and press the Enter key.
You may be asked to type in your login password, if so, and hit the Enter key. While typing the password you will not see any characters appear on the screen, do not worry, this is completely normal

Step 6. Make Oracle's Java software the system default program
In many Ubuntu-derived Linux distributions the OpenJDK program is the system default tool for running Java files. If you need or want to use Oracle's Java software, you will need to set it as the default by running this command sudo apt install oracle-java9-set-default.