Linux卸载、下载、安装JDK、配置环境变量

3 篇文章 0 订阅
1 篇文章 0 订阅

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 说明是系统自带的,我们要删除,不然有些东西使用不了!!!

  1. 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

  1. 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 -versionjavajavac命令试了试

[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!!!

完结

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Linux安装JDK配置环境变量的步骤如下: 1. 首先,你需要下载JDK。你可以从Oracle官方网站下载JDK下载链接是:https://www.oracle.com/java/technologies/javase-jdk8-downloads.html 。 2. 下载完成后,连接到你的Linux服务器,并使用命令`java -version`检查是否已经安装了其他版本的JDK。如果有其他版本的JDK,请先卸载它们。 3. 上传下载好的JDK安装包到Linux服务器上,可以使用工具如Xshell等。 4. 在Linux服务器中打开终端,进入到存放JDK安装包的目录。使用解压命令`tar -zxvf jdk-8u311-linux-x64.tar.gz`解压安装包,其中`jdk-8u311-linux-x64.tar.gz`是你下载JDK安装包的文件名。 5. 进入用户目录,使用vi编辑器打开配置文件`.bash_profile`,命令为`vi .bash_profile`。 6. 按下`i`键进入编辑模式,在配置文件中插入以下内容: ``` export JAVA_HOME=/tools/jdk1.8.0_311 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin ``` 其中,`/tools/jdk1.8.0_311`是你解压的JDK安装目录。 7. 保存文件并退出编辑模式,按下`Esc`键,然后输入`:wq`并按下`Enter`键。 8. 最后,刷新配置文件,使修改生效。输入以下命令:`source ~/.bash_profile` 9. 验证安装配置是否成功。输入命令`java -version`检查Java版本是否为JDK 1.8。 这样,你就成功在Linux安装JDK配置环境变量。现在你可以在Linux上开发和运行Java应用程序了。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Azure++

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值