Friday, December 28, 2018

To install / remove JDK on SuSE Linux

1. On new installation Java rpms not exists on SuSE Linux. To verify run below command:
# rpm -qa | grep java
libjavascriptcoregtk-4_0-18-2.12.5-1.12.x86_64


2. Check openjdk package in repository:
# zypper se openjdk-
Loading repository data...
Reading installed packages...

S | Name                        | Summary                                             | Type
--+-----------------------------+-----------------------------------------------------+--------
  | java-1_7_0-openjdk-demo     | OpenJDK 7 Demos                                     | package
  | java-1_7_0-openjdk-devel    | SUSE's implementation of the OpenJDK 7 Developmen-> | package
  | java-1_7_0-openjdk-headless | OpenJDK 7 runtime environment without X, audio an-> | package
  | java-1_8_0-openjdk-demo     | OpenJDK 8 Demos                                     | package
  | java-1_8_0-openjdk-devel    | OpenJDK 8 Development Environment                   | package
  | java-1_8_0-openjdk-headless | OpenJDK 8 Runtime Environment                       | package


3. Check openjdk package with version:
# zypper se -s openjdk-
Loading repository data...
Reading installed packages...

S | Name                        | Type    | Version        | Arch   | Repository
--+-----------------------------+---------+----------------+--------+------------------
  | java-1_7_0-openjdk-demo     | package | 1.7.0.141-42.1 | x86_64 | SLES12-SP3-12.3-0
  | java-1_7_0-openjdk-devel    | package | 1.7.0.141-42.1 | x86_64 | SLES12-SP3-12.3-0
  | java-1_7_0-openjdk-headless | package | 1.7.0.141-42.1 | x86_64 | SLES12-SP3-12.3-0
  | java-1_8_0-openjdk-demo     | package | 1.8.0.131-26.3 | x86_64 | SLES12-SP3-12.3-0
  | java-1_8_0-openjdk-devel    | package | 1.8.0.131-26.3 | x86_64 | SLES12-SP3-12.3-0
  | java-1_8_0-openjdk-headless | package | 1.8.0.131-26.3 | x86_64 | SLES12-SP3-12.3-0


4. Check Java Package information:
# zypper info java-1_8_0-openjdk-devel
Loading repository data...
Reading installed packages...

Information for package java-1_8_0-openjdk-devel:
-------------------------------------------------
Repository     : SLES12-SP3-12.3-0
Name           : java-1_8_0-openjdk-devel
Version        : 1.8.0.131-26.3
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Support Level  : Level 2
Installed Size : 21.4 MiB
Installed      : No
Status         : not installed
Source package : java-1_8_0-openjdk-1.8.0.131-26.3.src
Summary        : OpenJDK 8 Development Environment
Description    :
    The OpenJDK 8 development tools.


5. Check below folders:
# ls /usr/lib64/java
ls: cannot access '/usr/lib64/java': No such file or directory

# ls /usr/lib64/jvm
ls: cannot access '/usr/lib64/jvm': No such file or directory


6. Check environment Setting:
# env | grep -i java
#


7. Now install openjdk rpms by "zypper" command:
# zypper in java-1_8_0-openjdk-devel
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 5 NEW packages are going to be installed:
  java-1_8_0-openjdk java-1_8_0-openjdk-devel java-1_8_0-openjdk-headless javapackages-tools
  libgif6

5  new packages to install.
Overall download size: 65.9 MiB. Already cached: 0 B. After the operation, additional 105.9 MiB
will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package javapackages-tools-2.0.1-6.10.x86_64   (1/5),  50.8 KiB (129.9 KiB unpacked)
Retrieving package libgif6-5.0.5-12.1.x86_64              (2/5),  21.0 KiB ( 35.4 KiB unpacked)
Retrieving package java-1_8_0-openjdk-headless-1.8.0.131-26.3.x86_64
                                                          (3/5),  48.7 MiB ( 83.8 MiB unpacked)
Retrieving package java-1_8_0-openjdk-1.8.0.131-26.3.x86_64
                                                          (4/5), 289.2 KiB (565.7 KiB unpacked)
Retrieving package java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64
                                                          (5/5),  16.8 MiB ( 21.4 MiB unpacked)
