How to Run Multiple Versions of All Your Dev Tools with Jenv

Share this article

How to Run Multiple Versions of All Your Dev Tools with Jenv

Key Takeaways

  • Jenv is a platform-independent tool ideal for managing multiple installs of Java-based applications such as Maven, Gradle, and Tomcat. It allows you to easily install several versions of these tools side by side and select which one to use system-wide or on an individual shell.
  • Installing a new tool with Jenv is straightforward, involving a single command that identifies the latest version of the tool, downloads it, installs it onto the local system, and configures the local system to use this version of the tool as the default. You can also install a specific version by specifying the version number.
  • Jenv also makes it simple to switch between different versions of a tool. You can change the version for a specific shell or set a default version to be used across all shells. This is particularly useful when working on multiple projects at the same time or when you want to quickly test a specific version.

Table of Contents

If you need a platform independent tool that allows you to manage multiple installs of Java-based applications such as Maven, Gradle, and Tomcat, then jenv is the right choice. With jenv you can easily install several versions side by side and easily pick which one to use system-wide or just on an individual shell. That makes building one project with Maven 3.1 and another with 3.5 as easy as pie.

Introducing jenv

The Java Ecosystem has a large number of tools that you may want to use – ranging from Java itself, to build tools such as Maven and Gradle, to third party applications such as ActiveMQ and Tomcat. Often, you will have a need for different versions of these tools in different projects, or a desire to try a project in different versions for compatibility testing.

Managing these different versions can be a complicated task. Each tool will have different ways to obtain them, to install them, to control which version is being used, to generally do everything with.

Thankfully, there exists a tool that can make life a lot easier in this regard: jenv (not to be confused with jEnv, which sets JAVA_HOME). The tool – available on Windows, Mac, and Linux – makes it really easy to manage multiple versions of a large number of Java-based tools. At time of writing this can work with over 200 different tools that you might want to use.

Installation of jenv varies depending on the platform you are using, but the website gives clear instructions on exactly how to do this. While all examples are written from the point of view of a Mac, they are equally applicable to any supported system.

Installing a New Tool

Installing a new tool is as simple as:

$ gradle
-bash: gradle: command not found

$ jenv install gradle
Installing: gradle 3.5
Parsing http://jenv.mvnsearch.org/candidate/gradle/download/3.5/Darwin/x86_64

Downloading: gradle 3.5

Downloading http://get.jenv.mvnsearch.org/download/gradle/gradle-3.5.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 69.8M  100 69.8M    0     0   390k      0  0:03:03  0:03:03 --:--:--  350k

Do you want gradle 3.5 to be set as default? (Y/n): y
Setting gradle 3.5 as default.
Done installing!

This has, in one single command:

  • determined the latest version of the tool
  • downloaded the tool
  • installed it onto the local system
  • configured the local system to use this version of the tool as the default

And it works:

$ gradle
Starting a Gradle Daemon (subsequent builds will be faster)
:help

Welcome to Gradle 3.5.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

To see more detail about a task, run gradle help --task <task>

BUILD SUCCESSFUL

Total time: 2.691 secs

Installing a Specific Version of a Tool

If, instead, you want to install a specific version of a tool you would do:

$ jenv install tomcat 7.0.68
Installing: tomcat 7.0.68
Parsing http://jenv.mvnsearch.org/candidate/tomcat/download/7.0.68/Darwin/x86_64

Downloading: tomcat 7.0.68

Downloading http://get.jenv.mvnsearch.org/download/tomcat/tomcat-7.0.68.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 9268k  100 9268k    0     0   233k      0  0:00:39  0:00:39 --:--:--  342k

Do you want tomcat 7.0.68 to be set as default? (Y/n): n
Done installing!

Exactly the same as above, but by specifying a version number then this is the version that we get.

Seeing What Versions Are Available to Install

In order to install a specific version, you might need to know what the options are. This is possible simply by:

$ jenv ls maven
Available maven Versions
=========================
>* 3.5.0
 * 3.3.9
 * 3.3.3
   3.3.1
 * 3.2.5
   3.2.3
   3.2.2
   3.2.1
   3.1.1
   3.1.0
   3.0.5-mvnsearch
 * 3.0.5
 * 3.0.4
   2.2.1
   2.0.11

