Manage your Java environment

Related tags

Utility jenv
Overview

Master your Java Environment with jenv

Website : http://www.jenv.be

Maintainers :

Future maintainer in discussion:

As he makes an incredible work by taking time to merge the Pull Request on his fork, I (@gcuisinier) am in discussion with him to take part of jEnv directly if he wants. Whatever his decision, I thank him for his work, and to have convincing me to think about the future of jEnv and accepting a new maintainer for the good of the project.

What's jEnv ?

This is an updated fork of jenv, a beloved Java environment manager adapted from rbenv.

jenv gives you a few critical affordances for using java on development machines:

  • It lets you switch between java versions. This is useful when developing Android applications, which generally require Java 8 for its tools, versus server applications, which use later versions like Java 11.
  • It sets JAVA_HOME inside your shell, in a way that can be set globally, local to the current working directory or per shell.

However, this project does not:

  • Install java for you. Use your platform appropriate package manager to install java. On macOS, brew is recommended.

This document will show you how to install jenv, review its most common commands, show example workflows and identify known issues.

Contents

  1. Getting Started
  2. Example Workflows
  3. Known Issues

1. Getting Started

Follow the steps below to get a working jenv installation with knowledge of your java environment. Read all the code you execute carefully: a $ symbol at the beginning of a line should be omitted, since it's meant to show you entering a command into your terminal and observing the response after the command.

1.1 Installing jenv

On OSX, the simpler way to install jEnv is using Homebrew

brew install jenv

Alternatively, and on Linux, you can install it from source :

git clone https://github.com/jenv/jenv.git ~/.jenv
# Shell: bash
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
# Shell: zsh
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc

Restart your shell by closing and reopening your terminal window or running exec $SHELL -l in the current session for the changes to take effect.

To verify jenv was installed, run jenv doctor. On a macOS machine, you'll observe the following output:

$ jenv doctor
[OK]	No JAVA_HOME set
[ERROR]	Java binary in path is not in the jenv shims.
[ERROR]	Please check your path, or try using /path/to/java/home is not a valid path to java installation.
	PATH : /Users/user/.jenv/libexec:/Users/user/.jenv/shims:/Users/user/.jenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
[OK]	Jenv is correctly loaded

Observe that jenv is correctly loaded but Java is not yet installed.

To make sure JAVA_HOME is set, make sure to enable the export plugin:

jenv enable-plugin export
exec $SHELL -l

Problem? Please visit the Trouble Shooting Wiki page.

Continue to the next section to install java.

Untested: While this fork has improved fish shell support, it has not been tested by this maintainer. To install jenv for Fish according to the contributor's instructions:

echo 'set PATH $HOME/.jenv/bin $PATH' >> ~/.config/fish/config.fish
echo 'status --is-interactive; and source (jenv init -|psub)' >> ~/.config/fish/config.fish
cp ~/.jenv/fish/jenv.fish ~/.config/fish/functions/jenv.fish
cp ~/.jenv/fish/export.fish ~/.config/fish/functions/export.fish

1.2 Adding Your Java Environment

Use jenv add to inform jenv where your Java environment is located. jenv does not, by itself, install Java.

For example, on macOS, use brew to install the latest Java (OpenJDK 11) followed by the appropriate jenv add PATH_TO_JVM_HOME command to recognize it.

brew cask install java
jenv add $(/usr/libexec/java_home)

With macOS OpenJDK 11.0.2 installed, for example, either of these commands will add /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home as a valid JVM. Your JVM directory may vary!

Observe now that this version of Java is added to your java versions command:

$ jenv versions
* system (set by /Users/user/.jenv/version)
  11.0
  11.0.2
  openjdk64-11.0.2

By default, the latest version of Java is your system Java on macOS.

We'll now set a jenv local VERSION local Java version for the current working directory. This will create a .java-version file we can check into Git for our projects, and jenv will load it correctly when a shell is started from this directory.

$ jenv local 11.0.2
$ exec $SHELL -l
$ cat .java-version
11.0.2

Is JAVA_HOME set?

$ echo ${JAVA_HOME}
/Users/bberman/.jenv/versions/11.0.2

Yes! Observe that JAVA_HOME is set to a valid shim directory. Unlike the main repository's documentation we helpfully installed the export plugin, and we now have the most important jenv features covered.

