Skip to content

java install

Nelson Loyola edited this page Feb 27, 2019 · 3 revisions

WikiDevelopment EnvironmentInstalling Java

Installing Java

Oracle's Java SE is not included in the official Linux repositories due to license problems created by Oracle. However, it can still be installed on Linux.

  1. Download Oracle Java Java SE Development Kit from here (7u80 is the latest):

    https://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
    

    Note: Select the appropriate package for your architecture: x86 or x64.

    You will need to sign up for My Oracle Support to download this file.

  2. Run Oracle Java JDK binary:

    tar xvf jdk-7u80-linux-x64.tar.gz

    There will be a newly created folder on the same path with the extracted files

  3. Move the folder to a system wide path and give it a more identifiable name

    sudo mkdir -p /usr/lib/jvm
    cd /path/to/binary/
    sudo mv /path/to/binary/jdk1.7.0_80 /path/to/binary/java-7-oracle
    sudo mv /path/to/binary/java-7-oracle /usr/lib/jvm/
  4. Add the new version of java, javac and javaws as an system alternative and give it priority 1

    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-7-oracle/bin/java" 1
    sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-7-oracle/bin/javac" 1
    sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/java-7-oracle/bin/javaws" 1
  5. Select the new alternatives to be used

    sudo update-alternatives --config java
    sudo update-alternatives --config javac
    sudo update-alternatives --config javaws
  6. Test your newly added java and javac. The java -version command should return:

    java version "1.7.0_80"
    Java(TM) SE Runtime Environment (build 1.7.0_80-b12)
    Java HotSpot(TM) Client VM (build 20.5-b03, mixed mode, sharing)

    and the javac -version command should return

    javac 1.7.0_80
  7. Update system paths. Open /etc/profile with you favorite text editor, ie.

    sudo vi /etc/profile

    Navigate to the end of the file and add these contents:

    JAVA_HOME=/usr/lib/jvm/java-7-oracle
    PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
    export JAVA_HOME
    export JAVA_BIN
    export PATH

    Reload your system wide /etc/profile with the command:

    . /etc/profile