Linux(CentOS) Java 安装

来源:互联网 发布:淘宝直跳弹簧刀 编辑:程序博客网 时间:2024/05/16 00:30

Installation of the 64-bit JDK on RPM-based Linux Platforms

This procedure installs the Java Development Kit (JDK) for 64-bit RPM-based Linux platforms, such as Red Hat and SuSE, using an RPM binary file (.rpm) in the system location. You must be root to perform this installation.

These instructions use the following file:

jdk-8uversion-linux-x64.rpm

Download the file.

注:我把它下载下来放在:/usr 目录下

Become root by running su and entering the super-user password.
Uninstall any earlier installations of the JDK packages.

rpm -e package_name

Install the package.

rpm -ivh jdk-8uversion-linux-x64.rpm

To upgrade a package:

rpm -Uvh jdk-8uversion-linux-x64.rpm

Delete the .rpm file if you want to save disk space.
Exit the root shell. No need to reboot.
Check the default (recently installed) JDK version.

java -version

Check which specific RPM package provides the java files:

rpm -q –whatprovides java

配置 jdk 环境变量

1 找到 jdk 目录:

[root@h3cesb-data-01 ~]# whereis javajava: /usr/bin/java /usr/java/jdk1.8.0_144/bin/java /usr/share/man/man1/java.1所以是:/usr/java/jdk1.8.0_144

2 修改.bash_profile文件:
用文本编辑器打开用户目录下的.bash_profile文件
在.bash_profile文件末尾加入:

export JAVA_HOME=/usr/java/jdk1.8.0_144 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar 

3 重启 shell 并检查:

[root@h3cesb-data-01 ~]# echo $JAVA_HOME/usr/java/jdk1.8.0_144[root@h3cesb-data-01 ~]# echo $PATH/usr/java/jdk1.8.0_144/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin[root@h3cesb-data-01 ~]# echo $CLASSPATH.:/usr/java/jdk1.8.0_144/lib/dt.jar:/usr/java/jdk1.8.0_144/lib/tools.jar

4 或者写个类测试下:
用文本编辑器新建一个Test.java文件,在其中输入以下代码并保存:

public class test {     public static void main(String args[]) {         System.out.println("A new jdk test !");     } } 

编译:在shell终端执行命令 javac Test.java
运行:在shell终端执行命令 java Test
当shell下出现“A new jdk test !”字样则jdk运行正常。

原创粉丝点击