This list actually shows three different things in one:

  • every row is a version that is supported by jenv
  • every row with an asterisk next to it is already downloaded and ready to use
  • the row with an arrow next to it is the version that is currently in use

So the above shows that I have downloaded Maven 3.5.0, 3.3.9, 3.3.3, 3.2.5, 3.0.5 and 3.0.4, and that I am currently using 3.5.0.

Switching Versions of a Tool

When you have multiple versions installed and you need to change from one to the other, this is achieved as follows:

$ jenv use maven 3.0.4
Using maven(3.0.4) in this shell.

One thing to note is that this changes it for this shell. Any other sessions that you have open will be unaffected by this command, making it perfectly safe to use any time you want to do a quick test, or when working on multiple projects at the same time.

Changing the default version – used across all shells – is done instead by running:

$ jenv default maven 3.5.0
Default maven version set to 3.5.0

Using jenv to sort out tools

Summary

The jenv tool makes it painless to install Java based tools on your system (with jenv install), and to switch versions for specific use cases (jenv use). This article has given a very quick introduction to what can be achieved with this tool, but there is plenty more that it can help with. Be sure to read the website and the help for the tool, and finally stop stressing over managing your Java tool chains.

Frequently Asked Questions (FAQs) about Multiple Versions of Dev Tools with Jenv

How do I install Jenv on my Windows system?

To install Jenv on a Windows system, you first need to have Git installed. Once Git is installed, open Git Bash and clone the Jenv repository using the command: git clone https://github.com/jenv/jenv.git ~/.jenv. Then, add Jenv to your bash profile by adding the following lines to your .bashrc file: export PATH="$HOME/.jenv/bin:$PATH" and eval "$(jenv init -)". Finally, restart your terminal for the changes to take effect.

How can I use Jenv to manage multiple versions of Java?

Jenv allows you to easily switch between different versions of Java. To add a Java version to Jenv, use the command: jenv add /path/to/java. You can then set the global Java version with: jenv global oracle64-1.7.0.79. To set the Java version for a specific directory, navigate to that directory and use: jenv local oracle64-1.7.0.79.

Can I use Jenv with other development tools besides Java?

Yes, Jenv can be used with any development tool that requires version management. This includes tools like Maven, Gradle, and many others. You can add these tools to Jenv in a similar way to adding Java versions.

How do I uninstall a version of a tool from Jenv?

To uninstall a version of a tool from Jenv, you simply need to delete the corresponding directory from the .jenv/versions directory. For example, to uninstall Java version 1.7.0.79, you would use the command: rm -rf ~/.jenv/versions/oracle64-1.7.0.79.

How can I list all the versions of a tool managed by Jenv?

You can list all the versions of a tool managed by Jenv using the jenv versions command. This will display a list of all the versions that have been added to Jenv, along with an asterisk next to the currently active version.

How do I update Jenv to the latest version?

To update Jenv to the latest version, you can use the git pull command from within the .jenv directory. This will pull the latest changes from the Jenv repository and update your local copy.

Can I use Jenv to manage versions of tools on a per-project basis?

Yes, Jenv allows you to set the version of a tool for a specific project by creating a .java-version file in the project’s root directory. This file should contain the version number of the tool you want to use for that project.

How do I troubleshoot issues with Jenv?

If you’re having issues with Jenv, you can use the jenv doctor command to diagnose common problems. This command will check your Jenv installation and configuration and provide suggestions for fixing any issues it finds.

Can I use Jenv with other version management tools?

Yes, Jenv can be used alongside other version management tools like RVM, NVM, and Pyenv. However, you should be aware that these tools may conflict with each other if they are managing the same versions of the same tools.

How do I remove Jenv from my system?

To remove Jenv from your system, you need to remove the Jenv directory and the lines added to your .bashrc file during installation. The Jenv directory can be removed with the command: rm -rf ~/.jenv. The lines in your .bashrc file can be removed using a text editor.

Graham CoxGraham Cox
View Author

Graham Cox is a Software Developer from the UK who has been writing software for almost 15 years, predominantly using Java and Javascript but also covering a wide variety of other languages.

tools
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week