LoginSignup
1
0

More than 1 year has passed since last update.

MacOSにOracle SQL Developerをインストールする

Last updated at Posted at 2021-07-10

Oracle DBを操作するインターフェースとしてOracle SQL Developerを試してみることにしました。そのインストールの手順を残します。
私の環境はmacOS Catalinaになります

おまけでSQL DeveloperのJDKのバージョンチェックの仕組みを調べてみました。

インストール

ダウンロード

公式サイトからソフトをダウンロードします。プラットフォームはMac OSXです。

zipファイルを解答するとappファイルが入っています。このappファイルをアプリケーションフォルダに移動すればインストール完了です。

JDKのインストール

動作させるにはJDKが必要です。以下のサイトからインストールしましょう。バージョンとしては8か11が必要です。

古いバージョンのJDKを直接入れるのが嫌なら以下のツールを使ってみると良いかも

JDKが入っていない,もしくはバージョンが適切でない場合は以下のようなエラーが発生します。

最低でもJava 8が必要と書かれていますが,最新バージョンを入れても上のアラートが出るのでご注意を。
私は脳死でJDK 16を入れて動かなくて少し詰まりました。
調べてみると同じようにハマった方々がいらっしゃって,正しいバージョン(JDK 11)をインストールすることで解決できました。

完了

これにてインストール完了です。お疲れさまでした:v:

おまけ

最新のJDKを入れても動作しないというのが不思議でしたので深ぼって調べてみることにしました。

JDKバージョンのチェック処理

appファイルを覗いてみるとSQL Developerの起動時に走るシェルスクリプトを見つけました。
/Applications/SQLDeveloper.app/Contents/MacOS/sqldeveloper.sh

中身を読んでみると以下のスクリプトでJDKのバージョンをチェックしていました。

#!/bin/bash 
TMP_PATH=`/usr/libexec/java_home -F -v 1.8`
if [ -z "$TMP_PATH" ] ; then
  TMP_PATH=`/usr/libexec/java_home -F -v 11`
  if [ -z "$TMP_PATH" ] ; then
    TMP_PATH=`/usr/libexec/java_home -F -v 12`
    if [ -z "$TMP_PATH" ] ; then
      osascript -e 'tell app "System Events" to display dialog "SQL Developer requires a minimum of Java 8. \nJava 8 can be downloaded from:\n http://www.oracle.com/technetwork/java/javase/downloads/"'
      exit 1
    fi
  fi
fi

どうやら/usr/libexec/java_homeというコマンドでバージョンを調べているようです。
if文でJDK 8(1.8), JDK 11, JDK 12のどれかが入っていると起動できるようにしてあります。
公式では8と11のみ対応となっていましたが,一応12でもOKなようです。
(ここを弄れば最新のJDKでも動かせそうですね:rolling_eyes:

osascriptというのがmacOS標準のアラートのようです。

java_home

$JAVA_HOMEを読み取ってJDKをチェックするのが普通だと思っていましたが,SQL Developerではjava_homeというコマンドを使っています。初めて知ったコマンドだったので,ここに関して少し深ぼってみます。

/usr/libexec/java_homeを覗いてみるとこれはシンボリックリンクで本当のパスは/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java_homeでした。
システム直下にあるということでどうやらAppleが提供しているコマンドっぽいです。
manで使い方を調べてみます。

NAME
       java_home - return a value for $JAVA_HOME


SYNOPSIS
       /usr/libexec/java_home [options]


DESCRIPTION
       The java_home command returns a path suitable for setting the JAVA_HOME
       environment variable.  It determines this path from the user's  enabled
       and  preferred  JVMs  in  the Java Preferences application.  Additional
       constraints may be provided to filter the list of JVMs  available.   By
       default,  if  no  constraints  match  the  available  list of JVMs, the
       default order is used.  The path is printed to standard output.


OPTIONS
       -v or --version  version
          Filters the returned JVMs  by  the  major  platform  version  in
          "JVMVersion" form. Example versions: "1.5+", or "1.6*".


       -a or --arch  architecture
          Filters  the  returned  JVMs  by  the architecture they support.
          Example architectures: "i386", "x86_64", or "ppc".


       -d or --datamodel  datamodel
          Filters the returned JVMs capable of running  in  32  or  64-bit
          mode.  Supported  datamodels:  "-d32"  and  "-d64". Specifying a
          datamodel is synonymous with specifying a  particular  architec-
          ture.


       -t or --task  task
          Selects from the list of JVMs which can run a specific task. The
          order of each of these lists is  set  by  the  Java  Preferences
          application.   Supported  tasks:  "Applets",  "WebStart",  "Bun-
          dledApp", "JNI" and "CommandLine". The default task is "Command-
          Line".


       -F or --failfast
          Immediately  fails  when  filters return no JVMs; does not print
          out the path to the default $JAVA_HOME.


       --exec  command ...
          Executes the command at $JAVA_HOME/bin/<command> and passes  the
          remaining arguments. Any arguments to select which $JAVA_HOME to
          use must precede the --exec option.


       -X or --xml
          Prints the list of selected JVMs and associated properties as an
          XML plist to stdout.


       -V or --verbose
          Prints the matching list of JVMs and architectures to stderr.


       -h or --help
          Brief usage information.


USAGE
       /usr/libexec/java_home  helps  users set a $JAVA_HOME in their login rc
       files, or provides a way for command-line Java tools to  use  the  most
       appropriate  JVM  which  can  satisfy a minimum version or architecture
       requirement. The --exec argument  can  invoke  tools  in  the  selected
       $JAVA_HOME/bin  directory,  which  is useful for starting Java command-
       line tools from launchd plists without hardcoding the full path to  the
       Java command-line tool.


       Usage for bash-style shells:
          $ export JAVA_HOME=`/usr/libexec/java_home`

       Usage for csh-style shells:
          % setenv JAVA_HOME `/usr/libexec/java_home`




                04 August 2010          

sqldeveloper.shと照らし合わせてみます。
-vオプションでは指定したバージョンのJAVA_PATHを返します。しかし,指定したバージョンよりも新しいJDKがあればそのパスを返してしまいます。
そのため,-Fオプションを付けることで指定したバージョンのJDKがないときにJAVA_HOMEを返さないようにしているようです。

ちなみに-Vオプションを付けるとインストールされたJDKの一覧を見れます。

まとめ

ということでSQL DeveloperのJDKバージョンをチェックする仕組みを調べてみました。macOSではjava_homeを使うのが良さそうに思えました。

1
0
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
1
0