我是 Ubuntu 的新手,所以请多多包涵。
我最近手动下载并安装了 (Java SE 7ux) JavaSE 1.7.0_51。Linux x64(适用于 64 位系统)“tar.gz”包。我的 Ubuntu 版本是 13.10(操作系统 64 位)
我认真遵循以下指示:如何在 Ubuntu 上安装 JDK 7
为了验证安装是否成功,我写道:
javac -version
并得到以下结果:
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
$ which java gives the below results:
/usr/bin/java
$ which javac also gives the below results:
/usr/bin/javac
我重复了几次步骤,以防我错过了重要的步骤,但仍然得到了相同的结果。在网上搜索了几次后,我发现@参考,我实际上可以通过 PPA 存储库在 Ubuntu 上安装 Java。
安装完成后
$ java -version
我仍然得到:
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
然而当我
$ cd /usr/bin
$ ls -ld java*
我得到:
lrwxrwxrwx 1 root root 22 Feb 19 19:06 java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 23 Feb 17 02:15 javac -> /etc/alternatives/javac
lrwxrwxrwx 1 root root 25 Feb 19 20:09 javadoc -> /etc/alternatives/javadoc
lrwxrwxrwx 1 root root 32 Feb 19 20:09 javafxpackager -> /etc/alternatives/javafxpackager
lrwxrwxrwx 1 root root 23 Feb 19 20:09 javah -> /etc/alternatives/javah
lrwxrwxrwx 1 root root 23 Feb 19 20:09 javap -> /etc/alternatives/javap
lrwxrwxrwx 1 root root 25 Feb 19 20:09 java_vm -> /etc/alternatives/java_vm
lrwxrwxrwx 1 root root 24 Feb 17 02:15 javaws -> /etc/alternatives/javaws
也类似于:
$ cd /etc/alternatives
$ ls -ld java*
lrwxrwxrwx 1 root root 36 Feb 19 19:15 java -> /usr/local/java/jdk1.7.0_51/bin/java
lrwxrwxrwx 1 root root 37 Feb 17 02:15 javac -> /usr/local/java/jdk1.7.0_51/bin/javac
lrwxrwxrwx 1 root root 38 Feb 19 20:09 javadoc -> /usr/lib/jvm/java-7-oracle/bin/javadoc
lrwxrwxrwx 1 root root 48 Feb 19 20:09 javadoc.1.gz -> /usr/lib/jvm/java-7-oracle/man/man1/javadoc.1.gz
lrwxrwxrwx 1 root root 45 Feb 19 20:09 javafxpackager -> /usr/lib/jvm/java-7-oracle/bin/javafxpackager
lrwxrwxrwx 1 root root 55 Feb 19 20:09 javafxpackager.1.gz -> /usr/lib/jvm/java-7-oracle/man/man1/javafxpackager.1.gz
lrwxrwxrwx 1 root root 36 Feb 19 20:09 javah -> /usr/lib/jvm/java-7-oracle/bin/javah
lrwxrwxrwx 1 root root 46 Feb 19 20:09 javah.1.gz -> /usr/lib/jvm/java-7-oracle/man/man1/javah.1.gz
lrwxrwxrwx 1 root root 36 Feb 19 20:09 javap -> /usr/lib/jvm/java-7-oracle/bin/javap
lrwxrwxrwx 1 root root 46 Feb 19 20:09 javap.1.gz -> /usr/lib/jvm/java-7-oracle/man/man1/javap.1.gz
lrwxrwxrwx 1 root root 42 Feb 19 20:09 java_vm -> /usr/lib/jvm/java-7-oracle/jre/bin/java_vm
lrwxrwxrwx 1 root root 42 Feb 17 02:15 javaws -> /usr/local/java/jdk1.7.0_51/jre/bin/javaws
注意
javadoc.1.gz -> /usr/lib/jvm/java-7-oracle/man/man1/javadoc.1.gz
javafxpackager.1.gz -> /usr/lib/jvm/java-7-oracle/man/man1/javafxpackager.1.gz
javah.1.gz -> /usr/lib/jvm/java-7-oracle/man/man1/javah.1.gz
javah.1.gz -> /usr/lib/jvm/java-7-oracle/man/man1/javah.1.gz
...全部为红色
- 这一切意味着什么?最重要的是,如何使我的 Java 安装正常工作?
期待您的帮助!
答案1
从官方网站下载 Oracle java
手动安装 JDK 1.7
#java -version
#sudo mkdir -p /usr/lib/jvm
#sudo mv jdk-7u21-linux-i586.tar.gz /usr/lib/jvm
#cd /usr/lib/jvm
#sudo tar zxvf jdk-7u21-linux-i586.tar.gz
#sudo rm jdk-7u21-linux-i586.tar.gz
#ls -l
#jdk1.7.0_21
#sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_21/bin/javac" 1
#sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_21/bin/java" 1
#sudo update-alternatives --set "javac" "/usr/lib/jvm/jdk1.7.0_21/bin/javac"
#sudo update-alternatives --set "java" "/usr/lib/jvm/jdk1.7.0_21/bin/java"
#sudo vi /etc/profile
Add the following entries to the bottom of your /etc/profile file:
#JAVA_HOME=/usr/lib/jvm/jdk1.7.0_21 PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME export PATH
#. /etc/profile
#java -version
将 jdk1.7.0_21 替换为您下载的版本