OpenJDK 7  버전을 Ubuntu 16.04 에 설치하기


sudo add-apt-repository ppa:openjdk-r/ppa  
sudo apt-get update   
sudo apt-get install openjdk-7-jdk  





우분투에는 update-alternatives 를 이용해서 패키지의 버전을 관리 할 수 있다.


안드로이드를 개발하다보면 java version이 안맞아서 버전을 올리거나 내려야 할 경우가 가끔씩 있는데 update-alternatives 로 하면 간단하다.


먼저 oracle 에서 압축된 jdk를 받는다. 버전별로 받아서 원하는 곳에 풀어준다.


나는

/home/lionelj/hoho/dev/jdk 

에다가

.

├── jdk1.5.0_22

├── jdk1.6.0_45

├── jdk1.7.0_79

├── jdk1.8.0_161

└── set_java_env.sh

이렇게 해줬음.

그리고 이 스크립트를 돌리면 된다.

#!/bin/sh

sudo update-alternatives --install "/usr/bin/java" "java" "/home/lionelj/hoho/dev/jdk/jdk1.8.0_161/bin/java" 4
sudo update-alternatives --install "/usr/bin/javac" "javac" "/home/lionelj/hoho/dev/jdk/jdk1.8.0_161/bin/javac" 4
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/home/lionelj/hoho/dev/jdk/jdk1.8.0_161/bin/javaws" 4
sudo update-alternatives --install "/usr/bin/jar" "jar" "/home/lionelj/hoho/dev/jdk/jdk1.8.0_161/bin/jar" 4
sudo update-alternatives --install "/usr/bin/jarsigner" "jarsigner" "/home/lionelj/hoho/dev/jdk/jdk1.8.0_161/bin/jarsigner" 4
sudo update-alternatives --install "/usr/bin/javadoc" "javadoc" "/home/lionelj/hoho/dev/jdk/jdk1.8.0_161/bin/javadoc" 4

sudo update-alternatives --install "/usr/bin/java" "java" "/home/lionelj/hoho/dev/jdk/jdk1.7.0_79/bin/java" 3
sudo update-alternatives --install "/usr/bin/javac" "javac" "/home/lionelj/hoho/dev/jdk/jdk1.7.0_79/bin/javac" 3
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/home/lionelj/hoho/dev/jdk/jdk1.7.0_79/bin/javaws" 3
sudo update-alternatives --install "/usr/bin/jar" "jar" "/home/lionelj/hoho/dev/jdk/jdk1.7.0_79/bin/jar" 3
sudo update-alternatives --install "/usr/bin/jarsigner" "jarsigner" "/home/lionelj/hoho/dev/jdk/jdk1.7.0_79/bin/jarsigner" 3
sudo update-alternatives --install "/usr/bin/javadoc" "javadoc" "/home/lionelj/hoho/dev/jdk/jdk1.7.0_79/bin/javadoc" 3

sudo update-alternatives --install "/usr/bin/java" "java" "/home/lionelj/hoho/dev/jdk/jdk1.6.0_45/bin/java" 2
sudo update-alternatives --install "/usr/bin/javac" "javac" "/home/lionelj/hoho/dev/jdk/jdk1.6.0_45/bin/javac" 2
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/home/lionelj/hoho/dev/jdk/jdk1.6.0_45/bin/javaws" 2
sudo update-alternatives --install "/usr/bin/jar" "jar" "/home/lionelj/hoho/dev/jdk/jdk1.6.0_45/bin/jar" 2
sudo update-alternatives --install "/usr/bin/jarsigner" "jarsigner" "/home/lionelj/hoho/dev/jdk/jdk1.6.0_45/bin/jarsigner" 2
sudo update-alternatives --install "/usr/bin/javadoc" "javadoc" "/home/lionelj/hoho/dev/jdk/jdk1.6.0_45/bin/javadoc" 2

sudo update-alternatives --install "/usr/bin/java" "java" "/home/lionelj/hoho/dev/jdk/jdk1.5.0_22/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/home/lionelj/hoho/dev/jdk/jdk1.5.0_22/bin/javac" 1
sudo update-alternatives --install "/usr/bin/jar" "jar" "/home/lionelj/hoho/dev/jdk/jdk1.5.0_22/bin/jar" 1
sudo update-alternatives --install "/usr/bin/jarsigner" "jarsigner" "/home/lionelj/hoho/dev/jdk/jdk1.5.0_22/bin/jarsigner" 1

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
sudo update-alternatives --config jar
sudo update-alternatives --config javadoc
sudo update-alternatives --config jarsigner


update-alternatives --install 

/usr/bin/java 에 심볼릭 링크를 걸어준다.

java의 이름으로 관리한다는 뜻이고.

1 은 번호다.


1, 2 두개를 설정했으니까 1, 2로 골라서 쓸 수 있다.


sudo update-alternatives --config java

를 하면 위에서 --install 옵션으로 만든 1, 2 중에 고를 수 있는 설정이 나온다.

Posted by Real_G