Install Oracle Java on Ubuntu Linux

Author: Frank Hunt
Date Of Creation: 15 March 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 article describes the installation of 32-bit and 64-bit Oracle Java 7 (current version number 1.7.0_21) JDK / JRE on 32-bit and 64-bit Ubuntu operating systems. The instructions also work with Debian and Linux Mint.

To step

  1. Check if your Ubuntu Linux operating system is 32-bit or 64-bit, open a terminal window and run the following command.
    • Type / Copy / Paste: file / sbin / init
      • Look at the bit version of your Ubuntu Linux operating system, it shows if it is 32-bit or 64-bit.
  2. Check if Java is installed on your system. To do this you need to run the Java version command.
    • open a terminal window and run the following command:
      • Type / Copy / Paste: java version
    • If OpenJDK is installed on your system it might look like this:
      • 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 OpenJDK is installed on your system you may have installed the wrong manufacturer version of Java for this guide.
  3. Remove OpenJDK / JRE from your system and create a directory that will contain your Oracle Java JDK / JRE binaries. This avoids system conflicts and confusion between different manufacturer versions of Java. For example, if you have OpenJDK / JRE installed on your system, you can remove it by typing the following in a terminal window:
    • Type / Copy / Paste: sudo apt-get purge openjdk - *
      • This command removes OpenJDK / JRE from your system
    • Type / Copy / Paste: sudo mkdir -p / usr / local / java
      • This command creates a directory that contains your Oracle Java JDK and JRE binaries.
  4. Download Oracle Java JDK / JRE for Linux. Make sure you get the correct select compressed binaries for your system (32-bit / 64-bit, ending in tar.gz).
    • If your Ubuntu Linux is 32-bit, download 32-bit Oracle Java binaries.
    • If your Ubuntu Linux is 64-bit, download 64-bit Oracle Java binaries.
    • Optional Download the Oracle Java JDK / JRE Documentation
      • Select jdk-7u21-apidocs.zip
    • Important information 64-bit Oracle Java binaries will not work on 32-bit Ubuntu Linux operating systems, you will get various system error messages.
  5. Copy the Oracle Java binaries to the / usr / local / java directory. Usually the Oracle Java binaries are downloaded to: / home /"your_user_name"/Downloads.
    • Instructions for installing 32-bit Oracle Java on 32-bit Ubuntu Linux:
      • Type / Copy / Paste: cd / home /"your_user_name"/Downloads
      • Type / Copy / Paste: sudo cp -r jdk-7u21-linux-i586.tar.gz / usr / local / java
      • Type / Copy / Paste: sudo cp -r jre-7u21-linux-i586.tar.gz / usr / local / java
      • Type / Copy / Paste: cd / usr / local / java
    • Instructions for installing 64-bit Oracle Java on 64-bit Ubuntu Linux:
      • Type / Copy / Paste: cd / home /"your_user_name"/Downloads
      • Type / Copy / Paste: sudo cp -r jdk-7u21-linux-x64.tar.gz / usr / local / java
      • Type / Copy / Paste: sudo cp -r jre-7u21-linux-x64.tar.gz / usr / local / java
      • Type / Copy / Paste: cd / usr / local / java
  6. Extract the compressed Java binaries in the directory / usr / local / java
    • Instructions for installing 32-bit Oracle Java on 32-bit Ubuntu Linux:
      • Type / Copy / Paste: sudo tar xvzf jdk-7u21-linux-i586.tar.gz
      • Type / Copy / Paste: sudo tar xvzf jre-7u21-linux-i586.tar.gz
    • Instructions for installing 64-bit Oracle Java on 64-bit Ubuntu Linux:
      • Type / Copy / Paste: sudo tar xvzf jdk-7u21-linux-x64.tar.gz
      • Type / Copy / Paste: sudo tar xvzf jre-7u21-linux-x64.tar.gz
  7. Check your directories again. There should now be two uncompressed binary directories in / usr / local / java for Java JDK / JRE named as follows:
    • Type / Copy / Paste: ls -a
    • jdk1.7.0_21
    • jre1.7.0_21
  8. Edit the system PATH file / etc / profile and add the following system variables to your system path. Use nano, gedit or another text editor, as root open / etc / profile.
    • Type / Copy / Paste: sudo gedit / etc / profile
    • or
    • Type / Copy / Paste: sudo nano / etc / profile
  9. Scroll to the end of the file with your arrows and add the following lines to the end of your / etc / profile file:
    • Type / Copy / Paste:

      JAVA_HOME = / usr / local / java /jdk1.7.0_21
      PATH = $ PATH: $ HOME / bin: $ JAVA_HOME / bin
      JRE_HOME = / usr / local / java /jre1.7.0_21
      PATH = $ PATH: $ HOME / bin: $ JRE_HOME / bin
      export JAVA_HOME
      export JRE_HOME
      export PATH
  10. Save the / etc / profile file and close the window.
  11. Inform your Ubuntu Linux system where Oracle Java JDK / JRE is stored. Then the system knows that the new version of Oracle Java is ready for use.
    • Type / Copy / Paste: sudo update-alternatives --install "/ usr / bin / java" "java" "/usr/local/java/jre1.7.0_21/bin/java" 1
      • This command tells the system that Oracle Java JRE is ready to use.
    • Type / Copy / Paste: sudo update-alternatives --install "/ usr / bin / javac" "javac" "/usr/local/java/jdk1.7.0_21/bin/javac" 1
      • This command tells the system that Oracle Java JDK is ready to use.
    • Type / Copy / Paste: sudo update-alternatives --install "/ usr / bin / javaws" "javaws" "/usr/local/java/jre1.7.0_21/bin/javaws" 1
      • This command tells the system that Oracle Java Web Start is ready to use.
  12. Inform your Ubuntu Linux system that Oracle Java JDK / JRE must be the default Java.
    • Type / Copy / Paste: sudo update-alternatives --set java /usr/local/java/jre1.7.0_21/bin/java
      • This command sets up the java runtime environment for the system
    • Type / Copy / Paste: sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_21/bin/javac
      • This command sets up the java compiler for the system
    • Type / Copy / Paste: sudo update-alternatives --set javaws /usr/local/java/jre1.7.0_21/bin/javaws
      • This command sets up java Web Start for the system
  13. Reload PATH / etc / profile by typing the following command:
    • Type / Copy / Paste: . / etc / profile
    • Note: your PATH / etc / profile file will be loaded after you restart Ubuntu Linux.
  14. Test to see if Oracle Java was properly installed on the system. Run the following commands and look at the Java version.
  15. Upon successful installation of 32-bit Oracle Java you will see:
    • Type / Copy / Paste: java version
      • This command shows the version of Jave on your system.
    • You will receive a message stating:
      • java version "1.7.0_21"
        Java (TM) SE Runtime Environment (build 1.7.0_21-b21)
        Java HotSpot (TM) Server VM (build 23.1-b03, mixed mode)
    • Type / Copy / Paste: javac version
      • This command tells you that you can now compile Java programs from Terminal
    • You will receive a message stating:
      • javac 1.7.0_21
  16. Upon successful installation of 64-bit Oracle Jave you will see:
    • Type / Copy / Paste: java version
      • This command shows the version of Jave on your system.
    • You will receive a message stating:
      • java version "1.7.0_21"
        Java (TM) SE Runtime Environment (build 1.7.0_21-b21)
        Java HotSpot (TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
    • Type / Copy / Paste: javac version
      • This command tells you that you can now compile Java programs from Terminal
    • You will receive a message stating:
      • javac 1.7.0_21
  17. Congratulations, you have now installed Oracle Java on your Linux system. Restart Ubuntu Linux. After that, the system is fully configured and you can run and develop Java programs.

Optional: How to activate Oracle Java in web browsers

  1. To enable the Java plug-in in your web browsers, you must create a symbolic link from the web browser's plug-in directory to the location of the Java plug-in that was included in the Oracle Java distribution.

Google Chrome

32-bit Oracle Java instructions:

  1. Run the following commands.
    • Type / Copy / Paste: sudo mkdir -p / opt / google / chrome / plugins
      • This will create a directory called / opt / google / chrome / plugins
    • Type / Copy / Paste: cd / opt / google / chrome / plugins
      • This will take you to the google chrome plugins directory, make sure you are in this directory before creating the symbolic link.
    • Type / Copy / Paste: sudo ln -s /usr/local/java/jre1.7.0_21/lib/i386/libnpjp2.so
      • This creates a symbolic link of the Java JRE (Java Runtime Environment) plugin libnpjp2.so to your Google Chrome web browser

64-bit Oracle Java instructions:

  1. Run the following commands.
    • Type / Copy / Paste: sudo mkdir -p / opt / google / chrome / plugins
      • This will create a directory called / opt / google / chrome / plugins
    • Type / Copy / Paste: cd / opt / google / chrome / plugins
      • This will take you to the google chrome plugins directory, make sure you are in this directory before creating the symbolic link.
    • Type / Copy / Paste: sudo ln -s /usr/local/java/jre1.7.0_21/lib/amd64/libnpjp2.so
      • This creates a symbolic link of the Java JRE (Java Runtime Environment) plugin libnpjp2.so to your Google Chrome web browser

Pay attention:

  1. Pay attention: When you run the above command you sometimes get the following message:
    • ln: creating symbolic link `./libnpjp2.so ': File exists
    • In that case, remove the preceding symbolic 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 running the command.
  2. Restart your web browser and go to Java Tester to test if Java works in your web browser.

Mozilla Firefox

32-bit Oracle Java instructions:

  1. Run the following commands.
    • Type / Paste / Copy: cd / usr / lib / mozilla / plugins
      • This will take you to the directory / usr / lib / mozilla / plugins, create this directory if it does not exist.
    • Type / Paste / Copy: sudo mkdir -p / usr / lib / mozilla / plugins
      • This will create a directory called / usr / lib / mozilla / plugins, make sure you are in this directory before creating the symbolic link.
    • Type / Paste / Copy: sudo ln -s /usr/local/java/jre1.7.0_21/lib/i386/libnpjp2.so
      • This creates a symbolic link of the Java JRE (Java Runtime Environment) plugin libnpjp2.so to your Mozilla Firefox web browser

64-bit Oracle Java instructions:

  1. Run the following commands.
    • Type / Copy / Paste: cd / usr / lib / mozilla / plugins
      • This will take you to the directory / usr / lib / mozilla / plugins, create this directory if it does not exist.
    • Type / Copy / Paste: sudo mkdir -p / usr / lib / mozilla / plugins
      • This will create a directory called / usr / lib / mozilla / plugins, make sure you are in this directory before creating the symbolic link.
    • Type / Copy / Paste: sudo ln -s /usr/local/java/jre1.7.0_21/lib/amd64/libnpjp2.so
      • This creates a symbolic link of the Java JRE (Java Runtime Environment) plugin libnpjp2.so to your Mozilla Firefox web browser

Pay attention:

  1. Pay attention: When you run the above command you sometimes get the following message:
    • ln: creating symbolic link `./libnpjp2.so ': File exists
    • In that case, remove the preceding symbolic 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 the / usr / lib / mozilla / plugins directory before running the command.
  2. Restart your web browser and go to Java Tester to test if Java works in your web browser.

Tips

  • in Ubuntu Linux you have the choice of either using OpenJDK, a free and open-source implementation of the Java programming language, or Oracle Java JDK and JRE. Some people prefer Oracle Java (which is the latest version of Java and it comes directly from the Java techies.
  • This document is subject to change as Oracle sometimes changes the installation method of their Java JDK / JRE binaries.
  • Oracle does security updates and bug fixes with every new release of Oracle Java. Note the changes in the version number during the installation of Oracle Java.