Install Openjdk11 to Ubuntu 18.04 LTS

  Ubuntu 18.04 LTS系统上通过sudo apt install openjdk-11-*命令安装的jdk11版本依然是jdk10,怎么样才能安装openjdk 11呢,今天,我们就来完成这一工作。

download software package

lwk@qwfys:~$sudo curl -sL https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz -o /usr/lib/jvm/openjdk-11.0.1_linux-x64_bin.tar.gz

unzip package

lwk@qwfys:~$cd /usr/lib/jvm/
lwk@qwfys:/usr/lib/jvm$
lwk@qwfys:/usr/lib/jvm$sudo tar -zxvf openjdk-11.0.1_linux-x64_bin.tar.gz
lwk@qwfys:/usr/lib/jvm$ ll
total 32
drwxr-xr-x   5 root root  4096 Jan  4 02:27 ./
drwxr-xr-x 153 root root 12288 Dec 27 02:17 ../
lrwxrwxrwx   1 root root    20 Nov 20 09:07 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64/
-rw-r--r--   1 root root  2600 Nov 20 09:07 .java-1.8.0-openjdk-amd64.jinfo
drwxr-xr-x   8 root root  4096 Jan  4 01:42 java-8-openjdk-amd64/
drwxr-xr-x   8 root root  4096 Jan  4 02:04 jdk-11.0.1/
drwxr-xr-x   2 root root  4096 Jan  4 01:42 openjdk-8/
lwk@qwfys:/usr/lib/jvm$

config

update-alternatives install

lwk@qwfys:/usr/lib/jvm$ cd jdk-11.0.1/bin/
lwk@qwfys:/usr/lib/jvm/jdk-11.0.1/bin$ ll
total 516
drwxr-xr-x 2 root root   4096 Jan  4 02:04 ./
drwxr-xr-x 8 root root   4096 Jan  4 02:04 ../
-rwxr-xr-x 1  668  668  12952 Oct  6 20:17 jaotc*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jar*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jarsigner*
-rwxr-xr-x 1  668  668   8672 Oct  6 20:17 java*
-rwxr-xr-x 1  668  668   8784 Oct  6 20:17 javac*
-rwxr-xr-x 1  668  668   8784 Oct  6 20:17 javadoc*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 javap*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jcmd*
-rwxr-xr-x 1  668  668  12888 Oct  6 20:17 jconsole*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jdb*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jdeprscan*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jdeps*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jhsdb*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jimage*
-rwxr-xr-x 1  668  668  12880 Oct  6 20:17 jinfo*
-rwxr-xr-x 1  668  668   8784 Oct  6 20:17 jjs*
-rwxr-xr-x 1  668  668   8784 Oct  6 20:17 jlink*
-rwxr-xr-x 1  668  668  12880 Oct  6 20:17 jmap*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jmod*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jps*
-rwxr-xr-x 1  668  668   8792 Oct  6 20:17 jrunscript*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jshell*
-rwxr-xr-x 1  668  668  12880 Oct  6 20:17 jstack*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jstat*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jstatd*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 keytool*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 pack200*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 rmic*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 rmid*
-rwxr-xr-x 1  668  668   8744 Oct  6 20:17 rmiregistry*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 serialver*
-rwxr-xr-x 1  668  668 117656 Oct  6 20:17 unpack200*
lwk@qwfys:/usr/lib/jvm/jdk-11.0.1/bin$sudo sh -c 'for bin in /usr/lib/jvm/jdk-11.0.1/bin/*; do update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 100; done' 
lwk@qwfys:/usr/lib/jvm/jdk-11.0.1/bin$sudo sh -c 'for bin in /usr/lib/jvm/jdk-11.0.1/bin/*; do update-alternatives --set $(basename $bin) $bin; done'
lwk@qwfys:/usr/lib/jvm/jdk-11.0.1/bin$

set JAVA_HOME

lwk@qwfys:/usr/lib/jvm/jdk-11.0.1/bin$ cd /etc/profile.d/
lwk@qwfys:/etc/profile.d$ vim jdk.sh 
lwk@qwfys:/etc/profile.d$ cat jdk.sh 
export J2SDKDIR=/usr/lib/jvm/jdk-11.0.1
export J2REDIR=/usr/lib/jvm/jdk-11.0.1
#export PATH=$PATH:/usr/lib/jvm/jdk-11.0.1/bin
export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1
lwk@qwfys:/etc/profile.d$ 