If you executed this commands inside your $HOME directory, you can now delete .java-version:

rm .java-version

1.3 Setting a Global Java Version

Use jenv global VERSION to set a global Java version:

jenv global 11.0.2

When you next open a shell or terminal window, this version of Java will be the default.

On macOS, this sets JAVA_HOME for GUI applications on macOS using jenv macos-javahome. Integrates this tutorial to create a file that does not update dynamically depending on what local or shell version of Java is set, only global.

1.4 Setting a Shell Java Version

Use jenv shell VERSION to set the Java used in this particular shell session:

jenv shell 11.0.2

2 Common Workflows

These common workflows demonstrate how to use jenv to solve common problems.

2.1 Using Two JVMs on macOS

Our goal is to have both the latest version of Java and JDK 8 installed at the same time. This is helpful for developing Android applications, whose build tools are sensitive to using an exact Java version.

We'll resume where we left off with Java 11.0.2 installed. Let's install Java 8 now:

brew cask install adoptopenjdk8
brew cask install caskroom/versions/adoptopenjdk8

This will install the latest version of Java 8 to a special directory in macOS. Let's see which directory that is:

$ ls -1 /Library/Java/JavaVirtualMachines 
adoptopenjdk-8.jdk
openjdk-11.0.2.jdk

Observe the adoptopenjdk-8.jdk directory. Your exact version may vary. We cannot retrieve this using /usr/libexec/java_home, unfortunately. We'll add the Java home directory using jenv so that it shows up in our jenv versions command:

$ jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/
openjdk64-1.8.0.222 added
1.8.0.222 added
1.8 added
$ jenv versions
* system
  1.8
  1.8.0.222
  openjdk64-1.8.0.222
  11.0
  11.0.2
  openjdk64-11.0.2
  oracle64-1.8.0.202-ea

2.2 Other Workflows

Please contribute your own using a pull request!

3 Known Issues

Users seem to have issues using jenv with Fish. Please report any here.

