4 Ways to Install Java on Linux

Table of contents:

4 Ways to Install Java on Linux
4 Ways to Install Java on Linux
Anonim

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

Install Java on Linux Step 1
Install Java on Linux Step 1

Step 1. Access the web page to download the Java version for Linux systems

Within this site there are several options.

Install Java on Linux Step 2
Install Java on Linux Step 2

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.

Install Java on Linux Step 3
Install Java on Linux Step 3

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

Install Java on Linux Step 4
Install Java on Linux Step 4

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.

Install Java on Linux Step 5
Install Java on Linux Step 5

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.

Install Java on Linux Step 6
Install Java on Linux Step 6

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

Install Java on Linux Step 7
Install Java on Linux Step 7

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

Install Java on Linux Step 8
Install Java on Linux Step 8

Step 1. Access the web page to download the Java version for Linux systems

Within this site there are several options.

Install Java on Linux Step 9
Install Java on Linux Step 9

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.

Install Java on Linux Step 10
Install Java on Linux Step 10

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

Install Java on Linux Step 11
Install Java on Linux Step 11

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.

Install Java on Linux Step 12
Install Java on Linux Step 12

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.

Install Java on Linux Step 13
Install Java on Linux Step 13

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

Install Java on Linux Step 14
Install Java on Linux Step 14

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.

Install Java on Linux Step 15
Install Java on Linux Step 15

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)

Install Java on Linux Step 17
Install Java on Linux Step 17

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.

Install Java on Linux Step 18
Install Java on Linux Step 18

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.

Install Java on Linux Step 19
Install Java on Linux Step 19

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.

Install Java on Linux Step 20
Install Java on Linux Step 20

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

Install Java on Linux Step 21
Install Java on Linux Step 21

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

Install Java on Linux Step 22
Install Java on Linux Step 22

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.

Install Java on Linux Step 23
Install Java on Linux Step 23

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

Install Java on Linux Step 24
Install Java on Linux Step 24

Step 3. Add the PPA repository on the system

Type the command sudo add-apt-repository ppa: webupd8team / java and press the Enter key.

Install Java on Linux Step 25
Install Java on Linux Step 25

Step 4. Refresh the list of available packages

Type the command sudo apt-get update and wait for the list to be updated.

Install Java on Linux Step 26
Install Java on Linux Step 26

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

Install Java on Linux Step 27
Install Java on Linux Step 27

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.

Advice

While there are several ways to download and install Java using the installer (such as a GUI), the whole process will be considerably quicker and faster when done via the command line

Warnings

Oracle's Java software is no longer supported on Ubuntu. In this case you will need to use the OpenJDK program (this is a free implementation of Oracle's Java software). Oracle does not distribute.deb packages for Java, therefore any.deb files related to Oracle's Java software were surely created by third parties and could potentially be harmful to your system.

Recommended: