Kali下JDK1.8的安装过程

  最近在Linux上运行java程序出现Unsupported major.minor version 51.0错误,后发现是编译后的java程序与Linux上的java Se版本不一致而产生的错误。提示的版本号与Java se对应表如下:

JavaSE 8 = 52 (0x34 hex),
JavaSE 7 = 51 (0x33 hex),
JavaSE 6 = 50 (0x32 hex),
JavaSE 5 = 49 (0x31 hex),
J2SE 1.4 = 48 (0x30 hex),
J2SE 1.3 = 47 (0x2F hex),
J2SE 1.2 = 46 (0x2E hex),
J2SE 1.1 = 45 (0x2D hex)

下面介绍一下Kali下JDK1.8的安装过程

1、下载jdk安装包

  点击下面的链接选择合适的JDK版本下载:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

2、建立目录,将下载的jdk复制过去并解压

sudo mkdir -p /usr/local/java
sudo cp jdk-8u161-linux-x64.tar.gz /usr/local/java
cd /usr/local/java
sudo tar xzvf jdk-8u91-linux-x64.tar.gz

3、配置环境变量

sudo vim /etc/profile
###复制以下代码到文件结尾
JAVA_HOME=/usr/local/java/jdk1.8.0_161
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH

4、通知系统java的位置

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_161/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_161/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_161/bin/javaws" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_161/bin/javaws" 1

5、设置默认JDK

sudo update-alternatives --set java /usr/local/java/jdk1.8.0_161/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_161/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_161/bin/javaws

6、重新载入profile

source /etc/profile

通过 java -version以及javac -version即可看到是否安装完成
参考:http://blog.csdn.net/qq_29343201/article/details/51926430

你可能感兴趣的:(kali)