Checking for file conflicts: ............................................................[done]
(1/5) Installing: javapackages-tools-2.0.1-6.10.x86_64 ..................................[done]
(2/5) Installing: libgif6-5.0.5-12.1.x86_64 .............................................[done]
(3/5) Installing: java-1_8_0-openjdk-headless-1.8.0.131-26.3.x86_64 .....................[done]
Additional rpm output:
update-alternatives: using /usr/lib64/jvm/jre-1.8.0-openjdk/bin/java to provide /usr/bin/java (java) in auto mode
update-alternatives: using /usr/lib64/jvm/jre-1.8.0-openjdk to provide /usr/lib64/jvm/jre-openjdk (jre_openjdk) in auto mode
update-alternatives: using /usr/lib64/jvm/jre-1.8.0-openjdk to provide /usr/lib64/jvm/jre-1.8.0 (jre_1.8.0) in auto mode


(4/5) Installing: java-1_8_0-openjdk-1.8.0.131-26.3.x86_64 ..............................[done]
(5/5) Installing: java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64 ........................[done]
Additional rpm output:
update-alternatives: using /usr/lib64/jvm/java-1.8.0-openjdk/bin/javac to provide /usr/bin/javac (javac) in auto mode
update-alternatives: using /usr/lib64/jvm/java-1.8.0-openjdk to provide /usr/lib64/jvm/java-openjdk (java_sdk_openjdk) in auto mode
update-alternatives: using /usr/lib64/jvm/java-1.8.0-openjdk to provide /usr/lib64/jvm/java-1.8.0 (java_sdk_1.8.0) in auto mode


8. Now Java rpms exists:
# rpm -qa | grep -i java
java-1_8_0-openjdk-headless-1.8.0.131-26.3.x86_64
typelib-1_0-JavaScriptCore-4_0-2.12.5-1.12.x86_64
java-1_8_0-openjdk-1.8.0.131-26.3.x86_64
javapackages-tools-2.0.1-6.10.x86_64
libjavascriptcoregtk-4_0-18-2.12.5-1.12.x86_64
java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64


9. Have not set Java environment, /usr/lib64/java folder has created, /usr/lib64/jvm created and have no. of link files and folders:

# env | grep -i java

# ls -l /usr/lib64/java
total 0

# ls -l /usr/lib64/jvm
total 4
lrwxrwxrwx 1 root root   26 Oct 29 17:21 java -> /etc/alternatives/java_sdk
lrwxrwxrwx 1 root root   32 Oct 29 17:21 java-1.8.0 -> /etc/alternatives/java_sdk_1.8.0
lrwxrwxrwx 1 root root   24 Oct 29 17:21 java-1.8.0-openjdk -> java-1.8.0-openjdk-1.8.0
drwxr-xr-x 7 root root 4096 Oct 29 17:21 java-1.8.0-openjdk-1.8.0
lrwxrwxrwx 1 root root   34 Oct 29 17:21 java-openjdk -> /etc/alternatives/java_sdk_openjdk
lrwxrwxrwx 1 root root   21 Oct 29 17:21 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root   27 Oct 29 17:21 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root   28 Oct 29 17:21 jre-1.8.0-openjdk -> java-1.8.0-openjdk-1.8.0/jre
lrwxrwxrwx 1 root root   29 Oct 29 17:21 jre-openjdk -> /etc/alternatives/jre_openjdk


10. Now all java command is coming:
# java    (Press Tab to check)
java     javac    javadoc  javah    javap


11. Now if need to remove openjdk rpms, follow below steps:

# rpm -qa | grep java-1_8_0-openjdk-devel
java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64

# rpm -ev java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64
Preparing packages...
java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64
update-alternatives: warning: alternative /usr/lib64/jvm/java-1.8.0-openjdk/bin/javac (part of link group javac) doesn't exist; removing from list of alternatives
update-alternatives: warning: /etc/alternatives/javac is dangling; it will be updated with best choice
update-alternatives: warning: alternative /usr/lib64/jvm/java-1.8.0-openjdk (part of link group java_sdk_openjdk) doesn't exist; removing from list of alternatives
update-alternatives: warning: /etc/alternatives/java_sdk_openjdk is dangling; it will be updated with best choice
update-alternatives: warning: alternative /usr/lib64/jvm/java-1.8.0-openjdk (part of link group java_sdk_1.8.0) doesn't exist; removing from list of alternatives
update-alternatives: warning: /etc/alternatives/java_sdk_1.8.0 is dangling; it will be updated with best choice

