Java Language


Installing Java (Standard Edition) All Versions

Java SE 1.0
Java SE 1.1
Java SE 1.2
Java SE 1.3
Java SE 1.4
Java SE 5
Java SE 6
Java SE 7
Java SE 8
Java SE 9 (Early Access)

This draft deletes the entire topic.

Introduction

Introduction

expand all collapse all

Examples

  • 38

    Assumptions:

    • An Oracle JDK has been installed.
    • The JDK was installed to the default directory.

    Setup steps

    1. Open Windows Explorer.

    2. In the navigation pane on the left right click on This PC (or Computer for older Windows versions). There is a shorter way without using the explorer in actual Windows versions: Just press Win+Pause

    3. In the newly opened Control Panel window, left click Advanced System Settings which should be in the top left corner. This will open the System Properties window.
      enter image description here

      Alternatively, type SystemPropertiesAdvanced (case insensitive) in the Run (Win+R), and hit Enter.

    4. In the Advanced tab of System Properties select the Environment Variables... button in the lower right corner of the window.

    5. Add a New System Variable by clicking the New... button in System Variables with the name JAVA_HOME and whose value is the path to the directory where the JDK was installed. After entering these values, press OK.

      JAVA_HOME Environment Variable

    6. Scroll down the list of System Variables and select the Path variable.

    7. CAUTION: Windows relies on Path to find important programs. If any or all of it is removed, Windows may not be able to function properly. It must be modified to allow Windows to run the JDK. With this in mind ,click the "Edit..." button with the Path variable selected. Add %JAVA_HOME%\bin; to the beginning of the Path variable.

    It is better to append at the begining of the line because Oracle's software used to register their own version of Java in Path - This will cause your version to be ignored if it occurs after Oracle's declaration.


    Check your work

    1. Open the command prompt by clicking Start then typing cmd and pressing Enter.
    2. Enter javac -version into the prompt. If it was successful, then the version of the JDK will be printed to the screen.

    Note: If you have to try again, close the prompt before checking your work. This will force windows to get the new version of Path.

  • 6

    Using the Package Manager

    JDK and/or JRE releases for OpenJDK or Oracle can be installed using the package manager on most mainstream Linux distribution. (The choices that are available to you will depend on the distro.)

    As a general rule, the procedure is to open terminal window and run the commands shown below. (It is assumed that you have sufficient access to run commands as the "root" user ... which is what the sudo command does. If you do not, then please talk to your system's administrators.)

    Using the package manager is recommended because it (generally) makes it easier to keep your Java installation up to date.

    apt-get, Debian based Linux distributions (Ubuntu, etc)

    The following instructions will install Oracle Java 8:

    $ sudo add-apt-repository ppa:webupd8team/java
    $ sudo apt-get update
    $ sudo apt-get install oracle-java8-installer
    

    Note: To automatically set up the Java 8 environment variables, you can install the following package:

    $ sudo apt-get install oracle-java8-set-default
    

    Creating a .deb file

    If you prefer to create the .deb file yourself from the .tar.gz file downloaded from Oracle, do the following (assuming you've downloaded the .tar.gz to ./<jdk>.tar.gz):

    $ sudo apt-get install java-package # might not be available in default repos
    $ make-jpkg ./<jdk>.tar.gz          # should not be run as root
    $ sudo dpkg -i *j2sdk*.deb
    

    Note: This expects the input to be provided as a ".tar.gz" file.

    slackpkg, Slackware based Linux distributions

    sudo slapt-get install default-jdk
    

    yum, RedHat, CentOS, etc

    sudo yum install java-1.8.0-openjdk-devel.x86_64
    

    dnf, Fedora

    On recent Fedora releases, yum has been superseded by dnf.

    sudo dnf install java-1.8.0-openjdk-devel.x86_64
    

    In recent Fedora releases, there are no packages for installing Java 7 and earlier.

    pacman, Arch based Linux distributions

    sudo pacman -S jdk8-openjdk
    

    Using sudo is not required if you're running as the root user.

    Gentoo Linux

    The Gentoo Java guide is maintained by the Gentoo Java team and keeps an updated wiki page including the correct portage packages and USE flags needed.

    Installing Oracle JDKs on Redhat, CentOS, Fedora

    Installing JDK from an Oracle JDK or JRE tar.gz file.

    1. Download the appropriate Oracle archive ("tar.gz") file for the desired release from the Oracle Java downloads site.

    2. Change directory to the place where you want to put the installation;

    3. Decompress the archive file; e.g.

      tar xzvf jdk-8u67-linux-x64.tar.gz
      

    Installing from an Oracle Java RPM file.

    1. Retrieve the required RPM file for the desired release from the Oracle Java downloads site.

    2. Install using the rpm command. For example:

      $ sudo rpm -ivh jdk-8u67-linux-x644.rpm 
      
  • 3

    Oracle Java 7 and Java 8

    Java 7 and Java 8 for macOS are available from Oracle. This Oracle page answers a lot of questions about Java for Mac. Note that Java 7 prior to 7u25 have been disabled by Apple for security reasons.

    In general, Oracle Java (Version 7 and later) requires an Intel-based Mac running macOS 10.7.3 or later.

    Installation of Oracle Java

    Java 7 & 8 JDK and JRE installers for macOS can be downloaded from Oracle’s website:

    After downloading the relevant package, double click on the package and go through the normal installation process. A JDK should get installed here:

    /Library/Java/JavaVirtualMachines/<version>.jdk/Contents/Home
    

    where corresponds to the installed version.

    Command-Line Switching

    When Java is installed, the installed version is automatically set as the default. To switch between different, use:

    export JAVA_HOME=/usr/libexec/java_home -v 1.6 #Or 1.7 or 1.8
    

    The following functions can be added to the ~/.bash_profile (If you use the default Bash shell) for ease of use:

    function java_version {
       echo 'java -version';
    }
    
    function java_set {
       if [[ $1 == "6" ]]
       then
           export JAVA_HOME='/usr/libexec/java_home -v 1.6';
           echo "Setting Java to version 6..."
           echo "$JAVA_HOME"
       elif [[ $1 == "7" ]]
       then
           export JAVA_HOME='/usr/libexec/java_home -v 1.7';
           echo "Setting Java to version 7..."
           echo "$JAVA_HOME"
       elif [[ $1 == "8" ]]
       then
           export JAVA_HOME='/usr/libexec/java_home -v 1.8';
           echo "Setting Java to version 8..."
           echo "$JAVA_HOME"
       fi            
    }
    

    Apple Java 6 on macOS

    On older versions of macOS (10.11 El Capitan and earlier), Apple's release of Java 6 comes pre-installed. If installed, it can be be found at this location:

    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    

    Note that Java 6 passed its end-of-life long ago, so upgrading to a newer version is recommended. There is more information on reinstalling Apple Java 6 on the Oracle website.

Please consider making a request to improve this example.

Syntax

Syntax

Parameters

Parameters

Remarks

Remarks

Still have a question about Installing Java (Standard Edition)? Ask Question

Topic Outline