Download ArticleDownload Article

This How.com.vn teaches you how to install the latest version of the Java Runtime Environment (JRE) on a computer running Linux.

Method 1
Method 1 of 4:

Installing on Non-RPM Linux

Download Article
  1. How.com.vn English: Step 1 Open the Java...
    Open the Java for Linux download page. You'll see several options listed here.
  2. How.com.vn English: Step 2 Click Linux.
    It's a link in the middle of the page. Doing so will prompt the Java installation file to download.
    • You can also click the Linux X64 version if you want to install 64-bit Java.
    Advertisement
  3. How.com.vn English: Step 3 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.
    • For example, your file might be named "jre-8u151", signifying that it is version 8, update 151.
  4. How.com.vn English: Step 4 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. How.com.vn English: Step 5 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. How.com.vn English: Step 6 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.
    • As of October 2017, you'd type in tar zxvf jre-8u151-linux-i586.tar.
  7. How.com.vn English: Step 7 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).
  8. Advertisement
Method 2
Method 2 of 4:

Installing on RPM Linux

Download Article
  1. How.com.vn English: Step 1 Open the Java...
    Open the Java for Linux download page. You'll see several options listed here.
  2. How.com.vn English: Step 2 Click Linux RPM.
    It's in the middle of the page. Doing so will prompt the Java for RPM installation file to download.
    • You can also click the Linux RPM X64 version if you want to install 64-bit Java.
  3. How.com.vn English: Step 3 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.
    • For example, your file might be named "jre-8u151", signifying that it is version 8, update 151.
  4. How.com.vn English: Step 4 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. How.com.vn English: Step 5 Enter the root command.
    Type in sudo su and press Enter. This will prompt the command line to request your user password.[1]
  6. How.com.vn English: Step 6 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.
    • 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. How.com.vn English: Step 7 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. How.com.vn English: Step 8 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.
    • 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. 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.
  10. Advertisement
Method 3
Method 3 of 4:

Installing on Ubuntu (OpenJDK)

Download Article
  1. How.com.vn English: Step 1 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. How.com.vn English: Step 2 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. How.com.vn English: Step 3 Enter your password if prompted.
    If asked for your user password, type it in and press Enter.
  4. How.com.vn English: Step 4 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.
    • If Java is installed, you'll see a line that reports the current version of Java instead.
  5. How.com.vn English: Step 5 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.
    • If this doesn't work, try entering sudo apt-get install openjdk-8-jdk instead
  6. Advertisement
Method 4
Method 4 of 4:

Installing on Ubuntu 16.04 via PPAs

Download Article
  1. How.com.vn English: Step 1 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. How.com.vn English: Step 2 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.
    • While technically optional, this step is always recommended before installing anything, keeping your system updated will help prevent many problems.
  3. How.com.vn English: Step 3 Add the PPA repository to your system.
    Type in sudo add-apt-repository ppa:webupd8team/java, and then press Enter.
  4. How.com.vn English: Step 4 Update your package lists again.
    Type in sudo apt-get update and wait for the lists to be refreshed.
  5. How.com.vn English: Step 5 Install the package.
    Type in sudo apt-get install oracle-java9-installer -y.
    • You might get prompted for a password, type it in and press Enter, no dots or asterisks will appear, this is normal.
  6. How.com.vn English: Step 6 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.
  7. Advertisement

Community Q&A

Search
Add New Question
  • Question
    I can't run Java after installing it from a TAR. When I try the java -version command, it tells me that Java is not installed. When I try ./java, it opens a help page! What's going on?
    How.com.vn English: Living Concrete
    Living Concrete
    Top Answerer
    It sounds like the ./java worked, but you didn't include any parameters. Try using ./java -version and see what that gives you. Please note that you will have to use the full path to the Java binary every time that you wish to use Java. If you want to be able to execute it from anywhere without having to do that, you will need to add the binary to your PATH variable. If you're a beginner, it's strongly suggested that you use a GUI package manager to install Java and do this for you.
  • Question
    I installed with the first way, but cant get it to run. Any ideas?
    How.com.vn English: Somone
    Somone
    Community Answer
    Make sure you have the right Java selected for your operating system, and make sure your OS is up to date.
  • Question
    I am connecting a Java project to its database. Do I have to install anything else apart from the JDK?
    How.com.vn English: Living Concrete
    Living Concrete
    Top Answerer
    You will likely have to download a Java library to assist your program in communicating with the database. It's recommended to use Maven or Gradle to assist with this.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Tips

      • While there are ways to download Java using a program interface (e.g., a GUI), the installation process takes significantly less time if you use the command line.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      Warnings

      • Oracle Java is no longer supported on Ubuntu. Use OpenJDK instead (free implementation of Oracle Java).
      • Oracle doesn't distribute .deb packages, any and all .deb packages for Oracle's Java is from a 3rd party and can cause harm to your system.
      Advertisement

      About This Article

      How.com.vn English: Jack Lloyd
      Written by:
      How.com.vn Technology Writer
      This article was co-authored by How.com.vn staff writer, Jack Lloyd. Jack Lloyd is a Technology Writer and Editor for How.com.vn. He has over two years of experience writing and editing technology-related articles. He is technology enthusiast and an English teacher. This article has been viewed 1,075,843 times.
      How helpful is this?
      Co-authors: 43
      Updated: January 17, 2024
      Views: 1,075,843
      Categories: Linux
      Thanks to all authors for creating a page that has been read 1,075,843 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement