ubuntu/linux下命令行安装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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值