[Linux] install Java on Linux

Keywords: Java JDK Linux Ubuntu

Sketch

The Linux system used in this article is Ubuntu 16.04 and JDK is 1.8.0_.

JDK Download

JDK 1.8.0? Download link: https://pan.baidu.com/s/1AgiZ5DHnJjCVxBKPzdCddw
Extraction code: v1ud

Linux installing Java

  1. Create a folder in / usr/local / directory and upload the downloaded JDK through Xftp tool (if there is no Xftp tool, you can browse another article https://blog.csdn.net/qq_36525300/article/details/89216023 Download)
cd /usr/local
mkdir java
  1. decompression
tar -zxvf jdk-8u152-linux-x64.tar.gz
  1. Set owner
chown -R root:root /usr/local/java/
  1. Configure system environment variables and add path configuration
vi /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:	/usr/local/games"
export JAVA_HOME=/usr/local/java/jdk1.8.0_152
export JRE_HOME=/usr/local/java/jdk1.8.0_152/jre
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
  1. Configure user environment variables
vi /etc/profile
if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

export JAVA_HOME=/usr/local/java/jdk1.8.0_152
export JRE_HOME=/usr/local/java/jdk1.8.0_152/jre
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
  1. Validate configured environment variables
source /etc/profile
  1. Test whether the configuration is successful
root@Ubuntu:/usr/local/java# java -version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

Posted by bmpco on Fri, 29 Nov 2019 12:51:56 -0800