How do I install Java on Mac OSX allowing version switching?

后端 未结 10 829
暖寄归人
暖寄归人 2020-12-22 14:37

I want to install OpenJDK Java on Mac OSX and have it work alongside other JDK\'s since it is a newer release. Currently, I downloaded the tar.gz and placed it in my path b

10条回答
  •  离开以前
    2020-12-22 15:06

    With Homebrew and jenv:

    Assumption: Mac machine and you already have installed homebrew.

    Install cask:

    $ brew tap caskroom/cask
    $ brew tap caskroom/versions
    

    To install latest java:

    $ brew cask install java
    

    To install java 8:

    $ brew cask install java8
    

    To install java 9:

    $ brew cask install java9
    

    If you want to install/manage multiple version then you can use 'jenv':

    Install and configure jenv:

    $ brew install jenv
    $ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
    $ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
    $ source ~/.bash_profile
    

    Add the installed java to jenv:

    $ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
    $ jenv add /Library/Java/JavaVirtualMachines/jdk1.11.0_2.jdk/Contents/Home
    

    To see all the installed java:

    $ jenv versions
    

    Above command will give the list of installed java:

    * system (set by /Users/lyncean/.jenv/version)
    1.8
    1.8.0.202-ea
    oracle64-1.8.0.202-ea
    

    Configure the java version which you want to use:

    $ jenv global oracle64-1.6.0.39
    

提交回复
热议问题