Java multi-version management under macOS

This article introduces the use of HomeBrew and jEnv for Java multi-version management under macOS

  1. Upgrade HomeBrew (you have to install HomeBrew first)

    brew update

  2. Allow brew command to find version information

    brew tap caskroom/versions

  3. View Java version

    brew cask search java

  4. Install Java8

    brew cask install java8

  5. Install the jEnV version management tool

    brew install jenv

  6. Set environment variables (configured in the ~/.bash_profile file using Bash, and in the ~/.zshrc file using Zsh)

    export PATH="$HOME/.jenv/bin:$PATH"

    eval "$(jenv init -)"

  7. Add Java virtual environment (I added Java8, Java9 and Java10 here)

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

    jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home

    jenv add /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home

  8. View Added Java Versions

    jenv versions

  9. Set the current Java version

    jenv shell oracle64-1.8.0.162(current shell)

    jenv global oracle64-1.8.0.162(Global Settings)

  10. Check if it works

    java -version

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325693927&siteId=291194637