M1 MAC is configured with multiple jdks and can be actively switched

You and other students 2022-02-13 08:02:38 阅读数:618

m1 mac configured multiple jdks

Multiple Java Environmental Science

Because the project needs , need jdk11 To run a project , But other projects are jdk1.8 Of , It is inconvenient to replace directly jdk, So you need to configure multiple on one machine jdk

install jdk11

  1. download jdk11
    File download address :https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_osx-x64_bin.tar.gz

  2. Unzip the installation package ( The default installation location in the system :/Library/Java/JavaVirtualMachines/)

sudo tar -zxf openjdk-11.0.1_osx-x64_bin.tar.gz -C /Library/Java/JavaVirtualMachines/
  1. verification

  2. Configure environment variables

(1) ~/.bash_profile Modify environment variables

Replace according to the version installed by yourself

export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_11_HOME=$(/usr/libexec/java_home -v11)
export JAVA_17_HOME=$(/usr/libexec/java_home -v17)
#alias Command dynamic switching JDK edition 
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
alias jdk11='export JAVA_HOME=$JAVA_11_HOME'
alias jdk17='export JAVA_HOME=$JAVA_17_HOME'

perform source ~/.bash_profile Make the above settings work

  1. Multiple version switching tool JEnv
brew install jenv

To configure JEnv environment variable

echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile \
&&echo 'eval "$(jenv init -)"' >> ~/.bash_profile \
&&source ~/.bash_profile
  1. To configure jenv
    View all JDK The default installation location in the system
/usr/libexec/java_home -V

Add directory to jenv Ongoing management

jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home

View added versions

jenv versions

6. Manual switching

jenv global 11.0

Reference resources :

copyright:author[You and other students],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130802362120.html