Java version control using cask + anyenv + jenv


OS:macOS Catalina 10.15.5 brew:2.4.3

Java installation using cask

If you use brew cask as it is, you cannot install an old version of Java. Therefore, use the following command to install older versions as well.

$ brew tap homebrew/cask-versions

Install various versions

//Check the installable java version
$ brew search java

// java14
$ brew cask install java

// java11
$ brew cask install java11

// java8
$ brew cask install adoptopenjdk8

//Java version check
$ /usr/libexec/java_home -V

Install anyenv

anyenv can manage * env. In this case, it is installed to manage jenv.

//Install anyenv with brew
$ brew install anyenv

//Path added zsh version
$ echo 'eval "$(anyenv init -)"' >> ~/.zshrc

//Manifest directory creation
$ anyenv install --init
with this.The anyenv directory is created.

//SHELL restart
$ exec $SHELL -l

//anyenv command
//Installed*env version check
$ anyenv versions

//Can be installed with anyenv*List of env
$ anyenv install -l

Enter a convenient anyenv login

The plugin is optional, but it is convenient to include it.

//Create directory for plugins
$ mkdir -p ~/.anyenv/plugins

// anyenv-I put it in update anyenv*A plugin that updates env in bulk
$ git clone ~/.anyenv/plugins/anyenv-update

// anyenv-I put it in git anyenv*Plugin that can execute env with git command
$ git clone ~/.anyenv/plugins/anyenv-git

Install jenv

Manage Java installed with cask

//install jenv
$ anyenv install jenv

//SHELL restart
$ exec $SHELL -l

$ anyenv versions
* 14.0.1 (set by /Users/masa/.anyenv/envs/jenv/version)

Settings to manage Java with jenv

It is a method to register various Java versions in jenv and switch.

//Add to the associated jenv
$ jenv add `/usr/libexec/java_home -v "1.8"`
$ jenv add `/usr/libexec/java_home -v "11"`
$ jenv add `/usr/libexec/java_home -v "14"`

//Check the version of java managed by jenv
$ jenv versions

//global setting
$ jenv global 11.0.2

//Java version check
$ java versions

//Shell launch
$ jenv exec zsh

// JAVA_Set HOME automatically
$ jenv enable-plugin export

// JAVA_HOME confirmation
$ echo $JAVA_HOME

//Topic When using another version of JDK in a specific directory
$ jenv local 11.0.2

Recommended Posts

Java version control using cask + anyenv + jenv
Java version control with jenv
Java version control on macOS
Version control Java with SDKMAN
Using JavaScript from Java in Rhino 2021 version
# Java: vol1: [java / JDK version control best practice]
Java installation (Mac, Homebrew, multiple version control)
Java control syntax
Java control syntax
Java version check
Try using Sourcetrail (win version) in Java code
Try using Sourcetrail (macOS version) in Java code
Sorting using java comparator
Java version notation comparison
[Java] Control syntax notes
Scraping practice using Java ②
Switching java version (memorial)
Scraping practice using Java ①
[Rails version control] rails version downgrade
Using multiple versions of Java with Brew on Mac + jEnv