macbook installation JDK configuration environment variable JAVA_HOME CLASSPATH

Article Directory

Download and install

Go to Oracle official website: https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html to download

Insert picture description here


Find the line corresponding to macOS: After

Insert picture description here

clicking download, you will be asked to log in with your Oracle account (if you don't have one, you have to register one with your email).

The downloaded installation package is in the .dmgformat

Insert picture description here


Double-click to install (the installation method of the dmg package can be Baidu).

After the installation is successful, you can see that there is one more Java in the apple->System Preferences panel in the upper left corner.

Insert picture description here

Installation path && environment variables

Mine is /System/Volumes/Data/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/

Insert picture description here

Seeing this familiar catalog, it is obvious what to do next.
Environment variable content to be configured:

export JAVA_HOME=/System/Volumes/Data/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/
export CLASSPATH=.:$JAVA_HOME\lib:$JAVA_HOME\jre\lib
export PATH=$JAVA_HOME:$PATH

Environment variable write && to make it effective

# 将环境变量写入配置文件,保存
vi ~/.zshrc

# 生效
source ~/.zshrc

test

Insert picture description here


The text content of the above command is as follows:

[email protected] ~ % 
[email protected] ~ % vi ~/.zshrc
[email protected] ~ % 
[email protected] ~ % more ~/.zshrc

# alias list
alias l="ls -G "
alias ll="ls -alG "

# JDK
export JAVA_HOME=/System/Volumes/Data/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/
export CLASSPATH=.:$JAVA_HOME\lib:$JAVA_HOME\jre\lib
export PATH=$JAVA_HOME:$PATH
[email protected] ~ % 
[email protected] ~ % touch ~/.zshrc
[email protected] ~ % 
[email protected] ~ % echo $JAVA_HOME
/System/Volumes/Data/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/
[email protected] ~ % echo $CLASSPATH
.:/System/Volumes/Data/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib:/System/Volumes/Data/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jrelib
[email protected] ~ % echo $PATH
/System/Volumes/Data/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
[email protected] ~ % which java
/usr/bin/java
[email protected] ~ % which javac
/usr/bin/javac
[email protected] ~ % java -version
java version "1.8.0_291"
Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)
[email protected] ~ % javac -version
javac 1.8.0_291
[email protected] ~ % 

We can see JAVA_HOMEand CLASSPATHhave successfully configured.

But one thing, currently in use javaas well as javacin the /usr/bin/directory, not our configuration JAVA_HOMEunder.

[email protected] ~ % which java
/usr/bin/java
[email protected] ~ % which javac
/usr/bin/javac

But the version is the same as the version downloaded and installed just now.

The non-decompression installation method will automatically "link" the startup program of the program to the /usr/bin/directory.
Which /usr/bin/represents User Share Resource / Binarythat is 用户共享的可执行程序.