Sasi Kathimanda
Sasi Kathimanda

Reputation: 1806

Jenv - same java version added multiple times

I am using Jenv to manage multiple java version on My MacBook(OS X Yosemite).

jenv add /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
oracle64-1.6.0.65 added
1.6.0.65 added
1.6 added

and while adding Java 1.8

jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
oracle64-1.8.0.60 added
1.8.0.60 added
1.8 added

and jenv version show multiple line of the same version infact it is one version?

jenv versions

    * system (set by /Users/$USERNAME/.jenv/version)
      1.6
      1.6.0.65
      1.8
      1.8.0.60
      oracle64-1.6.0.65
      oracle64-1.8.0.60

Upvotes: 11

Views: 3448

Answers (4)

Barnesly
Barnesly

Reputation: 93

This is an intentional feature of jenv which allows you to work with multiple major versions of Java by allowing you to use versions depending on the specificity you require.

To see where all your aliases point you can run jenv versions --verbose.

In general you probably just want to specify the major version for a project/shell/globally (e.g. 1.8) but maybe in one project you need a specific version (e.g. 1.8.0.272) in which a JVM bug is fixed. Similarly you can have one project you want to build against openjdk 1.8 and another you want to build against corretto 1.8.

If you want to cleanup the more specific aliases you can use a command like below which would leave you with just 1.6 and 1.8

jenv remove 1.6.0.65 oracle64-1.6.0.65 1.8.0.60 oracle64-1.8.0.60

Upvotes: 0

Andrey Lebedenko
Andrey Lebedenko

Reputation: 1988

You can always add/remove/change aliases in your ~/.jenv/versions folder. Those are just links.

Upvotes: 3

djangofan
djangofan

Reputation: 29689

I wrote a script to handle my JEnv environment.

# configure Java  http://www.jenv.be/
# install Java: brew cask install java, brew cask install java7
# set global default: setJavaGlobal 1.7, jenv global 1.7
# set local folder default: jenv local 1.8
# 
JENV_HOME=$HOME/.jenv
export PATH=.:$PATH:$JENV_HOME/bin
eval "$(jenv init -)"
#export JAVA_HOME=$(/usr/libexec/java_home)
export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"
alias jenv_set_java_home='export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"'
setJavaGlobal() { 
  jenv global $1;
  jenv_set_java_home
  echoJavaSetup
}
setJavaLocal() { 
  jenv local $1;
  jenv_set_java_home
  echoJavaSetup
}
echoJavaSetup() {
  echo --------------------
  echo NEW JAVA SETUP:
  echo "  PATH: $PATH"
  export JAVA_VERSION=`java -version 2>&1 >/dev/null | grep 'java version' | awk '{print $3}'`
  echo "  JAVA: $JAVA_VERSION, $JAVA_HOME"
  jenv versions
  echo --------------------
}
removeJavaLocal() {
  rm -rf ./.java-version
}
showJava() {
  echo --------------------
  echo EXISTING JAVA SETUP:
  echo "  PATH: $PATH"
  export JAVA_VERSION=`java -version 2>&1 >/dev/null | grep 'java version' | awk '{print $3}'`
  echo "  JAVA: $JAVA_VERSION, $JAVA_HOME"
  jenv versions
  if [ -f ./.java-version ]; then
    echo "Using Java LOCAL DEFAULT.  Not using global default!  Run command 'removeJavaLocal' to change to global default."
  fi
  echo --------------------
}

Upvotes: 1

Vishwaksena
Vishwaksena

Reputation: 422

If you look inside the .jenv folder you can see all the three different instances of the same version.

Upvotes: 2

Related Questions