view

lwk@qwfys:~$ java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
lwk@qwfys:~$ javac -version
javac 11.0.1
lwk@qwfys:~$ 

  至此安装完成。

uninstall

remove ‘JAVA_HOME’

lwk@qwfys:~$ sudo rm /etc/profile.d/jdk.sh
lwk@qwfys:~$ 

update-alternatives uninstall

lwk@qwfys:~$ cd /usr/lib/jvm/jdk-11.0.1/bin/
lwk@qwfys:/usr/lib/jvm/jdk-11.0.1/bin$ ll
total 516
drwxr-xr-x 2 root root   4096 Jan  4 02:04 ./
drwxr-xr-x 8 root root   4096 Jan  4 02:04 ../
-rwxr-xr-x 1  668  668  12952 Oct  6 20:17 jaotc*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jar*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jarsigner*
-rwxr-xr-x 1  668  668   8672 Oct  6 20:17 java*
-rwxr-xr-x 1  668  668   8784 Oct  6 20:17 javac*
-rwxr-xr-x 1  668  668   8784 Oct  6 20:17 javadoc*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 javap*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jcmd*
-rwxr-xr-x 1  668  668  12888 Oct  6 20:17 jconsole*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jdb*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jdeprscan*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jdeps*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jhsdb*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jimage*
-rwxr-xr-x 1  668  668  12880 Oct  6 20:17 jinfo*
-rwxr-xr-x 1  668  668   8784 Oct  6 20:17 jjs*
-rwxr-xr-x 1  668  668   8784 Oct  6 20:17 jlink*
-rwxr-xr-x 1  668  668  12880 Oct  6 20:17 jmap*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jmod*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jps*
-rwxr-xr-x 1  668  668   8792 Oct  6 20:17 jrunscript*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jshell*
-rwxr-xr-x 1  668  668  12880 Oct  6 20:17 jstack*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jstat*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 jstatd*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 keytool*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 pack200*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 rmic*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 rmid*
-rwxr-xr-x 1  668  668   8744 Oct  6 20:17 rmiregistry*
-rwxr-xr-x 1  668  668   8736 Oct  6 20:17 serialver*
-rwxr-xr-x 1  668  668 117656 Oct  6 20:17 unpack200*
lwk@qwfys:/usr/lib/jvm/jdk-11.0.1/bin$ sudo sh -c 'for bin in /usr/lib/jvm/jdk-11.0.1/bin/*; do update-alternatives --remove $(basename $bin) $bin; done'
update-alternatives: removing manually selected alternative - switching jaotc to auto mode
update-alternatives: removing manually selected alternative - switching jar to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jar to provide /usr/bin/jar (jar) in auto mode
update-alternatives: removing manually selected alternative - switching jarsigner to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jarsigner to provide /usr/bin/jarsigner (jarsigner) in auto mode
update-alternatives: removing manually selected alternative - switching java to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in auto mode
update-alternatives: removing manually selected alternative - switching javac to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in auto mode
update-alternatives: removing manually selected alternative - switching javadoc to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/javadoc to provide /usr/bin/javadoc (javadoc) in auto mode
update-alternatives: removing manually selected alternative - switching javap to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/javap to provide /usr/bin/javap (javap) in auto mode
update-alternatives: removing manually selected alternative - switching jcmd to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jcmd to provide /usr/bin/jcmd (jcmd) in auto mode
update-alternatives: removing manually selected alternative - switching jconsole to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jconsole to provide /usr/bin/jconsole (jconsole) in auto mode
update-alternatives: removing manually selected alternative - switching jdb to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jdb to provide /usr/bin/jdb (jdb) in auto mode
update-alternatives: removing manually selected alternative - switching jdeprscan to auto mode
update-alternatives: removing manually selected alternative - switching jdeps to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jdeps to provide /usr/bin/jdeps (jdeps) in auto mode
update-alternatives: removing manually selected alternative - switching jhsdb to auto mode
update-alternatives: removing manually selected alternative - switching jimage to auto mode
update-alternatives: removing manually selected alternative - switching jinfo to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jinfo to provide /usr/bin/jinfo (jinfo) in auto mode
update-alternatives: removing manually selected alternative - switching jjs to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/jjs to provide /usr/bin/jjs (jjs) in auto mode
update-alternatives: removing manually selected alternative - switching jlink to auto mode
update-alternatives: removing manually selected alternative - switching jmap to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jmap to provide /usr/bin/jmap (jmap) in auto mode
update-alternatives: removing manually selected alternative - switching jmod to auto mode
update-alternatives: removing manually selected alternative - switching jps to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jps to provide /usr/bin/jps (jps) in auto mode
update-alternatives: removing manually selected alternative - switching jrunscript to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jrunscript to provide /usr/bin/jrunscript (jrunscript) in auto mode
update-alternatives: removing manually selected alternative - switching jshell to auto mode
update-alternatives: removing manually selected alternative - switching jstack to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jstack to provide /usr/bin/jstack (jstack) in auto mode
update-alternatives: removing manually selected alternative - switching jstat to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jstat to provide /usr/bin/jstat (jstat) in auto mode
update-alternatives: removing manually selected alternative - switching jstatd to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jstatd to provide /usr/bin/jstatd (jstatd) in auto mode
update-alternatives: removing manually selected alternative - switching keytool to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/keytool to provide /usr/bin/keytool (keytool) in auto mode
update-alternatives: removing manually selected alternative - switching pack200 to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/pack200 to provide /usr/bin/pack200 (pack200) in auto mode
update-alternatives: removing manually selected alternative - switching rmic to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/rmic to provide /usr/bin/rmic (rmic) in auto mode
update-alternatives: removing manually selected alternative - switching rmid to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/rmid to provide /usr/bin/rmid (rmid) in auto mode
update-alternatives: removing manually selected alternative - switching rmiregistry to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/rmiregistry to provide /usr/bin/rmiregistry (rmiregistry) in auto mode
update-alternatives: removing manually selected alternative - switching serialver to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/serialver to provide /usr/bin/serialver (serialver) in auto mode
update-alternatives: removing manually selected alternative - switching unpack200 to auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/unpack200 to provide /usr/bin/unpack200 (unpack200) in auto mode
lwk@qwfys:/usr/lib/jvm/jdk-11.0.1/bin$

