How to Install Java on Linux

This wikiHow teaches you how to install the latest version of the Java Runtime Environment (JRE) on a computer running Linux. Open the [https://www.java.com/en/download/linux_manual.jsp Java for Linux download page]. You'll see several...

Method 1 of 4:

Installing on Non-RPM Linux

  1. Picture 1 of How to Install Java on Linux
    Open the Java for Linux download page. You'll see several options listed here.
  2. Picture 2 of How to Install Java on Linux
    Click Linux. It's a link in the middle of the page. Doing so will prompt the Java installation file to download.
    1. You can also click the Linux X64 version if you want to install 64-bit Java.
  3. Picture 3 of How to Install Java on Linux
    Note the file's name. The latest version of Java is version 8, but you also need the update version number, which is written in the file name after the "8u" section.
    1. For example, your file might be named "jre-8u151", signifying that it is version 8, update 151.
  4. 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 by clicking a bar at the top or bottom of the screen.
  5. Picture 5 of How to Install Java on Linux
    Change the installation directory. Type cd into console, press the spacebar once, and then type in the path (e.g., /usr/java/ and press Enter.
  6. Picture 6 of How to Install Java on Linux
    Enter the installation command. Type in tar zxvf, press the spacebar once, and then type in the full file name. This will vary depending on the Java version and when you downloaded it.
    1. As of October 2017, you'd type in tar zxvf jre-8u151-linux-i586.tar.
  7. Picture 7 of How to Install Java on Linux
    Press Enter. Doing so will install Java on your computer in a folder entitled "jre1.8.0_[update]" where "[update]" is the update version number (e.g., 151).
Method 2 of 4:

Installing on RPM Linux

  1. Picture 8 of How to Install Java on Linux
    Open the Java for Linux download page. You'll see several options listed here.
  2. Picture 9 of How to Install Java on Linux
    Click Linux RPM. It's in the middle of the page. Doing so will prompt the Java for RPM installation file to download.
    1. You can also click the Linux RPM X64 version if you want to install 64-bit Java.
  3. Picture 10 of How to Install Java on Linux
    Note the file's name. The latest version of Java is version 8, but you also need the update version number, which is written in the file name after the "8u" section.
    1. For example, your file might be named "jre-8u151", signifying that it is version 8, update 151.
  4. 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 by clicking a bar at the top or bottom of the screen.
  5. Picture 12 of How to Install Java on Linux
    Enter the root command. Type in sudo su and press Enter. This will prompt the command line to request your user password.[1]
  6. Picture 13 of How to Install Java on Linux
    Enter your account password. Type in the password for your account and press Enter. As long as you have root access on your account, doing so will allow you to install Java.
    1. If you don't have root access on your account, you'll need to enter the password for an account that does have root access.
  7. Picture 14 of How to Install Java on Linux
    Change the installation directory. Type cd into console, press the spacebar once, and then type in the path (e.g., /usr/java/ and press Enter.
  8. Picture 15 of How to Install Java on Linux
    Enter the installation command. Type in rpm -ivh, press the spacebar once, type in the full file name, and press Enter. This will install Java on your computer.
    1. The file name will depend on when you downloaded the file. As of October 2017, you'd type in rpm -ivh jre-8u151-linux-i586.rpm and press Enter.
  9. Upgrade the download. Type in rpm -Uvh jre-8u73-linux-i586.rpm and press Enter. This will check for updates for the Java package and, if possible, apply them.
Method 3 of 4:

Installing on Ubuntu (OpenJDK)

  1. Picture 16 of How to Install Java on Linux
    Open the command line. Press Ctrl+Alt+T on the keyboard, or click the black box icon with a white ">_" on it on the left side of the screen.
  2. Picture 17 of How to Install Java on Linux
    Enter the update command. Type in sudo apt-get update && sudo apt-get upgrade -y and press Enter. This will refresh the package list and install all available updates for you.
  3. Picture 18 of How to Install Java on Linux
    Enter your password if prompted. If asked for your user password, type it in and press Enter.
  4. Picture 19 of How to Install Java on Linux
    Make sure that you don't have Java already installed. Type in java -version and press Enter. If you see a line that says "The program 'java' can be found in the following packages" appear, Java is not installed on your computer.
    1. If Java is installed, you'll see a line that reports the current version of Java instead.
  5. Picture 20 of How to Install Java on Linux
    Type in the installation command. Type sudo apt-get install default-jre into the command line, then press Enter. This will install Java on your Ubuntu computer in the default directory.
    1. If this doesn't work, try entering sudo apt-get install openjdk-8-jdk instead
Method 4 of 4:

Installing on Ubuntu 16.04 via PPAs

  1. Picture 21 of How to Install Java on Linux
    First of all, this is a 3rd party package, your distro's maintainer can't audit this package, use with caution. That being said, first open a terminal by pressing Ctrl+Alt+T.
  2. Picture 22 of How to Install Java on Linux
    Ensure you have an updated system. Type in sudo apt-get update && sudo apt-get upgrade -y, you might get prompted for a password, type it in and press Enter, no dots or asterisks will appear as you type, this is normal.
    1. While technically optional, this step is always recommended before installing anything, keeping your system updated will help prevent many problems.
  3. Picture 23 of How to Install Java on Linux
    Add the PPA repository to your system. Type in sudo add-apt-repository ppa:webupd8team/java, and then press Enter.
  4. Picture 24 of How to Install Java on Linux
    Update your package lists again. Type in sudo apt-get update and wait for the lists to be refreshed.
  5. Picture 25 of How to Install Java on Linux
    Install the package. Type in sudo apt-get install oracle-java9-installer -y.
    1. You might get prompted for a password, type it in and press Enter, no dots or asterisks will appear, this is normal.
  6. Picture 26 of How to Install Java on Linux
    Make Oracle's Java the default. In many Ubuntu derivatives, OpenJDK is set to be the default Java to be used, if you want Oracle's Java to be used by default you need to type sudo apt install oracle-java9-set-default.
« PREV POST
READ NEXT »