Linux中卸载自带JDK
首先先检查Linux是否有自带的JDK
[root@localhost ~]# java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
显示的是OpenJDK 说明是系统自带的,我们要删除,不然有些东西使用不了!!!
- rpm -qa | grep jdk查看jdk的具体信息
[root@localhost ~]# rpm -qa | grep jdk
java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
copy-jdk-configs-3.3-10.el7_5.noarch
java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
- rpm -e --nodeps java-1.8.0-openjdk挨个给他删了
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk
[root@localhost ~]# rpm -qa | grep jdk
java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
copy-jdk-configs-3.3-10.el7_5.noarch
java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-headless
[root@localhost ~]# rpm -qa | grep jdk
copy-jdk-configs-3.3-10.el7_5.noarch
java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-headless
[root@localhost ~]# rpm -qa | grep jdk
copy-jdk-configs-3.3-10.el7_5.noarch
[root@localhost ~]# rpm -e --nodeps copy-jdk-configs
[root@localhost ~]# rpm -qa | grep jdk
[root@localhost ~]#
Linux中官网下载JDK
然后去官网下载Linux对应版本的JDK
网址:官网下载JDK
应该让你登录一下,登完之后就可以下载了
Linux中安装新的JDK
打开Xshell链接好Linux,再打开Xftp
不会的看这个---->
Xshell的下载、安装、链接
Xftp的下载、安装、使用
下面就开始解压压缩包
先切换到有JDK的文件夹再用tar -zxvf jdk-8u281-linux-i586.tar.gz解压(这里的jdk-8u281-linux-i586.tar.gz是我的JDK)
[root@localhost local]# cd /usr/local/java
[root@localhost java]# tar -zxvf jdk-8u281-linux-i586.tar.gz
给JDK单独弄个文件
[root@localhost java]# cp -r jdk1.8.0_281/ /usr/local/jdk
[root@localhost java]# cd ..
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 3 root root 61 Jan 21 15:46 java
drwxr-xr-x. 8 root root 273 Jan 21 15:54 jdk
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Jan 17 16:38 share
drwxr-xr-x. 2 root root 6 Apr 11 2018 src
[root@localhost local]#
Linux配置JDK环境
首先输入vim /etc/profile,进入之后按 i进行修改
[root@localhost local]# vim /etc/profile
把export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL注释掉(用#注释)加入下面两行命令(注意jdk是我自己放JDK的目录)
#export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
按ESC然后按**:wq保存退出
然后解析文件,不解析,必须通过重启才能生效。只要解析不需要重启了
再输入source /etc/profile**命令
[root@localhost local]# source /etc/profile
检查是否配置好环境变量java -version
[root@localhost local]# java -version
-bash: /usr/local/jdk/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
我的出现这个,没配好,没关系,百度一下
然后看见这个–>-bash: /usr/local/jdk1.7.0_71/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or dir
然后我就按照他的步骤弄了一下
[root@localhost local]# sudo yum install glibc.i686
一路选择----> y,好了之后,用java -version、java、javac命令试了试
[root@localhost local]# java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) Client VM (build 25.281-b09, mixed mode)
[root@localhost local]# java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-client to select the "client" VM
-server to select the "server" VM
-minimal to select the "minimal" VM
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
Warning: this feature is deprecated and will be removed
in a future release.
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
Warning: this feature is deprecated and will be removed
in a future release.
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
[root@localhost local]# javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-h <directory> Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-profile <profile> Check that API used is available in the specified profile
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-Werror Terminate compilation if warnings occur
@<filename> Read options and filenames from file
出来这个就没问题了,OK!!!
完结