How do you set the java version to use in a windows git bash? Does it work via the environment variables? Java -version gives another version in dos command prompt than in git bash...
How do you set the java version to use in a windows git bash? Does it work via the environment variables? Java -version gives another version in dos command prompt than in git bash...
Let's say you want to try other Java versions but you don't want to alter the Windows environment variables.
Steps:
Edit the .bashrc file and add the following code below.
#For example:
export JAVA_HOME='/c/Program Files (x86)/Java/jdk1.8.0_45'
export PATH=$JAVA_HOME/bin:$PATH
.bashrc and .bash_profile are files created during the git-bash installation.
Yes the environment variables affect which java is used in Git Bash. But if setting the $JAVA_HOME and $PATH variables doesn't seem work, try this:
Now set the PATH variable as described in the other answers. I.e.
export JAVA_HOME='{yourjavahome}'
Restart Git Bash.
This is what worked for me. I'm using Git for Windows v2.17.0.
Go the location where you want to set java path temporarily. Run below command. export PATH="/c/Program Files/Java/jdk-11.0.1/bin:$PATH"
User the jdk version you want in place of jdk-11.0.1