Do you need to run Java programs on Ubuntu? Perhaps you want to use Java to create applications. Java is a general-purpose programming language that is designed to run on any platform with as few dependencies as possible. Java Runtime Environment (JRE) allows you to run Java applications on your computer. Java Development Kit (JDK) allows you to write and compile programs in Java. You can easily install Open Java using the Terminal. You can also install Oracle Java, which has some additional commercial features using a different software repository in the Terminal. This wikiHow teaches you how to install Java using the Terminal on Ubuntu.

Method 1
Method 1 of 4:

Installing Open Java Run Time Environment

  1. 1
    Press Ctrl+Alt+T to open the Terminal. This is the keyboard shortcut to open the Terminal in Ubuntu.
    • Alternatively, you can click the Terminal icon in the Apps menu. It has an icon that resembles a black screen with a white cursor.
  2. 2
    Type sudo apt update and press Enter. This updates the "apt" software repository so that you are running the latest version.
    • If prompted to do so, enter your Ubuntu user password and press Enter.
    Advertisement
  3. 3
    Type java -version and press Enter. This checks if Java is already installed on your computer. If Java is already installed, it will display which version of JDK and JRE you have installed. If Java is not already installed, it will say "'Java', not found."[1]
  4. 4
    Type sudo apt install default-jre and press Enter. This is the command to install the latest version of Java Runtime Environment on your Ubuntu system. Java Runtime Environment allows you to run Java applications on your computer.
  5. 5
    Type y and press Enter. This confirms that you want to install Java Runtime Environment and installs the latest version of Java Runtime Environment.
    • You can verify your Java installation using the "java -version" command.
  6. Advertisement
Method 2
Method 2 of 4:

Installing Open Java Development Kit

  1. 1
    Press Ctrl+Alt+T to open the Terminal. This is the keyboard shortcut to open the Terminal in Ubuntu.
    • Alternatively, you can click the Terminal icon in the Apps menu. It has an icon that resembles a black screen with a white cursor.
  2. 2
    Type sudo apt update and press Enter. This updates the "apt" software repository so that you are running the latest version.
    • If prompted to do so, enter the user password you use to log in to Ubuntu.
  3. 3
    Type java -version and press Enter. This checks if Java is already installed on your computer. If Java is already installed, it will display which version of JDK and JRE you have installed. If Java is not already installed, it will say "'Java', not found."
  4. 4
    Type sudo apt install default-jdk and press Enter. This is the command to install the latest version of Java Development Kit on your Ubuntu system. Java Development Kit allows you to write applications using the Java programming language.
    • If you want to install a specific version of Java, you can do so using the following command: sudo apt install openjdk-#-jdk. Replace "#" with the version of Java you want to download (i.e. "8" to install JDK 8).
  5. 5
    Type y and press Enter. This confirms that you want to install Java Runtime Environment and installs Java Development Kit.
    • You can verify your Java installation using the "java -version" command.
  6. Advertisement
Method 3
Method 3 of 4:

Installing Oracle Java

  1. 1
    Press Ctrl+Alt+T to open the Terminal. This is the keyboard shortcut to open the Terminal in Ubuntu.
    • Alternatively, you can click the Terminal icon in the Apps menu. It has an icon that resembles a black screen with a white cursor.
  2. 2
    Type sudo apt update and press Enter. This updates the "apt" software repository so that you are running the latest version.
    • If prompted to do so, enter the user password you use to log in to Ubuntu.
  3. 3
    Type java -version and press Enter. This checks if Java is already installed on your computer. If Java is already installed, it will display which version of JDK and JRE you have installed. If Java is not already installed, it will say "'Java', not found."
  4. 4
    Type sudo apt install software-properties-common and press Enter. This installs the properties needed to add the software repository needed to install Oracle Java.
  5. 5
    Type sudo add-apt-repository ppa:linuxuprising/java and press Enter. This installs the software repository that is needed to install Oracle Java.
    • Alternatively, you can install Oracle Java from the "Webupd8" software repository. Use the following command to do so: sudo add-apt-repository ppa:webupd8team/java
    • If prompted to do so, enter the password you use to log in to Ubuntu and press Enter.
  6. 6
    Type sudo apt update and press Enter. This updates the repository so that you are running the latest version.
  7. 7
    Type sudo apt install oracle-java11-installer-local and press Enter. This is the command to install the latest version of Java.[2]
    • If you want to install a specific version of Java, replace the "11" with the version number you want to install (i.e. Java10).
  8. 8
    Type y and press Enter. This confirms that you want to install Oracle Java.
  9. 9
    Agree to the Terms and Conditions. To do so, scroll down to the bottom of the text document and select Ok' and press Enter. Then select Yes and press Enter. This completes the Java installation.
  10. Advertisement
Method 4
Method 4 of 4:

Setting a Default Version of Java

  1. 1
    Press Ctrl+Alt+T to open the Terminal. This is the keyboard shortcut to open the Terminal in Ubuntu. If there is more than one version of Java installed on your Ubuntu system, you can specify which version you want to use as the default version.
    • Alternatively, you can click the Terminal icon in the Apps menu. It has an icon that resembles a black screen with a white cursor.
  2. 2
    Typesudo update-alternatives --config java and press Enter. This displays all versions of Java currently installed on your Ubuntu system. Each version is listed by a numbered mode.
  3. 3
    Press the number that corresponds to the version you want to use and press Enter. This sets the Java version you selected as the default version of Java.
  4. Advertisement

About This Article

Travis Boylls
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Travis Boylls. Travis Boylls is a Technology Writer and Editor for wikiHow. Travis has experience writing technology-related articles, providing software customer service, and in graphic design. He specializes in Windows, macOS, Android, iOS, and Linux platforms. He studied graphic design at Pikes Peak Community College. This article has been viewed 11,120 times.
How helpful is this?
Co-authors: 2
Updated: February 12, 2022
Views: 11,120
Categories: Ubuntu | Java
Advertisement