# rpm -qa | grep java-1_8_0-openjdk-devel
#

12. After removing now  list of link file is less as compared to above:
# ls -l /usr/lib64/jvm
total 4
drwxr-xr-x 3 root root 4096 Oct 29 17:25 java-1.8.0-openjdk-1.8.0
lrwxrwxrwx 1 root root   21 Oct 29 17:21 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root   27 Oct 29 17:21 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root   28 Oct 29 17:21 jre-1.8.0-openjdk -> java-1.8.0-openjdk-1.8.0/jre
lrwxrwxrwx 1 root root   29 Oct 29 17:21 jre-openjdk -> /etc/alternatives/jre_openjdk


13. Now other java command is not exist like above:
# java (Press tab key)
.cache.      .config.     .dbus.       .gnupg.      .targetcli.  bin.         inst-sys.


14. After installing openjdk again all folders, files and symbolic link come:

# zypper se java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64
Loading repository data...
Reading installed packages...

S | Name                     | Type    | Version        | Arch   | Repository
--+--------------------------+---------+----------------+--------+------------------
  | java-1_8_0-openjdk-devel | package | 1.8.0.131-26.3 | x86_64 | SLES12-SP3-12.3-0

# zypper in java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
  java-1_8_0-openjdk-devel

1 new package to install.
Overall download size: 16.8 MiB. Already cached: 0 B. After the operation, additional 21.4 MiB
will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64
                                                          (1/1),  16.8 MiB ( 21.4 MiB unpacked)
Checking for file conflicts: ............................................................[done]
(1/1) Installing: java-1_8_0-openjdk-devel-1.8.0.131-26.3.x86_64 ........................[done]
Additional rpm output:
update-alternatives: using /usr/lib64/jvm/java-1.8.0-openjdk/bin/javac to provide /usr/bin/javac (javac) in auto mode
update-alternatives: using /usr/lib64/jvm/java-1.8.0-openjdk to provide /usr/lib64/jvm/java-openjdk (java_sdk_openjdk) in auto mode
update-alternatives: using /usr/lib64/jvm/java-1.8.0-openjdk to provide /usr/lib64/jvm/java-1.8.0 (java_sdk_1.8.0) in auto mode


15. Now all java command is available:
# java (Press tab key)
java     javac    javadoc  javah    javap


Note : After reboot the server all Java Environment automatically set by /etc/profile.d/alljava.sh:

# env | grep -i java
JRE_HOME=/usr/lib64/jvm/java/jre
JAVA_BINDIR=/usr/lib64/jvm/java/bin
JAVA_HOME=/usr/lib64/jvm/java
SDK_HOME=/usr/lib64/jvm/java
JDK_HOME=/usr/lib64/jvm/java
JAVA_ROOT=/usr/lib64/jvm/java



# cat /etc/profile.d/alljava.sh
#
#    /etc/profile.d/alljava.sh
#
# send feedback to http://bugs.opensuse.org

#
# This script sets some environment variables for default java.
# Affected variables: JAVA_BINDIR, JAVA_HOME, JRE_HOME,
#                     JDK_HOME, SDK_HOME
#

for JDIR in /usr/lib64/jvm /usr/lib/jvm /usr/java/latest /usr/java; do

    if ! test -d $JDIR; then
        continue
    fi

    for JPATH in $JDIR $JDIR/java `ls -I 'java' -I 'jre' -d $JDIR/* 2>/dev/null` $JDIR/jre; do

        if ! test -x $JPATH/bin/java; then
            continue
        fi

        export JAVA_BINDIR=$JPATH/bin
        export JAVA_ROOT=$JPATH
        export JAVA_HOME=$JPATH
        unset JDK_HOME
        unset SDK_HOME

        case "$JPATH" in
            *jre*)
                [ -z "$JRE_HOME" ] && export JRE_HOME=$JPATH
                ;;

            *)
                [ -z "$JRE_HOME" ] && export JRE_HOME=$JPATH/jre
                # it is development kit
                if [ -x $JPATH/bin/javac ] ; then
                    export JDK_HOME=$JPATH
                    export SDK_HOME=$JPATH
                    unset JPATH
                    break 2; # we found a JRE + SDK -- don't look any further
                fi
                ;;
        esac

    done
    unset JPATH

done
unset JDIR
#

No comments:

Post a Comment