ubuntu下命令行安装jdk --转载

1.ubuntu使用的是openjdk,所以我们需要先找到合适的jdk版本。在命令行中输入命令:

$apt-cache search openjdk

返回结果列表(因个人电脑而有所不同):

default-jdk-doc - Standard Java or Java compatible Development Kit (documentation) 
…(省略部分显示结果) 
openjdk-6-source - OpenJDK Development Kit (JDK) source files 
openjdk-7-jre-dcevm - Alternative VM for OpenJDK 7 with enhanced class redefinition 
openjdk-7-jre-lib - OpenJDK Java runtime (architecture independent libraries) 
openjdk-7-jre-zero - Alternative JVM for OpenJDK, using Zero/Shark 
openjdk-8-dbg - Java runtime based on OpenJDK (debugging symbols) 
openjdk-8-demo - Java runtime based on OpenJDK (demos and examples) 
openjdk-8-doc - OpenJDK Development Kit (JDK) documentation 
openjdk-8-jdk - OpenJDK Development Kit (JDK) 
openjdk-8-jre - OpenJDK Java runtime, using Hotspot JIT 
openjdk-8-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless) 
openjdk-8-jre-jamvm - Alternative JVM for OpenJDK, using JamVM 
openjdk-8-jre-zero - Alternative JVM for OpenJDK, using Zero/Shark 
openjdk-8-source - OpenJDK Development Kit (JDK) source files 
uwsgi-app-integration-plugins - plugins for integration of uWSGI and application 
uwsgi-plugin-jvm-openjdk-7 - Java plugin for uWSGI (OpenJDK 7)

2.从搜索的列表里找到我们需要安装的jdk版本,如上面标黑的 
openjdk-8-jdk - OpenJDK Development Kit (JDK)

3.输入安装命令,进行安装:

$sudo apt-get install openjdk-8-jdk

等待命令行显示“done”,即安装成功过。

4.查看安装结果。输入命令:

$java -version

显示结果如下: 
openjdk version “1.8.0_91” 
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~15.10.1-b14) 
OpenJDK Server VM (build 25.91-b14, mixed mode) 
则说明安装成功。

5.安装成功后,还需要配置java_home变量:

1)输入命令:echo $java_home 
返回空行;

2)which javac 
返回:/usr/bin/javac

3)file /usr/bin/javac 
返回:/usr/bin/javac: symbolic link to /etc/alternatives/javac

4)file /etc/alternatives/javac 
返回:/etc/alternatives/javac: symbolic link to /usr/lib/jvm/java-8-openjdk-i386/bin/javac

5)file /usr/lib/jvm/java-8-openjdk-i386/bin/javac 
返回:/usr/lib/jvm/java-8-openjdk-i386/bin/javac: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-Linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=a8eeb948df0418fc8f046910c73713f2b6697a9a, stripped

6)sudo echo export JAVA_HOME=”/usr/lib/jvm/java-8-openjdk-i386/bin”>>~/.bashrc 
输入密码;

7)source ~/.bashrc

8)测试命令:gedit ~/.bashrc 
查看打开的文件末尾是否成功加入java_home

posted @ 2017-05-21 13:34  虾米mi  阅读(1273)  评论(0编辑  收藏  举报