How to Use Multiple Java Versions in Windows: A Simple Tutorial
Blog Author: Anup G.
Managing multiple Java versions on Windows can be challenging, but jEnv simplifies it by allowing you to switch between various Java versions seamlessly. This tutorial will guide you through the step-by-step installation of jEnv on Windows.
Step 1: Install Java (If Not Installed)
Before installing jEnv, ensure you have Java installed on your system. You can download Java from:
After installation, verify Java installation by running:
java -version
If Java is installed correctly, it will display the installed version.
Step 2: Install Git Bash (Recommended)
Since jEnv is primarily Unix-based, using Git Bash provides a better shell-like environment on Windows.
The jEnv only works on Unix based terminals.
Step 3: Installing jEnv Manually
Since jEnv does not officially support Windows, you need to install it manually using Git.
Open Git Bash and run:
git clone https://github.com/jenv/jenv.git ~/.jenv
Add jEnv to the system PATH by modifying the ~/.bashrc file:
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(jenv init -)"' >> ~/.bashrc
Apply the changes:
source ~/.bashrc
If you see output as above, follow the Step 7 of the guide.
Step 4: Confirm jEnv Installation
To confirm jEnv is installed successfully, run:
jenv - version
If jEnv is installed correctly, it will display its version.
Step 5: Add Java Versions to jEnv
Now, manually add installed Java versions to jEnv.
Locate installed Java versions on your machine:
ls /c/Program\ Files/Java/
Add a Java version to jEnv:
jenv add "C:\Program Files\Java\jdk-XX.X.X"
(Replace jdk-XX.X.X with the actual installed version.) Set a global Java version: (Ensure to use exact names as shown when we run jenv versions)
jenv global jdk-XX.X.X
Set a local Java version for a specific project:
cd /path/to/project
jenv local jdk-XX.X.X
Verify the configured Java versions:
jenv versions
Step 6: Enable jEnv Plugins (Optional)
To automatically set Java environment variables, enable the export plugin:
jenv enable-plugin export
source ~/.bashrc
Step 7: Fix jEnv Path Issues
If you encounter issues like “Java binary in path is not in the jenv shims”, follow these steps:
Check the content of ~/.jenv/bin/jenv:
cat ~/.jenv/bin/jenv
It should output:
../libexec/jenv
If needed, modify the file using:
nano ~/.jenv/bin/jenv
Ensure it contains:
#!/usr/bin/env bash
exec "$(dirname "$0")/../libexec/jenv" "$@"
Reload the environment:
source ~/.bashrc
Verify jEnv status:
jenv doctor
If you see errors like:
[ERROR] Java binary in path is not in the jenv shims.
Try adding Java manually:
jenv add /c/Program\ Files/Java/jdk-XX.X.X
Step 8: Troubleshooting (If Needed)
If jEnv does not detect Java versions, try the following:
Ensure JAVA_HOME is correctly set in your ~/.bashrc:
echo 'export JAVA_HOME="$(jenv prefix system)"' >> ~/.bashrc
source ~/.bashrc
Conclusion
Congratulations! You have successfully installed jEnv on Windows. You can now effortlessly switch between multiple Java versions as needed.
If you found this tutorial helpful, feel free to share it! Need help? Leave a comment below!