How to Run Multiple Versions of All Your Dev Tools with Jenv
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.
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
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.