How to Install Java on Linux

Today's TipsMake will show you how to install the latest version of Java Runtime Environment (JRE) on a computer running the Linux operating system.

Install on Non-RPM Linux

Picture 1 of How to Install Java on Linux

Open the Java for Linux download page . You will see several options.

Picture 2 of How to Install Java on Linux

Click Linux . This link is in the middle of the page. The Java installation file will be downloaded.

You can also click on the Linux X64 version if you want to install 64-bit Java.

Picture 3 of How to Install Java on Linux

Record the file name. The latest Java version is version 8, but you may also need the update version number after the "8u" part at the end of the file name.

For example, your file might be called "jre-8u151", which is version 8, update 151.

Picture 4 of How to Install Java on Linux

Open the command line. This step will vary depending on your version of Linux, but you can usually find the command line by opening the Terminal app or clicking the bar at the top or bottom of the screen.

Picture 5 of How to Install Java on Linux

Change installation directory. Type cdinto the console, press spacebar once, then enter the path (e.g. /usr/java/enter then press ↵ Enter.

Picture 6 of How to Install Java on Linux

Enter the installation command. Type tar zxvf, press spacebar once, then enter the full name of the file. This operation depends on the Java version and when you downloaded it.

As of October 2017, you will have to enter tar zxvf jre-8u151-linux-i586.tar.

Picture 7 of How to Install Java on Linux

Press ↵ Enter. Java will be installed on the computer in a folder titled "jre1.8.0_[update]" where "[update]", where 'update' is the version number (e.g. 151).

Install on RPM Linux

Picture 8 of How to Install Java on Linux

Open the Java for Linux download page . You will see several options.

Picture 9 of How to Install Java on Linux

Click Linux RPM in the middle of the page. The Java installation file for the RPM will be downloaded.

You can also click on the Linux RPM X64 version if you want to install 64-bit Java.

Picture 10 of How to Install Java on Linux

Record the file name. The latest Java version is version 8, but you may also need the update version number after the "8u" part at the end of the file name.

For example, your file might be called "jre-8u151", which is version 8 and update 151.

Picture 11 of How to Install Java on Linux

Open the command line. This step will vary depending on your version of Linux, but you can usually find the command line by opening the Terminal app or clicking the bar at the top/bottom of the screen.

Picture 12 of How to Install Java on Linux

Enter the root command. Type sudo suand press ↵ Enter. The command line will ask for the user password.

Picture 13 of How to Install Java on Linux

Enter your account password. Type in the account password and press ↵ Enter. As long as you have root (or root) access on the account, this will allow you to install Java.

If you don't have root access on the account, you need to enter the password of the account that has root access.

Picture 14 of How to Install Java on Linux

Change installation directory. Type cdinto the console, press spacebar once, then enter the path (e.g. /usr/java/enter then press ↵ Enter.

Picture 15 of How to Install Java on Linux

Enter the installation command. Type rpm -ivh, press space once, enter the full name of the file, then press ↵ Enter. Java will be installed on the computer.

The file name will depend on when you download it. As of October 2017, you will have to enter rpm -ivh jre-8u151-linux-i586.rpmthen press ↵ Enter.

Upgrade downloaded files. Enter rpm -Uvh jre-8u73-linux-i586.rpmand press ↵ Enter. This will check for updates to the Java package and apply them if possible.

Install on Ubuntu (OpenJDK)

Picture 16 of How to Install Java on Linux

Open the command line. Press Ctrl+ Alt+ Ton your keyboard or click the black frame icon with a white ">_" on the left side of the screen.

Picture 17 of How to Install Java on Linux

Enter the update command. Type sudo apt-get update && sudo apt-get upgrade -yand press ↵ Enter. The package list will refresh and install all available updates for you.

Picture 18 of How to Install Java on Linux

Enter your password if asked. If you are asked to enter your user password, enter it and tap ↵ Enter.

Picture 19 of How to Install Java on Linux

You need to make sure Java is not installed. Enter java -versionand press ↵ Enter. If you see the message "The program 'java' can be found in the following packages" (The java program can be found in the following packages), Java is not installed on your computer.

If Java is installed, you will see a command line reporting the current version of Java on your computer.

Picture 20 of How to Install Java on Linux

Enter the installation command. Enter sudo apt-get install default-jrethe command line, then press ↵ Enter. Java will be installed into the default directory on the Ubuntu computer.

If this command doesn't work, try entering sudo apt-get install openjdk-8-jdkinstead

Install on Ubuntu 16.04 via PPA

Picture 21 of How to Install Java on Linux

First of all, this is a third-party installation package, so the Linux distribution's package management system (often referred to as distro) cannot inventory this package, so you need to be careful when using it. CtrlEven so, you still have to press + Alt+ Tto open the terminal first .

Picture 22 of How to Install Java on Linux

You need to make sure the system is up to date. After entering sudo apt-get update && sudo apt-get upgrade -y, the system will prompt you to enter the password, type the password and press ↵ Enter, note that no dots or asterisks will appear when you enter and this is normal.

Although this step is not technically required, it is always recommended to do it before we install any content, so you should keep the system up to date to limit many problems.

Picture 23 of How to Install Java on Linux

Add PPA repository to the system. Enter sudo add-apt-repository ppa:webupd8team/javathen press ↵ Enter.

Picture 24 of How to Install Java on Linux

Update the package lists again. Please type sudo apt-get updateand wait for the packages to be refreshed.

Picture 25 of How to Install Java on Linux

Install the package. Enter sudo apt-get install oracle-java9-installer -y.

You may be asked to enter your password, then enter it and press ↵ Enter, note that no dots or asterisks will appear as you enter and this is normal.

Picture 26 of How to Install Java on Linux

Set Oracle's Java as default. On many Ubuntu derivatives, OpenJDK is often the default Java used. If you want Oracle's Java to be used as default, you need to import sudo apt install oracle-java9-set-default.

Update 26 October 2023
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile