Coder Social home page Coder Social logo

install-java's Introduction

Java Development Kit (JDK) installation script for Linux

"install-java.sh" is an installation script for setting up Java Development Kit (JDK) on Debian based Linux Operating Systems.

Currently, the install-java.sh script supports tar.gz distributions from Oracle, OpenJDK and AdoptOpenJDK

I'm mainly using Ubuntu and therefore this script is tested only on different versions of Ubuntu.

Prerequisites

The script uses "unzip" command. Therefore, please make sure it is installed.

sudo apt install unzip

The "install-java.sh" script will not download the Java distribution. You must download JDK tar.gz distribution.

For Oracle JDK 7 & 8, install-java.sh supports installing demos and "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files". This files are picked up from the same directory.

For example, if you want to install Java 7, then the following files should be downloaded and moved to a single directory.

  • jdk-7u80-linux-x64.tar.gz
  • jdk-7u80-linux-x64-demos.tar.gz
  • UnlimitedJCEPolicyJDK7.zip

Similarly for Java 8, following are the files required

  • jdk-8u212-linux-x64.tar.gz
  • jdk-8u212-linux-x64-demos.tar.gz
  • jce_policy-8.zip

The Java Demos and Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy files are optional. There are no demos from Java 9 upwards. Since Java 9, default JCE policy files already allow for "unlimited" cryptographic strengths.

For any other JDK, you only need to have the Java binary distribution.

Installation

The script needs to be run as root.

You need to provide the JDK distribution file (tar.gz) and the Java Installation Directory. The default value for Java installation directory is "/usr/lib/jvm"

$ sudo ./install-java.sh -h

Usage: 
install-java.sh -f <java_dist> [-p <java_dir>]

-f: The jdk tar.gz file.
-p: Java installation directory. Default: /usr/lib/jvm.
-h: Display this help and exit.

Example: Installing Oracle JDK 12

$ sudo ./install-java.sh -f ~/software/java/jdk-12.0.1_linux-x64_bin.tar.gz 
Installing: jdk-12.0.1_linux-x64_bin.tar.gz
Extracting /home/isuru/software/java/jdk-12.0.1_linux-x64_bin.tar.gz to /usr/lib/jvm
JDK is extracted to /usr/lib/jvm/jdk-12.0.1
Run update-alternatives commands? [y/N] 
Do you want to set JAVA_HOME environment variable in /home/isuru/.bashrc? [y/N]

Automate Java Installation

You can automate the Java installation script by using the yes command.

Example: Installing AdoptOpenJDK 11

yes | sudo ./install-java.sh -f ~/software/java/OpenJDK11U-jdk_x64_linux_hotspot_11.0.3_7.tar.gz

Java Mission Control

The installation script will also create a shortcut for Oracle Java Mission Control (JMC).

If the "Welcome" page is blank in JMC, try installing libwebkitgtk-3.0-0 package.

sudo apt install libwebkitgtk-3.0-0

Uninstallation

There is another script named "uninstall-java.sh" to uninstall Java.

You need to provide Java distribution directory.

$ sudo ./uninstall-java.sh -h

Usage: 
uninstall-java.sh -p <java_dist_dir>

-p: Java distribution directory.
-h: Display this help and exit.

Example: Uninstall Oracle JDK 12

sudo ./uninstall-java.sh -p /usr/lib/jvm/jdk-12.0.1/

License

Copyright (C) 2014 M. Isuru Tharanga Chrishantha Perera

Licensed under the Apache License, Version 2.0

install-java's People

Contributors

chrishantha avatar firestorm942 avatar korosukke avatar m-razavi avatar yelkaramacsc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

install-java's Issues

install only for root

i try to execute the script with "sudo" but the result is "this script is allowed only for root"

Help With Fedora 32

Hi. I have used the script with Linux Mint 19.3 (cinnamon) and even Kubuntu 20.04 without any issues. However, I am unable to run my .JNLP files after installing Oracle jre-8u251-linux-x64.tar.gz (using this script) in Fedora KDE 32. I am not sure if the installation is happening properly. Soon after the install process, when I double-click on the .JNLP files, nothing happens. Can you test if the script is working properly with Fedora 32?

