Java environment management tool. By introducing jEnv, you can easily switch between Java versions. It is pyenv in Python. The operation method is almost the same.
Install from Homebrew.
$ brew update
$ brew install jenv
Add the following to .bash_profile
and pass it through the path.
.bash_profile
# jEnv
export JENV_ROOT="$HOME/.jenv"
if [ -d "${JENV_ROOT}" ]; then
export PATH="$JENV_ROOT/bin:$PATH"
eval "$(jenv init -)"
fi
There are many articles installed with brew cask
, but this time I will drop the installer from Oracle and install it manually.
Install the required version of the JDK by referring to the following article.
-How to install past version of Java (JDK 10 or earlier) (Mac) --Qiita
-How to uninstall Java 8 (Mac) --Qiita
Doing the above will enrich your Java development environment.
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (5):
10, x86_64: "Java SE 10" /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home
9.0.4, x86_64: "Java SE 9.0.4" /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
1.8.0_162, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
1.8.0_77, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
1.7.0_80, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home
Probably not all, but somehow it feels good so I installed all of JDK 7-10.
Manually create the ~ / .jenv / versions
folder.
$ mkdir ~/.jenv
$ mkdir ~/.jenv/versions
If not created, jenv add
will cause ln: failed to create symbolic link'/ Users / {username} /. Jenv / versions / oracle64-1.7.0.80': No such file or directory
error.
https://github.com/gcuisinier/jenv/issues/175
Once created, reload .bash_profile
.
$ source ~/.bash_profile
Initially there is no environment in jEnv.
$ jenv versions
* system (set by /Users/{username}/.jenv/version)
Add the environment with the jenv add
command.
# jenv add {Java Virtual Machine(JVM)Home path}
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
$ jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
$ jenv add /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home
The JVM Home path is the path output by the / usr / libexec / java_home -V
command.
If an environment with the same major version has already been added, overwriting will be confirmed, so enter y
and it is OK.
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
oracle64-1.8.0.162 added
1.8.0.162 added
There is already a 1.8 JDK managed by jenv
Do you want to override (type y to confirm)? y
1.8 added
With this, the environment of jEnv has also been enriched.
$ jenv versions
* system (set by /Users/{username}/.jenv/version)
1.7
1.7.0.80
1.8
1.8.0.162
1.8.0.77
10
9.0
9.0.4
oracle64-1.7.0.80
oracle64-1.8.0.162
oracle64-1.8.0.77
oracle64-10
oracle64-9.0.4
Set up the global Java environment with the jenv global
command.
Java 10 has just been released and it seems that Kotlin is not yet supported, so we will set Java 9 here.
#Set up a global Java environment
# jenv global {Environment name}
$ jenv global oracle64-9.0.4
Even in Java 9, there are three environments, "9.0", "9.0.4", and "oracle64-9.0.4", but since the tutorial on the official website sets "oracle64 ...", that is also the case here. I haven't investigated what is different.
Check if the environment has changed. If "*" is added at the beginning of "oracle64-9.0.4", the environment has been switched.
$ jenv versions
system
1.7
1.7.0.80
1.8
1.8.0.162
1.8.0.77
10
9.0
9.0.4
oracle64-1.7.0.80
oracle64-1.8.0.162
oracle64-1.8.0.77
oracle64-10
* oracle64-9.0.4 (set by /Users/{username}/.jenv/version)
Also check the Java version.
$ java -version
java 9.0.4
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
You can see that the environment has changed.
Gradle didn't work well with Java 9, so I decided to use Java 8. https://qiita.com/uhooi/items/c9caa9a9ed6c934a789b#gradleのインストール
If you want to set up a local Java environment (only under a specific folder), you can set it with the jenv local
command after moving to the target folder.
$ mkdir java7
$ cd java7
$ jenv local oracle64-1.7.0.80
$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
##Global settings are applied to folders that are not set locally
$ cd ..
$ java -version
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
The Java development environment is ready. Now you can play around with Android Studio and Kotlin!
Recommended Posts