302
289

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacでJDKのバージョンを切り替える

Last updated at Posted at 2014-03-19

Java 8がリリースされたので早速インストールしたが、まだJava 7も残しておきたいし、切り替えることもあるので調べてみた。

Macでは、 /usr/libexec/java_home を使ってJAVA_HOMEを変えるのが一番スマートっぽい。

インストールされているJDKのバージョン一覧を出す

% /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    1.8.0, x86_64:      "Java SE 8"     /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
    1.7.0_45, x86_64:   "Java SE 7"     /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home

現在有効なJDKのバージョンを出す

% /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home

JDKのバージョンを切り替える

% export JAVA_HOME=`/usr/libexec/java_home -v 1.7.0_45`

% java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
% javac -version
javac 1.7.0_45

% export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0`
% java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
302
289
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
302
289

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?