Ubuntu下安装JDK
Table of Contents
直接下载JDK压缩包方式安装
官网下载对应版本的JDK
解压缩并放至指定目录
sudo mkdir /usr/lib/jvm sudo tar -zxvf jdk-xxx.gz -C /usr/lib/jvm
修改环境变量
sudo vim ~/.bashrc export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_151 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH ~/.bashrc
设置系统默认JDK版本
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_151/bin/java 300 # 数字表示优先级 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_151/bin/javac 300 sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.8.0_151/bin/jar 300 sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.8.0_151/bin/javah 300 sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.8.0_151/bin/javap 300 sudo update-alternatives --config java # 选择合适的JDK
通过ppa(源)方式安装
添加ppa
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update
安装oracle-java-installer
sudo apt-get install oracle-java8-installer
注意事项
- ppa有可能会失效,若失效则再找过一个
- 如果installer下载很慢,可以中断,然后下载好对应的jdk的tar.gz包。放在
/var/cache/oracle-jdk8-installer
目录下。然后再安装一次installer,它会默认使用下载好的压缩包。
Generated by Emacs 25.x(Org mode 8.x)
Copyright © 2014 - pinvon - Powered by EGO