UbuntuにOracle (Sun) Java 6 SDKをインストールする

AOSPのソースビルドなどのために、UbuntuにOracle(Sun)のJava6環境が必要なケースはあると思うのだけども、ここ数ヶ月くらいの間にUbuntuリポジトリから削除されてしまってるとのこと。

なので、AOSPのサイトに書かれている以下の方法も今では「パッケージが見つかりません」みたいなエラーになって使えないと。

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

で、これを回避しようとググってみるとPPAで有志が独自に公開してるaptリポジトリを追加してそこからインストールするとか、aptを使わずにOracleサイトからパッケージ落としてきてインストールするなどあるらしい。

お手軽なのはPPAリポジトリ形式で、これはppa:ferramrobertoを使うサンプルを多く見かける。

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:ferramroberto/java
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk sun-java6-plugin

ただし正確にはOracle(Java?)のライセンスや著作権的にppaで独自にパッケージ配布するのはNGなようなのでこの方式はグレー(実際にはきちんとインストールできるし、動作は問題無いけど)。

かといって、いちばん真っ当な手順と思われるOracleサイトからダウンロードしてインストールする方式だと、インストールした後の環境設定が少し面倒。

Ubuntu公式のドキュメントでJava6の項を見てみると、

Java - Community Ubuntu Documentation

ppa:ferramrobertoを公開していた人がライセンス・著作権問題をクリアにした形でインストールできるスクリプトを作って公開していた。

flexiondotorg/oab-java6 · GitHub

Downloads the Java binary installers from Oracle, builds the .deb packages locally on your computer and then installs them. Packages are compatible with the “official” Ubuntu ones and will upgrade Java 6 that was previously installed from packages.

・Oracleサイトからのバイナリパッケージダウンロード
・.debファイル化
・ローカルのaptリポジトリとして構築

までを自動で行うスクリプトのようだ。JDKのバイナリをOracleサイトからきちんとダウンロードすることで諸問題を回避しているぽい。

githubのreadmeに書かれているとおりにスクリプトをダウンロードして実行する。

cd ~/
wget https://github.com/flexiondotorg/oab-java6/raw/0.2.0/oab-java6.sh -O oab-java6.sh
chmod +x oab-java6.sh
sudo ./oab-java6.sh

すると、

oab-java6.sh v0.1.9 - Create a local 'apt' repository for Ubuntu Java packages.
Copyright (c) Martin Wimpress, http://flexion.org. MIT License

By running this script to download Java you acknowledge that you have
read and accepted the terms of the Oracle end user license agreement.

* http://www.oracle.com/technetwork/java/javase/terms/license/

If you want to see what this is script is doing while it is running then execute
the following from another shell:

  tail -f /home/findup/oab-java6.sh.log

Downloading common.sh
 [x] Installing Java build requirements success
 [x] Making build directories success
 [x] Removing clones of https://github.com/rraptorr/sun-java6 success
 [x] Cloning https://github.com/rraptorr/sun-java6 success
 [x] Checking out v6.31-2 success
 [x] Getting Java SE download pagesuccess
 [x] Getting current release download page success
 [x] Downloading jdk-6u31-linux-i586.bin : 81.34 MB success
 [x] Symlinking jdk-6u31-linux-i586.bin success
 [x] Downloading jdk-6u31-linux-x64.bin : 81.62 MB success
 [x] Symlinking jdk-6u31-linux-x64.bin success
 [x] Updating the changelog success
 [x] Building the packages success
 [x] Moving the packages success
 [x] Creating Packages.gz file success
 [x] Creating Release file success
 [x] Signing the 'Release' file success
 [x] Exporting public key success
 [x] Adding public key success
 [x] Update package list success
All done!

っという感じでダウンロードとローカルなaptリポジトリを設定するところまで行ってくれる。あとはいつものように

$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

とやればJava6 SDKがインストールできる。

Java6 SDKの最近のインストール方法はいろいろあるけど、こういう方法もあるよ、ということで。

まぁ個人的にはAOSPビルドにしか使わないので、AOSPがOpenJDKに対応してくれるほうが良いかなぁとは思うけど。

タイトルとURLをコピーしました