安装包路径:
https://www.oracle.com/java/technologies/downloads/#java22
1、卸载之前的旧版本
[root@localhost ~]# yum remove *java* #卸载之前下载的Java
[root@localhost ~]# ls
anaconda-ks.cfg jdk-22_linux-x64_bin.tar.gz 软件包
apache-tomcat-10.1.25.tar.gz jdk-22_linux-x64_bin.tar.gz.0 正在检查事务
jdk-22.0.1 解决依赖关系完成
[root@localhost ~]# java
-bash: /bin/java: 没有那个文件或目录
[root@localhost ~]# javac
-bash: javac: 未找到命令
[root@localhost ~]# rm -rf jdk-22.0.1
[root@localhost ~]# cd /usr/local/
[root@localhost local]# rm -rf jdk-22.0.1 #删除解压的文件
[root@localhost local]# cd
2、下载安装包,并解压到/usr/local目录
[root@localhost ~]# ls
anaconda-ks.cfg jdk-22_linux-x64_bin.tar.gz 解决依赖关系完成 正在检查事务
apache-tomcat-10.1.25.tar.gz jdk-22_linux-x64_bin.tar.gz.0 软件包
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache-tomcat-10.1.25 bin etc games include lib lib64 libexec sbin share src
[root@localhost local]# cd
[root@localhost ~]# tar -zxvf jdk-22_linux-x64_bin.tar.gz -C /usr/local/ #将文件解压到/usr/local目录下
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache-tomcat-10.1.25 etc include lib libexec share
bin games jdk-22.0.1 lib64 sbin src
3、修改配置文件,激活修改后的配置文件
[root@localhost local]# vim /etc/profile #修改配置文件
[root@localhost local]# source /etc/profile #激活修改后的文件
配置文件内容:
4、验证
5、问题集锦
在配置文件里面的内容(export PATH=$JAVA_HOME/bin:$PATH),不加入":$PATH"
可以加入“export PATH=/bin:/usr/bin:$PATH”解决问题
6、运行包todolist.jar
[root@localhost ~]# cd /usr/local
[root@localhost local]# cd jdk-22.0.1
[root@localhost jdk-22.0.1]# cd bin/
[root@localhost bin]# ./java -jar /root/todolist.jar
验证:
7、部署python
[root@localhost 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@localhost bin]# python2
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("2+3=",5)
('2+3=', 5)
>>> quit()
[root@localhost bin]# yum list | grep python
[root@localhost 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@localhost bin]# yum list | grep python3
[root@localhost 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("a.txt","wb") as f:
... f.write("python是一个相对容易学习的脚本")
...
>>> 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', 'todolist.jar', 'a.txt']