How to switch Java versions on Mac

There is a phenomenon that I misunderstand the method every time even though the method is written on various sites, so I will summarize it myself.

: computer: environment: computer:

$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

--Installed Java --How to check Java installed on Mac-- Qiita

$ /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java_home -V
Matching Java Virtual Machines (5):
    1.8.0_131, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
    1.8.0_45, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
    1.7.0_67, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
    1.6.0_65-b14-468, x86_64:   "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-468, i386: "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home

Switch the version from "1.8.0_45" to "1.7.0_67".

1 Add to .bashrc.

Add two lines to .bashrc: "JAVA_HOME settings" and "Add JAVA_HOME to PATH".

$ sudo vi .bashrc
Password:{password}

---Vi editor from here------------------------------------------
<Here is the setting I wrote earlier>
export JAVA_HOME=`/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java_home -v "1.7"`
PATH=$JAVA_HOME/bin:$PATH
---So far vi editor------------------------------------------

Thank you to this site.

.profile, .bashrc, .zshrc, etc. are fine, but set the environment variable JAVA_HOME using the java_home command. Switch Java version on OS X-Qiita

2 Reload .bashrc.

I always misunderstand "I can't switch: confounded:" without doing this. After writing the configuration file, reloading is basic, isn't it?

$ source ~/.bashrc

Thank you to this site.

After adding it, reload it with source ~ / .bash_profile to switch the version. How to install and switch multiple versions of Java (JDK) using Homebrew on Mac + Update --TASK NOTES

3 Confirm.

Make sure it is switched.

$ java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

Recommended Posts

How to switch Java versions on Mac
How to check Java installed on Mac
How to switch between multiple Java versions
How to switch Java in the OpenJDK era on Mac
How to uninstall Java 8 (Mac)
How to switch Java version with direnv in terminal on Mac
Switch between multiple versions of Java on Mac
As of April 2018 How to get Java 8 on Mac
[Java] How to update Java on Windows
How to install Eclipse (Photon) on Mac
How to uninstall if you have updated to Java 9 on your Mac
Install Java on Mac
Easily switch Java versions with alias on macOS
[Java] How to switch from open jdk to oracle jdk
[Java] Memo on how to write the source
[Java] How to use Map
How to lower java version
[Java] How to use Map
Java --How to make JTable
How to use java Optional
How to use java non-standard library on IntelliJ IDEA
How to deploy on heroku
How to minimize Java images
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] How to use string.format
How to use Java Map
[Java] How to execute tasks on a regular basis
How to set Java constants
How to run Java EE Tutial on github on Eclipse
How to use Java variables
How to convert Java radix
[Java] How to implement multithreading
[Java] How to use Optional ①
How to install JDK8-10 (Mac)
How to initialize Java array
Notes on how to use regular expressions in Java
How to decompile apk file to java source code with MAC
Java conditional branching: How to create and study switch statements
How to deploy a simple Java Servlet app on Heroku
Using multiple versions of Java with Brew on Mac + jEnv
How to deploy a kotlin (java) app on AWS fargate
How to dynamically switch JDK when building Java in Gradle
How to install java9 on elementaryOS Freya or Ubuntu 14.04 LTS
How to study Java Silver SE 8
How to use Java HttpClient (Get)
How to deploy jQuery on Rails
How to deploy Laravel on CentOS 7
How to install JMeter for Mac
Steps to run docker on Mac
How to "hollow" View on Android
How to install ImageMagick on Windows 10
How to disassemble Java class files
[Java] How to use join method
How to use Ruby on Rails
How to deploy Bootstrap on Rails
How to run JavaFX on Docker
How to learn JAVA in 7 days
How to use Bio-Formats on Ubuntu 20.04