Does it works for JDK8 i586?

Hello.
I want to use your script with the jdk-8u181-linux-i586.tar.gz and the execution of:

./install-java.sh -f jdk-8u181-linux-i586.tar.gz

Returns:
Please specify a valid java distribution

Both files are in the same directory.

Also I've checked your code and I can't see support for jdk8
Regards.

Issues with OpenJDK 12

Just tried using the install-java.sh script on OpenJDK 12, filename: openjdk-12.0.1_linux-x64_bin.tar.gz

I'm using CentOS 7.6, but I can't imagine it's a problem with CentOS because there's nothing different or unique about the Distro that should be tripping it up at this part of the script I would think (like any sort of apt-get or distro specific commands). Also the Unzip package is installed, but I don't think that's the issue.

[root@testing-centos-03 ~]# yes | ./install-java.sh -f openjdk-12.0.1_linux-x64_bin.tar.gz
Extracting openjdk-12.0.1_linux-x64_bin.tar.gz to /usr/lib/jvm
JDK is extracted to /usr/lib/jvm/openjdk-12.0.1
Couldn't check the extracted directory. Please check the installation script
[root@testing-centos-03 ~]#

Looking at the code, I think the filename / extracted directory may be tripping up the script, possibly due to changing naming conventions with OpenJDK 12 (and maybe 11?) Just my best guess without fully picking things apart.

if [[ $java_dist_filename =~ $java_78_dist_file_regex ]]; then
    jdk_dir=$(echo $java_dist_filename | sed -nE "s/$java_78_dist_file_regex/jdk1.\1.0_\2/p")
    jdk_major_version=$(echo $jdk_dir | sed -nE 's/jdk1\.([0-9]*).*/\1/p')
elif [[ $java_dist_filename =~ $java_9up_dist_file_regex ]]; then
    jdk_dir=$(echo $java_dist_filename | sed -nE "s/$java_9up_dist_file_regex/jdk-\1/p")
    jdk_major_version=$(echo $jdk_dir | sed -nE 's/jdk-([0-9]*).*/\1/p')
else
    echo "Please specify a valid java distribution"
    exit 1
fi

extracted_dirname=$java_dir"/"$jdk_dir

# Extract Java Distribution

if [[ ! -d $extracted_dirname ]]; then
    echo "Extracting $java_dist to $java_dir"
    tar -xof $java_dist -C $java_dir
    echo "JDK is extracted to $extracted_dirname"
else 
    echo "JDK is already extracted to $extracted_dirname"
fi


if [[ ! -f $extracted_dirname"/bin/java" ]]; then
    echo "Couldn't check the extracted directory. Please check the installation script"
    exit 1
fi

I'm not entirely sure, but thought I'd post here to let you know! I didn't see any mentions of OpenJDK 11 or 12, so maybe I shouldn't assume that it's supported - unfortunately there seem to be articles going around that are linking to your tool saying that it will install "any JDK version" which is how I came across it https://www.linuxuprising.com/2019/02/install-any-oracle-java-jdk-version-in.html

update-alternatives doesn't work with JDK15

Hi ! It seems like update-alternatives no longer work. I'm trying to install Oracle JDK15. Here my output