Comments
  • Jenv not setting JAVA_HOME

    Jenv not setting JAVA_HOME

    Did I miss something; i'm trying to reset my JAVA_HOME with jenv and have tried all the command and it seems it is updating the values but not the JAVA_HOME?

    Any reason this should be happening?

    Thanks,

    Ian.

    Ians-MacBook-Pro:~ ian$ echo $JAVA_HOME
    /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
    Ians-MacBook-Pro:~ ian$ jenv local oracle64-1.7.0.45
    Ians-MacBook-Pro:~ ian$ jenv global oracle64-1.7.0.45 
    Ians-MacBook-Pro:~ ian$ jenv shell
    shell          shell-options  
    Ians-MacBook-Pro:~ ian$ jenv shell oracle64-1.7.0.45 
    Ians-MacBook-Pro:~ ian$ jenv version
    oracle64-1.7.0.45 (set by JENV_VERSION environment variable)
    Ians-MacBook-Pro:~ ian$ echo $JAVA_HOME
    /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
    Ians-MacBook-Pro:~ ian$ jenv versions
      system
      oracle64-1.6.0.65
    * oracle64-1.7.0.45 (set by JENV_VERSION environment variable)
      oracle64-1.8.0-ea
    Ians-MacBook-Pro:~ ian$ echo $JENV_VERSION
    oracle64-1.7.0.45
    Ians-MacBook-Pro:~ ian$ cat .java-version
    oracle64-1.7.0.45
    Ians-MacBook-Pro:~ ian$ ```
    
    
    opened by kellizer 89
  • jenv add

    jenv add "ln No such file or directory"

    MacOS 10.12.4

    I used Homebrew to install java with

    brew update
    brew cast install java
    

    and I checked the version of it as following.

    xxxx-MacBook-Pro:Home reapor.yurnero$ java -version
    java version "1.8.0_121"
    Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
    

    Then I tried jenv add jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home but it shows ln: /Users/reapor.yurnero/.jenv/versions/oracle64-1.8.0.121: No such file or directory So I'm confused which procedure am I wrong.

    opened by Reapor-Yurnero 17
  • JAVA_HOME not exported properly

    JAVA_HOME not exported properly

    After installing, and adding jdk's 8 and 9, then setting jenv global to 1.8, I get expected results when issuing jenv info java. java -version also outputs expected results. However, other tools that rely on JAVA_HOME are failing, and incorrectly referencing the wrong java version's home. I don't have any other variable exports anywhere. echo $JAVA_HOME returns a blank line.

    enhancement 
    opened by wkhatch 16
  • jenv: no such command `enable-plugin'

    jenv: no such command `enable-plugin'

    Hello, I'm facing a weird issue on my mac. Whenever I try:

    $> jenv enable-plugin maven                                                                                                         10:09  fbiville@VID01701
    jenv: no such command `enable-plugin'
    

    However,

    $> jenv help enable-plugin                                                                                                          10:09  fbiville@VID01701
    Usage: jenv enable-plugin <pluginName>
    
    Activate a jEnv plugin
    

    What's going on?

    opened by fbiville 16
  • I had to mkdir some directories after a homebrew intall.

    I had to mkdir some directories after a homebrew intall.

    $ brew install jenv ==> Downloading https://github.com/gcuisinier/jenv/archive/0.4.2.tar.gz

    ################################################################## 100.0%

    ==> Patching ==> Caveats To enable shims and autocompletion add to your profile: if which jenv > /dev/null; then eval "$(jenv init -)"; fi

    To use Homebrew's directories rather than ~/.jenv add to your profile: export JENV_ROOT=/usr/local/opt/jenv ==> Summary 🍺 /usr/local/Cellar/jenv/0.4.2: 74 files, 308K, built in 2 seconds $ jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home ln: /Users/paul/.jenv/versions/oracle64-1.6.0.65: No such file or directory

    The fix (for me):

    mkdir -p /Users/paul/.jenv/versions

    opened by paul-hammant 14
  • can't reset  JAVA_HOME from 1.7 to 1.8

    can't reset JAVA_HOME from 1.7 to 1.8

    When i run 'jenv shell 1.8' ,the java version is 1.8,but i found JAVA_HOME still is 1.7.I had set .zshrc like this "export JAVA_HOME="$HOME/.jenv/versions/jenv version-name" " 2015-04-01 9 14 25

    How can i fix it?

    opened by droid-Q 13
  • jenv

    jenv "~/.jenv/libexec/../completions/jenv.bash:15: command not found: complete"

    On ubuntu 14.04 with zsh, fresh install, when I start zsh after having followed the install instructions.

    Am I missing a dependency ? It is funny that it tries to use the bash completion though.

    opened by autra 12
  • jenv.bash - No such file or directory

    jenv.bash - No such file or directory

    I'm getting this error message whenever i fire up a terminal on Mac OS X mavericks:

    -bash: /usr/local/Cellar/jenv/0.2.0-201404260/libexec/../completions/jenv.bash: No such file or directory

    There is a line as the following when I run "jenv init -": source "/usr/local/Cellar/jenv/0.2.0-201404260/libexec/../completions/jenv.bash"

    there is no "jenv.bash" file under the whole jenv directory structure.

    thanks for the help.

    opened by ghost 11
  • Cannot add Java 8

    Cannot add Java 8

    Recently I've updated Java 8 and I wanted to add it to jenv and I cannot. After adding it is not being registered in jenv as 1.8:

    ➜  ~  jenv versions
    jenv: version `1.8' is not installed
      system
      1.7
      1.7.0.79
      oracle64-1.7.0.79
    ➜  ~  jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/
    oracle64-Picked added
    Picked added
    There is already a Picked JDK managed by jenv
    Do you want to override (type y to confirm)? y
    Picked added
    ➜  ~  jenv refresh-versions
    ➜  ~  jenv rehash
    ➜  ~  jenv versions
    jenv: version `1.8' is not installed
      system
      1.7
      1.7.0.79
      Picked
      oracle64-1.7.0.79
      oracle64-Picked
    
    ➜  ~  jenv --version
    jenv 0.4.3
    
    ➜  ~  jenv doctor
    [OK]    No JAVA_HOME set
    [OK]    Java binaries in path are jenv shims
    [OK]    Jenv is correctly loaded
    

    what can I do to fix that?

    bug 
    opened by antusus 10
  • Unable to add versions

    Unable to add versions

    I just installed jenv with Homebrew and updated ~/.bash_profile with:

    if which jenv > /dev/null; then eval "$(jenv init -)"; fi
    export JENV_ROOT="/usr/local/opt/jenv"
    

    Now this happens:

    $ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/
    ln: /usr/local/opt/jenv/versions/oracle64-1.8.0.51: No such file or directory
    
    opened by Zooce 9
  • Gradle plugin should work with gradlew as well

    Gradle plugin should work with gradlew as well

    Gradle plugin works fine but unfortunately it does not work with gradlew: https://docs.gradle.org/current/userguide/gradle_wrapper.html

    $ echo $JAVA_HOME
    /Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home
    
    $ jenv local
    1.7
    
    $ gradle --version
    ------------------------------------------------------------
    Gradle 2.11
    ------------------------------------------------------------
    [...]
    JVM:          1.7.0_79 (Oracle Corporation 24.79-b02)
    [...]
    
    $ gradlew --version 
    ------------------------------------------------------------
    Gradle 2.11
    ------------------------------------------------------------
    [...]
    JVM:          1.8.0_71 (Oracle Corporation 25.71-b15)
    [...]
    

    However enabling export plugin solves the issue.

    opened by jonatan-ivanov 7
  • jenv adds many different jdk's of the same version, but I don't install them

    jenv adds many different jdk's of the same version, but I don't install them

    Hi, when I use jenv add , jenv will add other jdk of the same version what is going on? Can I remove the extra ones?

    I only downloaded and installed zulu jdk 17 and zulu jdk 11, but when I use jenv add, it has more versions 11.0 and 11.0.17, why is that? Can I remove the ones I don't need?

    opened by AKmoex 1
  • Error when trying to add openjdk 11 installed with brew on MAC with M1 pro chip

    Error when trying to add openjdk 11 installed with brew on MAC with M1 pro chip

    When using jenv add $JAVA_HOME To add the path of openjdk11 installed with brew I get the bellow error: /opt/homebrew/Cellar/openjdk@11/11.0.17/bin is not a valid path to java installation

    opened by pablichjenkov 1
  • Bug: Azul 11 for M1 Mac fails to create 11.0 alias

    Bug: Azul 11 for M1 Mac fails to create 11.0 alias

    When I use jenv add for Azul 8 & 16 it installs all the proper aliases just fine. But for Azul 11, it reports: "11.0 already present, skip installation" but this is not correct. See the output of installing versions 8 & 11 below, and the 1 erroneous line. I'm using: jenv 0.5.5

    dwichers@MacBook-Pro brew % jenv add /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home zulu64-1.8.0.352 added 1.8.0.352 added 1.8 added 1.8.0.352 already present, skip installation dwichers@MacBook-Pro brew % jenv add /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home zulu64-11.0.17 added 11.0.17 added 11.0 already present, skip installation. <---- This is NOT CORRECT 11.0.17 already present, skip installation dwichers@MacBook-Pro brew % jenv versions

    • system (set by /Users/dwichers/.jenv/version) 1.8 1.8.0.352 11.0.17 16.0 16.0.2 zulu64-1.8.0.352 zulu64-11.0.17 zulu64-16.0.2
    opened by davewichers 0
  • Release new version of jenv

    Release new version of jenv

    Would it be possible to make a new release of jenv since https://github.com/jenv/jenv/pull/365 was merged? Without it there are still problems with using jenv on fish.

    opened by mdedetrich 0
  • Please provide some documentation for plugins

    Please provide some documentation for plugins

    There was minimal documentation provided by #31 but that was removed in https://github.com/jenv/jenv/commit/2be276c3a6dda70c86aedd01ccf23f08d300cd26. It would be good to know what plugins are for, and how to write them.

    opened by kstarsinic 0
