Master your Java Environment with jenv

https://github.com/jenv/jenv#readme

  1. Installing jenv

    On OSX, the simpler way to install jEnv is using Homebrew

    brew install jenv

    Alternatively, and on Linux, you can install it from source :

    1
    2
    3
    4
    5
    6
    7
    git clone https://github.com/jenv/jenv.git ~/.jenv
    # Shell: bash
    echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
    echo 'eval "$(jenv init -)"' >> ~/.bash_profile
    # Shell: zsh
    echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
    echo 'eval "$(jenv init -)"' >> ~/.zshrc

    note: notice your Shell(zsh or bash), find regarding profile(~/.bash_profile or ~/.zshrc).

  2. jenv doctor

  3. Adding Your Java Environment

    jenv add $(/usr/libexec/java_home)

    add jdk to your jenv.

    jenv add /Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home jdk1.8 added

  4. Check java versions.

    1
    2
    3
    4
    5
    jenv versions
    *system (set by /Users/user/.jenv/version)
    11.0
    11.0.2
    openjdk64-11.0.2
  5. Setting a Java Version

    1
    2
    3
    jenv global 11.0.2
    jenv shell 11.0.2
    jenv local 11.0.2
  6. Using two JVMs on MacOS

    https://github.com/AdoptOpenJDK/homebrew-openjdk

    • latest:

      1
      brew cask install adoptopenjdk
    • Other Versions

      1
      2
      brew tap AdoptOpenJDK/openjdk
      brew cask install <version>

    This will install the latest version of Java 8 to a special directory in macOS. Let’s see which directory that is:

    1
    2
    3
    ls -1 /Library/Java/JavaVirtualMachines
    adoptopenjdk-8.jdk
    openjdk-11.0.2.jdk

    We’ll add the Java home directory using jenv

    1
    jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/ openjdk64-1.8.0.222 added
感谢支持,让我安静的做蚂蚁梦!