xxx@zzz:~/Downloads$ sudo ./install-java.sh -f jdk-15.0.2_linux-x64_bin.tar.gz 
[sudo] password for expert: 
Installing: jdk-15.0.2_linux-x64_bin.tar.gz
Extracting jdk-15.0.2_linux-x64_bin.tar.gz to /usr/lib/jvm
JDK is extracted to /usr/lib/jvm/jdk-15.0.2
Run update-alternatives commands? [y/N] y
Running update-alternatives...
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-15.0.2/bin/java 10000 --slave /usr/bin/jaotc jaotc /usr/lib/jvm/jdk-15.0.2/bin/jaotc --slave /usr/bin/jar jar /usr/lib/jvm/jdk-15.0.2/bin/jar --slave /usr/bin/jarsigner jarsigner /usr/lib/jvm/jdk-15.0.2/bin/jarsigner --slave /usr/bin/javac javac /usr/lib/jvm/jdk-15.0.2/bin/javac --slave /usr/bin/javadoc javadoc /usr/lib/jvm/jdk-15.0.2/bin/javadoc --slave /usr/bin/javap javap /usr/lib/jvm/jdk-15.0.2/bin/javap --slave /usr/bin/jcmd jcmd /usr/lib/jvm/jdk-15.0.2/bin/jcmd --slave /usr/bin/jconsole jconsole /usr/lib/jvm/jdk-15.0.2/bin/jconsole --slave /usr/bin/jdb jdb /usr/lib/jvm/jdk-15.0.2/bin/jdb --slave /usr/bin/jdeprscan jdeprscan /usr/lib/jvm/jdk-15.0.2/bin/jdeprscan --slave /usr/bin/jdeps jdeps /usr/lib/jvm/jdk-15.0.2/bin/jdeps --slave /usr/bin/jfr jfr /usr/lib/jvm/jdk-15.0.2/bin/jfr --slave /usr/bin/jhsdb jhsdb /usr/lib/jvm/jdk-15.0.2/bin/jhsdb --slave /usr/bin/jimage jimage /usr/lib/jvm/jdk-15.0.2/bin/jimage --slave /usr/bin/jinfo jinfo /usr/lib/jvm/jdk-15.0.2/bin/jinfo --slave /usr/bin/jlink jlink /usr/lib/jvm/jdk-15.0.2/bin/jlink --slave /usr/bin/jmap jmap /usr/lib/jvm/jdk-15.0.2/bin/jmap --slave /usr/bin/jmod jmod /usr/lib/jvm/jdk-15.0.2/bin/jmod --slave /usr/bin/jpackage jpackage /usr/lib/jvm/jdk-15.0.2/bin/jpackage --slave /usr/bin/jps jps /usr/lib/jvm/jdk-15.0.2/bin/jps --slave /usr/bin/jrunscript jrunscript /usr/lib/jvm/jdk-15.0.2/bin/jrunscript --slave /usr/bin/jshell jshell /usr/lib/jvm/jdk-15.0.2/bin/jshell --slave /usr/bin/jstack jstack /usr/lib/jvm/jdk-15.0.2/bin/jstack --slave /usr/bin/jstat jstat /usr/lib/jvm/jdk-15.0.2/bin/jstat --slave /usr/bin/jstatd jstatd /usr/lib/jvm/jdk-15.0.2/bin/jstatd --slave /usr/bin/keytool keytool /usr/lib/jvm/jdk-15.0.2/bin/keytool --slave /usr/bin/rmid rmid /usr/lib/jvm/jdk-15.0.2/bin/rmid --slave /usr/bin/rmiregistry rmiregistry /usr/lib/jvm/jdk-15.0.2/bin/rmiregistry --slave /usr/bin/serialver serialver /usr/lib/jvm/jdk-15.0.2/bin/serialver
update-alternatives: error: alternative jaotc can't be slave of java: it is a master alternative
update-alternatives: error: alternative /usr/lib/jvm/jdk-15.0.2/bin/java for java not registered; not setting
Do you want to set JAVA_HOME environment variable in /home/expert/.bashrc? [y/N] y

Error creating symbolic link

install-java.sh:152

sudo update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "$extracted_dirname/jre/lib/amd64/libnpjp2.so" 1

This command gave me following error on Ubuntu 16.04 64-bit:

update-alternatives: error: error creating symbolic link '/usr/lib/mozilla/plugins/libjavaplugin.so.dpkg-tmp': No such file or directory

Possible fix that worked for me is replacing /usr/lib/mozilla/plugins/libjavaplugin.so.dpkg-tmp to /usr/lib/firefox-addons/plugins/libjavaplugin.so.dpkg-tmp.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.