Releases(0.5.5)
A tool ot export, analyse and visualize your transactions, rewards and commissions of your liquidity mining pools or DEX transactions

A tool ot export, analyse and visualize your transactions, rewards and commissions of your liquidity mining pools or DEX transactions.

Adam·Michael 15 Mar 11, 2022
Generate Heroku-like random names to use in your Java applications

HaikunatorJAVA Generate Heroku-like random names to use in your java applications. Installation To install Haikunator add the following to your maven

Atrox 29 Aug 28, 2022
A simple figura api extention that allow you to change your avatar, or upload it with script

A simple figura api extention that allow you to change your avatar, or upload it with script

null 4 Apr 14, 2022
Java lib for monitoring directories or individual files via java.nio.file.WatchService

ch.vorburger.fswatch Java lib for monitoring directories or individual files based on the java.nio.file.WatchService. Usage Get it from Maven Central

Michael Vorburger ⛑️ 21 Jan 7, 2022
Tencent Kona JDK11 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) with quarterly updates. Tencent Kona JDK11 is certified as compatible with the Java SE standard.

Tencent Kona JDK11 Tencent Kona JDK11 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) w

Tencent 268 Dec 16, 2022
This repository contains Java programs to become zero to hero in Java.

This repository contains Java programs to become zero to hero in Java. Data Structure programs topic wise are also present to learn data structure problem solving in Java. Programs related to each and every concep are present from easy to intermidiate level

