Gangmax Blog

JVM: The Java Version Manager

jvm“ is a version manager for Java like RVM for Ruby or pyenv for Python. The following code shows how to use it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 1. Install more than one Java versions(via Ubuntu PPAs by "webupd8").
sudo apt-get install \
oracle-java7-installer oracle-java7-unlimited-jce-policy \
oracle-java8-installer oracle-java8-unlimited-jce-policy \
oracle-java9-installer oracle-java9-unlimited-jce-policy
# The above command will install 3 Java versions under the following
# paths in my environment:
ls /usr/lib/jvm/java-7-oracle/
ls /usr/lib/jvm/java-8-oracle/
ls /usr/lib/jvm/java-9-oracle/

# 2. Install jvm.
git clone https://github.com/caarlos0/jvm.git ~/.jvm
echo ".java-version" >> ~/.gitignore

# 3. Modify my "zshrc". If you use bash, write to ".bashrc".
echo "source ~/.jvm/jvm.sh" >> ~/.zshrc

# 4. Create "~/.jvmconfig" file with the following content:
7=/usr/lib/jvm/java-7-oracle
8=/usr/lib/jvm/java-8-oracle
9=/usr/lib/jvm/java-9-oracle

# 5. Set the JVM version you want to use:
# Set Java 7 as default:
jvm global 7
# Check if the setting works:
jvm version
which java
java -version
# Set Java 9 as default:
jvm global 9
# Check if the setting works:
jvm version
which java
java -version

Comments