Website : http://www.jenv.be
jenv is for a equivalent of rbenv, but for Java environment. It allow to easily switch between several JDKs installations (already presents), and configure which one to use per project.
jEnv may work on bash-ready OS.
Verified on :
- Mac OS X
- Debian
-
Check out jenv into
~/.jenv
.$ git clone https://github.com/gcuisinier/jenv.git ~/.jenv
-
Add
~/.jenv/bin
to your$PATH
for access to thejenv
command-line utility.$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
Ubuntu note: Modify your
~/.profile
instead of~/.bash_profile
.Zsh note: Modify your
~/.zshrc
file instead of~/.bash_profile
.Fish note: Modify your `~/.conf/fish/config.sh' to append
set PATH $HOME/.jenv/bin $PATH
-
Add
jenv init
to your shell to enable shims and autocompletion.$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
Same as in previous step, use
~/.profile
on Ubuntu,~/.zshrc
for Zsh.Fish note: Instead, copy
~/.jenv/fish/jenv.fish
to~/.conf/fish/function/jenv.fish
. If you don't have theexport
function, also copyexport.fish
cp ~/.jenv/fish/jenv.fish ~/.conf/fish/function/jenv.fish cp ~/.jenv/fish/export.fish ~/.conf/fish/function/export.fish
-
Restart your shell as a login shell so the path changes take effect. You can now begin using jenv.
$ exec $SHELL -l
-
Configure JVM in jenv
$ jenv add /path/to/java/home
-
Configure which JVM to use (globally, by directory or for the current shell instance)
$ jenv global oracle-1.7.0
or
$ jenv local oracle-1.7.0
or
$ jenv shell oracle-1.7.0
-
Check that works
$ java -version
-
Add JVM Options (globally, by directory or for the current shell instance)
$ jenv global-options "-Xmx512m"
or
$ jenv local-options "-Xmx512m"
or
$ jenv shell-options "-Xmx512m"
-
Check that works
$ jenv info java
-
jenv also provides wrappers for several build tools (Ant, Gradle, Maven, SBT) that will use the configured JVM Options (globally, by directory or for the current shell instance), unless the tool's environment variable is already set (e.g.
ANT_OPTS
for Ant).
Like git
, the jenv
command delegates to subcommands based on its
first argument. The most common subcommands are:
Sets a local application-specific Java version by writing the version
name to a .java-version
file in the current directory. This version
overrides the global version, and can be overridden itself by setting
the JENV_VERSION
environment variable or with the jenv shell
command.
$ jenv local oracle-1.7
When run without a version number, jenv local
reports the currently
configured local version. You can also unset the local version:
$ jenv local --unset
Previous versions of jenv stored local version specifications in a
file named .jenv-version
. For backwards compatibility, jenv will
read a local version specified in an .jenv-version
file, but a
.java-version
file in the same directory will take precedence.
Sets the global version of Java to be used in all shells by writing
the version name to the ~/.jenv/version
file. This version can be
overridden by an application-specific .java-version
file, or by
setting the JENV_VERSION
environment variable.
$ jenv global oracle-1.6
The special version name system
tells jenv to use the system Java
(detected by searching your $PATH
).
When run without a version number, jenv global
reports the
currently configured global version.
Sets a shell-specific Java version by setting the JENV_VERSION
environment variable in your shell. This version overrides
application-specific versions and the global version.
$ jenv shell jJava-1.7.1
When run without a version number, jenv shell
reports the current
value of JENV_VERSION
. You can also unset the shell version:
$ jenv shell --unset
Note that you'll need jenv's shell integration enabled (step 3 of
the installation instructions) in order to use this command. If you
prefer not to use shell integration, you may simply set the
JENV_VERSION
variable yourself:
$ export JENV_VERSION=oracle-1.6
Lists all Java versions known to jenv, and shows an asterisk next to the currently active version.
$ jenv versions
oracle-1.6
* oracle-1.7 (set by /Users/hikage/.jenv/version)
Displays the currently active Java version, along with information on how it was set.
$ jenv version
oracle-1.6 (set by /tmp/test/.java-version)
Installs shims for all Java executables known to jenv (i.e.,
~/.jenv/versions/*/bin/*
). Run this command after you install a new
version of Java.
$ jenv rehash
Displays the full path to the executable that jenv will invoke when you run the given command.
$ jenv which java
/Users/sam/.jenv/versions/oracle-1.6/bin/java
Lists all Java versions with the given command installed.
$ jenv whence java
oracle-1.6
oracle-1.7
Jenv provides plugins to make command-line tools aware of which JDK is activated.
$ jenv plugins
ant
golo
gradle
grails
groovy
lein
maven
sbt
scala
vlt
Let's say you want Maven to use the JDK activated with Jenv, not the default JAVA_HOME
configuration. You need to activate Jenv's maven plugin.
$ jenv enable-plugin maven
maven plugin activated
$ jenv disable-plugin maven
maven disabled
Note: The enable-plugin functionality is system wide not local to the shell, or temporary - you only need to do each one once.
The jenv source code is hosted on GitHub. It's clean, modular, and easy to understand, even if you're not a shell hacker.
It is based on rbenv.
Please feel free to submit pull requests and file bugs on the issue tracker.