Sahil Batra 15 Oct 9, 2022
An open-source Java library for Constraint Programming

Documentation, Support and Issues Contributing Download and installation Choco-solver is an open-source Java library for Constraint Programming. Curre

null 607 Jan 3, 2023
Java Constraint Programming solver

https://maven-badges.herokuapp.com/maven-central/org.jacop/jacop/badge.svg [] (https://maven-badges.herokuapp.com/maven-central/org.jacop/jacop/) JaCo

null 202 Dec 30, 2022
Java Constraint Solver to solve vehicle routing, employee rostering, task assignment, conference scheduling and other planning problems.

OptaPlanner www.optaplanner.org Looking for Quickstarts? OptaPlanner’s quickstarts have moved to optaplanner-quickstarts repository. Quick development

KIE (Drools, OptaPlanner and jBPM) 2.8k Jan 2, 2023
Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas

Arthas Arthas is a Java Diagnostic tool open sourced by Alibaba. Arthas allows developers to troubleshoot production issues for Java applications with

Alibaba 31.5k Jan 4, 2023
Java rate limiting library based on token/leaky-bucket algorithm.

Java rate-limiting library based on token-bucket algorithm. Advantages of Bucket4j Implemented on top of ideas of well known algorithm, which are by d

Vladimir Bukhtoyarov 1.7k Jan 8, 2023
Object-Oriented Java primitives, as an alternative to Google Guava and Apache Commons

Project architect: @victornoel ATTENTION: We're still in a very early alpha version, the API may and will change frequently. Please, use it at your ow

Yegor Bugayenko 691 Dec 27, 2022
Dex : The Data Explorer -- A data visualization tool written in Java/Groovy/JavaFX capable of powerful ETL and publishing web visualizations.

Dex Dex : The data explorer is a powerful tool for data science. It is written in Groovy and Java on top of JavaFX and offers the ability to: Read in

Patrick Martin 1.3k Jan 8, 2023
Google core libraries for Java

Guava: Google Core Libraries for Java Guava is a set of core Java libraries from Google that includes new collection types (such as multimap and multi

Google 46.5k Jan 1, 2023
Java regular expressions made easy.

JavaVerbalExpressions VerbalExpressions is a Java library that helps to construct difficult regular expressions. Getting Started Maven Dependency: <de

null 2.6k Dec 30, 2022
MinIO Client SDK for Java

MinIO Java SDK for Amazon S3 Compatible Cloud Storage MinIO Java SDK is Simple Storage Service (aka S3) client to perform bucket and object operations

High Performance, Kubernetes Native Object Storage 787 Jan 3, 2023
java port of Underscore.js

underscore-java Requirements Java 1.8 and later or Java 11. Installation Include the following in your pom.xml for Maven: <dependencies> <dependency

Valentyn Kolesnikov 411 Dec 6, 2022
(cross-platform) Java Version Manager

jabba Java Version Manager inspired by nvm (Node.js). Written in Go. The goal is to provide unified pain-free experience of installing (and switching

Stanley Shyiko 2.5k Jan 9, 2023
The shell for the Java Platform

______ .~ ~. |`````````, .'. ..'''' | | | |'''|''''' .''```. .'' |_________| |

CRaSH Repositories 916 Dec 30, 2022