ubuntu系统默认没有安装java环境,当运行javac时提示没有安装:
$ javac The program 'javac' can be found in the following packages: * default-jdk * ecj * gcj-5-jdk * openjdk-8-jdk-headless * gcj-4.8-jdk * gcj-4.9-jdk * openjdk-9-jdk-headless Try: sudo apt install <selected package>
打开oracle官网,java下载地址
http://www.oracle.com/technetwork/java/javase/downloads/index.html
根据系统选择版本,这里选择 jdk-8u144-linux-x64.tar.gz(Linux x64 176.92 MB)下载好之后,进行解压安装,这里安装到/opt/jdk-8目录下
cd /opt/ mkdir jdk1.8.0_144 cd jdk1.8.0_144/ mv /home/muti/Downloads/jdk-8u144-linux-x64.tar.gz . tar -zxvf jdk-8u144-linux-x64.tar.gz mv jdk1.8.0_144/* .
然后在/etc/profile中新建java环境变量,
vim /etc/profile
填写内容如下
export JAVA_HOME=/opt/jdk1.8.0_144 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin export JAVA_HOME=/usr/jdk1.8.0_144 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
立刻生效
source /etc/profile
检查是否正确安装
java -version
输出
# java -version java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)