Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set java version in windows 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...

like image 265
Lieven Cardoen Avatar asked Jul 30 '12 14:07

Lieven Cardoen


2 Answers

Let's say you want to try other Java versions but you don't want to alter the Windows environment variables.

Steps:

  • Go to your home folder. i.e. C:\Users\MyAccountName
  • 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.

like image 180
Kim G. Avatar answered Oct 16 '22 03:10

Kim G.


You don't set the java version. You are seeking the $PATH (bash) and the %PATH% (Windows/DOS/cmd.exe) environment variables. When you run the command java -version, the shell searches the directories on the $PATH to locate the java program and run it with the given arguments. If you get different results in different shells then that means you have different PATHs such that a different installation of Java is found.

like image 22
dsh Avatar answered Oct 16 '22 05:10

dsh