How to Install Oracle Java JDK on Ubuntu Linux Operating System

Author: Laura McKinney
Date Of Creation: 10 August 2021
Update Date: 1 July 2024
Anonim
How To Install Oracle Java (JDK) On Ubuntu 20.04 LTS, Debian Linux
Video: How To Install Oracle Java (JDK) On Ubuntu 20.04 LTS, Debian Linux

Content

This tutorial will cover how to install Oracle Java 8 32-bit and 64-bit (version 1.8.0_20JDK on 32-bit and 64-bit Ubuntu operating systems. These steps are only applicable on Debian and Linux Mint. This article is only for those who want to install the Oracle Java JDK with the Oracle Java JRE included in the JDK download. Instructions for installing Oracle Java JDK on Debian and Linux platforms such as Debian, Ubuntu and Linux Mint.

Steps

  1. Check if your Ubuntu Linux operating system is 32-bit or 64-bit, open the terminal and enter the following command.
    • Type / Copy / Paste: file / sbin / init
      • Note whether Ubuntu Linux version is 32-bit or 64-bit.

  2. Check if Java is installed on the system or not. You need to enter the command into the terminal.
    • Open the terminal and enter the following command.
      • Type / Copy / Paste: java -version
    • If OpenJDK is installed you will see the following line appear:
      • java version "1.7.0_15"
        OpenJDK Runtime Environment (IcedTea6 1.10pre) (7b15 ~ pre1-0lucid1)
        OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
    • If you have OpenJDK installed on your system, you have installed the wrong version of this exercise.

  3. Completely remove OpenJDK / JRE from the system and create a directory to store the Oracle Java JDK / JRE binaries. This is how to avoid system conflicts and confusion between different developers' versions of Java. For example, if you install OpenJDK / JRE on your system, you can remove it by entering the following command:
    • Type / Copy / Paste: sudo apt-get purge openjdk - *
      • This command will completely remove OpenJDK / JRE from the system.
    • Type / Copy / Paste: sudo mkdir -p / usr / local / java
      • This command will create a directory to store binaries of Oracle Java JDK and JRE.

  4. Download Oracle Java JDK for Linux. Make sure to choose exactly Compressed binaries for 32-bit or 64-bit operating systems (ending with tar.gz).
    • For example, if you are using 32-bit Ubuntu Linux, download 32-bit Oracle Java.
    • If using Ubuntu Linux 64-bit download Oracle Java 64-bit.
    • Option, Downloading Oracle Java JDK documents
      • Select jdk-8u20-apidocs.zip
    • Important Information: 64-bit Oracle Java does not work on 32-bit Linux operating system, you will receive a system error message if you intentionally install 64-bit Oracle Java on 32-bit Ubuntu Linux.
  5. Copy the Oracle Java binary to the / usr / local / java directory. Usually downloaded Java is stored in the directory: / home /"Your name"/ Downloads.
    • How to install Oracle Java 32-bit on Ubuntu Linux 32-bi:
      • Type / Copy / Paste: cd / home /"Your name"/ Downloads
      • Type / Copy / Paste: sudo cp -r jdk-8u20-linux-i586.tar.gz / usr / local / java /
      • Type / Copy / Paste: cd / usr / local / java
    • Instructions for installing Oracle Java 64-bit on Ubuntu 64-bit:
      • Type / Copy / Paste: cd / home /"Your name"/ Downloads
      • Type / Copy / Paste: sudo cp -r jdk-8u20-linux-x64.tar.gz / usr / local / java /
      • Type / Copy / Paste: cd / usr / local / java
  6. Extract the Java file in / usr / local / java directory
    • How to install Oracle Java 32-bit on Ubuntu Linux 32-bit:
      • Type / Copy / Paste: sudo tar xvzf jdk-8u20-linux-i586.tar.gz
    • How to install Oracle Java 64-bit on Ubuntu Linux 64-bit:
      • Type / Copy / Paste: sudo tar xvzf jdk-8u20-linux-x64.tar.gz
  7. Check the directory 1 again. At this step, you will see 2 uncompressed binary directories at / usr / local / java of Java JDK / JRE listed as follows:
    • Type / Copy / Paste: ls -a
    • jdk1.8.0_20
    • jre1.8.0_20
  8. Edit the / etc / profile file path and add the following system variables to the path. Use nano, gedit or any other text editor to open / etc / profile.
    • Type / Copy / Paste: sudo gedit / etc / profile
    • or
    • Type / Copy / Paste: sudo nano / etc / profile
  9. Scroll to the bottom of the file using the navigation key and enter the following line in / etc / profile file:
    • Type / Copy / Paste:

      JAVA_HOME = / usr / local / java /jdk1.8.0_20
      JRE_HOME = / usr / local / java /jre1.8.0_20
      PATH = $ PATH: $ JRE_HOME / bin: $ JAVA_HOME / bin
      export JAVA_HOME
      export JRE_HOME
      export PATH
  10. Save the / etc / profile file and exit.
  11. Inform the Ubuntu Linux system of the location of the Oracle Java JDK / JRE. This is how to notify the system that Oracle Java version is ready for use.
    • Type / Copy / Paste: sudo update-alternatives -install "/ usr / bin / java" "java" "/usr/local/java/jdk1.8.0_20/bin/java" 1
      • This is the command to inform the system that the Oracle Java JRE is ready for use.
    • Type / Copy / Paste: sudo update-alternatives -install "/ usr / bin / javac" "javac" "/usr/local/java/jdk1.8.0_20/bin/javac" 1
      • This is the command to inform the system that the Oracle Java JDK is ready for use.
    • Type / Copy / Paste: sudo update-alternatives -install "/ usr / bin / javaws" "javaws" "/usr/local/java/jdk1.8.0_20/bin/javaws" 1
      • This is the command to inform the system that Oracle Java Web is ready for use.
  12. Inform the Ubuntu Linux system that the Oracle Java JDK / JRE is the default Java.
    • Type / Copy / Paste: sudo update-alternatives -set java /usr/local/java/jdk1.8.0_20/bin/java
      • This is the command to set up java runtime system for the system.
    • Type / Copy / Paste: sudo update-alternatives -set javac /usr/local/java/jdk1.8.0_20/bin/javac
      • This is the command to set up the javac compiler for the system.
    • Type / Copy / Paste: sudo update-alternatives -set javaws /usr/local/java/jdk1.8.0_20/bin/javaws
      • This is the command to set Java Web to boot on the system.
  13. Reload the / etc / profile system path by entering the following command:
    • Type / Copy / Paste: source / etc / profile
    • Make note of the file path / etc / profile that will reboot your Ubuntu Linux system.
  14. Check if Oracle Java is installed correctly on the system or not. Run the following command and remember the Java version:
  15. Successful installation of Oracle Java 32-bit will display:
    • Type / Copy / Paste: java -version
      • This is the command to show the java version running on the system.
    • You will receive the following message.
      • java version "1.8.0_20"
        Java (TM) SE Runtime Environment (build 1.8.0_20-b26)
        Java HotSpot (TM) Server VM (build 25.20-b23, mixed mode)
    • Type / Copy / Paste: javac -version
      • This is a command that informs you that you can compile Java programs from the terminal.
    • You will receive the following message:
      • javac 1.8.0_20
  16. Successful installation of Oracle Java 64-bit displays:
    • Type / Copy / Paste: java -version
      • This is the command to show the java version running on the system.
    • You will receive the following message:
      • java version "1.8.0_20"
        Java (TM) SE Runtime Environment (build 1.8.0_20-b26)
        Java HotSpot (TM) Server VM (build 25.20-b23, mixed mode)
    • Type / Copy / Paste: javac -version
      • This is a command telling you that you can compile Java programs from the terminal.
    • You will receive the following message:
      • javac 1.8.0_20
  17. Congratulations, you have successfully installed Oracle Java on your Linux system. Now, reboot your Ubuntu Linux system. The system will then be fully configured to run and develop Java programs. Next, you can compile and run Java programs following the online tutorials. advertisement

Optional: How to enable Oracle Java on the Web Browser

  1. To enable Java plug-ins in a web browser, you must create a symbolic link from the browser's plug-in directory to the Java plug-in location including Oracle Java.

Important Note: I would be cautious when enabling Oracle Java 7 on a web browser because of many security vulnerabilities and exploits. In particular, when activating Oracle Java 7 on your web browser, if there is a security hole and exploit it, the bad guy can break into your system. For more detailed information, visit the following website: Java Tester

Google Chrome

Oracle Java 32-bit Tutorial:

  1. Issue the following commands.
    • Type / Copy / Paste: sudo mkdir -p / opt / google / chrome / plugins
      • This is the command to create / opt / google / chrome / plugins directory
    • Type / Copy / Paste: cd / opt / google / chrome / plugins
      • This is the change command in the Google Chrome plugin directory, make sure you are in that directory before creating the icon link.
    • Type / Copy / Paste: sudo ln -s /usr/local/java/jdk1.8.0_20/jre/lib/i386/libnpjp2.so
      • Here is the command to generate symbolic link from JRE (Java Operating Environment) plugin. libnpjp2.so to the Google Chrome web browser.

Oracle Java64-bit Tutorial:

  1. Enter the following commands:
    • Type / Copy / Paste: sudo mkdir -p / opt / google / chrome / plugins
      • This is the command to create / opt / google / chrome / plugins directory
    • Type / Copy / Paste: cd / opt / google / chrome / plugins
      • This is a change command in the Google Chrome plugi n directory, make sure you are in this directory before creating the symbolic link.
    • Type / Copy / Paste: sudo ln -s /usr/local/java/jdk1.8.0_20/jre/lib/amd64/libnpjp2.so
      • Here is the command to generate symbolic link from Java JRE (Java Operating Environment) plugin. libnpjp2.so to the Google Chrome web browser.

Remind:

  1. Note: Many times, you will receive the following message:
    • ln: creating symbolic link `./libnpjp2.so ': File exists
    • To get around this, simply remove the previous symbol link with the following command:
    • Type / Copy / Paste: cd / opt / google / chrome / plugins
    • Type / Copy / Paste: sudo rm -rf libnpjp2.so
    • Make sure you are in the / opt / google / chrome / plugins directory before entering the command.
  2. Restart the web browser and visit Java Tester to test Java functionality on the browser.

Mozilla Firefox

Oracle Java 32-bit Tutorial:

  1. Enter the following commands:
    • Type / Copy / Paste: cd / usr / lib / mozilla / plugins
      • This is the command to change in the / usr / lib / mozilla / plugins directory, creating a directory if it is not already available.
    • Type / Copy / Paste: sudo mkdir -p / usr / lib / mozilla / plugins
      • Here is the command to create / usr / lib / mozilla / plugins directory, make sure you are in this directory before creating the symbolic link.
    • Type / Copy / Paste: sudo ln -s /usr/local/java/jdk1.8.0_20/jre/lib/i386/libnpjp2.so
      • Here is the command to generate symbolic link from Java JRE (Java Operating Environment) plugin. libnpjp2.so to the Mozilla Firefox web browser.

Oracle Java 64-bit Tutorial:

  1. Enter the following commands.
    • Type / Copy / Paste: cd / usr / lib / mozilla / plugins
      • This is the command change in the / usr / lib / mozilla / plugins directory, creating the directory yourself if it is not already available.
    • Type / Copy / Paste: sudo mkdir -p / usr / lib / mozilla / plugins
      • Here is the command to create / usr / lib / mozilla / plugins directory, make sure you are in this directory before creating the symbolic link.
    • Type / Copy / Paste: sudo ln -s /usr/local/java/jdk1.8.0_20/jre/lib/amd64/libnpjp2.so
      • Here is the command to generate Java JRE (Java Operating Environment) plugin icon link. libnpjp2.so to the Mozilla Firefox web browser.

Remind:

  1. Note: Many times, you will receive the following message:
    • ln: creating symbolic link `./libnpjp2.so ': File exists
    • To solve this problem simply remove the previous symbol link with the following command:
    • Type / Copy / Paste: cd / usr / lib / mozilla / plugins
    • Type / Copy / Paste: sudo rm -rf libnpjp2.so
    • Make sure you are in / usr / lib / mozilla / plugins directory before entering the command.
  2. Restart the web browser and visit the Java Tester page to test Java functionality on the browser.