赞
踩
第二天:
卸载之前的jdk,装jdk22版本以及更高版本
卸载方式:(之前下载的jdk1.8.0-161在/etc/profile中已有修改环境变量的命令,卸载时无需修改环境变量)
1.找出之前下载的jdk版本:
[root@one01 ~]# rpm -qa | grep -i java
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2018c-1.el7.noarch
2.查看之前下载的版本号(目前用的jdk1.8.0_161版本)
[root@one01 ~]# java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
3.卸载之前的版本(版本号为上面所查询到的已有的)
[root@one01 ~]# yum -y remove java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
[root@one01 ~]# java -version //卸载完后查看,没有了
-bash: /usr/bin/java: 没有那个文件或目录
4.去官网(Java Downloads | Oracle 中国)上查看自己需要的jdk安装文件,此处我选用的是https://download.oracle.com/java/22/latest/jdk-22_linux-x64_bin.tar.gz
[root@one01 ~]# ls
anaconda-ks.cfg jdk-22_linux-x64_bin.tar.gz
5.解压
[root@one01 ~]# tar -zxvf jdk-22_linux-x64_bin.tar.gz
[root@one01 ~]# ls
anaconda-ks.cfg jdk-22.0.1 jdk-22_linux-x64_bin.tar.gz
6.移动jdk文件并查询其路径
[root@one01 ~]# mv jdk-22.0.1/ /usr/local/
[root@one01 ~]# cd /usr/local/
[root@one01 local]# ls
apache-tomcat-10.1.25 bin games jdk-22.0.1 lib64 sbin src
apache-tomcat-9.0.91 etc include lib libexec share
[root@one01 local]# cd /usr/local/jdk-22.0.1/
[root@one01 jdk-22.0.1]# cd bin/
[root@one01 bin]# pwd
/usr/local/jdk-22.0.1/bin
7.修改环境变量
[root@one01 bin]# vim /etc/profile
export PATH=/usr/local/jdk-22.0.1/bin:$PATH //末尾添加暴露路径
8.刷新并查看
[root@one01 bin]# source /etc/profile
[root@one01 bin]# java -version
java version "22.0.1" 2024-04-16
Java(TM) SE Runtime Environment (build 22.0.1+8-16)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing)
------------------------------,----------------------------
关闭防火墙systemctl stop firewalld
开启防火墙systemctl start firewalld
开机自启防火墙systemctl enable firewalld
重新启动tomcat与maven
[root@one01 bin]# cd /usr/local/apache-tomcat-9.0.91/
[root@one01 apache-tomcat-9.0.91]# ./bin/startup.sh //启动tomcat
Using CATALINA_BASE: /usr/local/apache-tomcat-9.0.91
Using CATALINA_HOME: /usr/local/apache-tomcat-9.0.91
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.91/temp
Using JRE_HOME: /usr/local/jdk-22.0.1
Using CLASSPATH: /usr/local/apache-tomcat-9.0.91/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.91/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@one01 apache-tomcat-9.0.91]# cd /opt apache-maven-3.9.8/bin/
[root@one01 bin]# mvn -v //启动maven
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /opt/apache-maven-3.9.8
Java version: 22.0.1, vendor: Oracle Corporation, runtime: /usr/local/jdk-22.0.1
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"
---------------------,-------------------
第二天下午:
export PATH=/usr/local/maven3/bin/:/usr/local/jdk17/bin/:$PATH
export JAVA_HOME=/usr/local/jdk17/ //红色部分:jdk路径jdk-22.0.1
[root@one01 bin]# vim /etc/profile
export PATH=/usr/local/maven3/bin/:/usr/local/jdk-22.0.1/bin/:$PATH
export JAVA_HOME=/usr/local/ jdk-22.0.1/ //红色部分:jdk路径jdk-22.0.1
[root@one01 bin]# source /etc/profile
[root@one01 bin]# $JAVA_HOME
-bash: /usr/local/jdk-22.0.1/: 是一个目录
查看哪有这个:
[root@one01 bin]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
[root@one01 bin]# python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("xnjnnc")
xnjnnc
>>> print(2+3)
5
>>> //quit或者ctrl+z退出
下载python3试试,官网tar包连接:Python Source Releases | Python.org
python2
with open(“a.txt”,”wb”)as f:
f.write(“write”)
------,----------,--------
[root@one01 bin]# yum list|grep python3
[root@one01 bin]# python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> with open("b.txt","wb") as f:
... f.write("我,秦始皇,打钱")
>>> import os
>>> os.listdir("./")
['jar', 'jarsigner', 'java', 'javac', 'javadoc', 'javap', 'jcmd', 'jconsole', 'jdb', 'jdeprscan', 'jdeps', 'jfr', 'jhsdb', 'jimage', 'jinfo', 'jlink', 'jmap', 'jmod', 'jpackage', 'jps', 'jrunscript', 'jshell', 'jstack', 'jstat', 'jstatd', 'jwebserver', 'keytool', 'rmiregistry', 'serialver']
>>>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。