linux系統安裝jdk,配置環境變數

゛ゞ旁觀者ヾ發表於2020-12-05

新建資料夾

cd /usr/local
mkdir java

上傳tar包

解壓tar包

tar -xzvf jdk-8u152-linux-x64.tar.gz

配置系統環境變數

cd /etc/
vi environment
	增加以下內容:
		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:$JRE_HOME/lib

配置使用者環境變數

vi profile
在內容中間,增加以下內容:
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:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH:$HOME/bin
例如:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

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:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/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

環境變數設定生效

source /etc/profile 

相關文章