remove the java installation directory

lwk@qwfys:/usr/lib/jvm/jdk-11.0.1/bin$ cd ../../
lwk@qwfys:/usr/lib/jvm$ ll
total 32
drwxr-xr-x   5 root root  4096 Jan  4 02:27 ./
drwxr-xr-x 153 root root 12288 Dec 27 02:17 ../
lrwxrwxrwx   1 root root    20 Nov 20 09:07 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64/
-rw-r--r--   1 root root  2600 Nov 20 09:07 .java-1.8.0-openjdk-amd64.jinfo
drwxr-xr-x   8 root root  4096 Jan  4 01:42 java-8-openjdk-amd64/
drwxr-xr-x   8 root root  4096 Jan  4 02:04 jdk-11.0.1/
drwxr-xr-x   2 root root  4096 Jan  4 01:42 openjdk-8/
lwk@qwfys:/usr/lib/jvm$ sudo rm -rf jdk-11.0.1/
lwk@qwfys:/usr/lib/jvm$ ll
total 28
drwxr-xr-x   4 root root  4096 Jan  4 03:38 ./
drwxr-xr-x 153 root root 12288 Dec 27 02:17 ../
lrwxrwxrwx   1 root root    20 Nov 20 09:07 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64/
-rw-r--r--   1 root root  2600 Nov 20 09:07 .java-1.8.0-openjdk-amd64.jinfo
drwxr-xr-x   8 root root  4096 Jan  4 01:42 java-8-openjdk-amd64/
drwxr-xr-x   2 root root  4096 Jan  4 01:42 openjdk-8/
lwk@qwfys:/usr/lib/jvm$ 

view

lwk@qwfys:~$ java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-0ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
lwk@qwfys:~$ javac -version
javac 1.8.0_191
lwk@qwfys:~$ 

  至此卸载完成。

你可能感兴趣的:(Linux)