8

I made my gitrepository and committed it. Inserted one java-file and wanted to to compile it ,but it gave me this:

Bernard@BERNARD-PC /c/users/bernard/desktop/git2 (master)
$ javac TestGUI.java
sh.exe": javac: command not found

It used to work in school on their computer,but at home on my laptop I cant make it work.

EDIT : I added javac as environment variable:enter image description here

EDIT : Short term solution for the duration of the runtime of gitbash enter:

 `export PATH=$PATH:"/C/Program Files/Java/jdk1.7.0_21/bin/"`

Long term solution so you can reuse this command after shutting down and rebooting gitbash: (for win7) Create a file called .bashrc under Users/username. Open with notepad and add 'export PATH=$PATH:"/C/Program Files/Java/jdk1.7.0_21/bin/"' Finished

BURNS
  • 711
  • 1
  • 9
  • 20
  • 1
    NOTE: Remove the backticks, or this won't work. On my system, it was: `export PATH=$PATH:"/C/Program Files/Java/jdk1.8.0_121/bin/"` (I tried to just remove redundant backticks in the answer above, but StackOverflow complained that it was a trivial edit <6 characters, so I added this explanation!) Also, Git Bash will complain that you have an incorrect setup, but that's OK as it will generate a `~/.bash_profile` to load your `~/.bashrc`. – Matt Obert Apr 08 '17 at 01:19

3 Answers3

11

You need to add javac parent folder to your PATH.

export PATH=$PATH:"/C/Program Files/Java/jdk1.7.0_21/bin/"

You can check what PATH your git bash shell does see (probably the default one).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thanks! :) Just one remaining question .When I exit gitbash and reboot it ,the command is lost. How can I set it up to remain there permanently? – BURNS Mar 09 '14 at 12:27
  • 2
    @BURNS you can register that export command in a `.bashrc` file in `C:\Users\YourUsername`. See also http://danlimerick.wordpress.com/2011/06/10/git-for-windows-tip-setting-shell-aliases-with-msysgit/ for instance. – VonC Mar 09 '14 at 13:00
  • I added a file with the command and put it under the folder with my username.http://postimg.org/image/iei1100hr/ It didnt work – BURNS Mar 09 '14 at 13:19
  • I named my bashrc file,and now i removed the name with the exception of the extension . It works now permanently. Many thx! :) – BURNS Mar 09 '14 at 14:02
  • 1
    @BURNS right, I didn't see your picture right aways, but the file is named `.bashrc`, not `file.bashrc` :) – VonC Mar 09 '14 at 14:03
0

As suggested by @VonC in a comment in the correct answer in order to have this this command permanently added to the path you have to:

  1. Go to C:\Users\YourUsername
  2. Open with an editor the file .bashrc (if is not there just create it)
  3. Write the command to add the command to your path in this file:

    export PATH=$PATH:"/C/Program Files/Java/jdk1.7.0_21/bin/"

  4. Restart GitBash and it works
rakwaht
  • 3,666
  • 3
  • 28
  • 45
0

The other answers did not work for me. What DID work (Windows 10) was:

  1. Go to System Properties -> Advanced -> Environment Variables
  2. New System Variable
  3. 'Variable name': PATH
  4. 'Variable value': C\Program Files\Java\jdk-9\bin (or whatever your path is)
  5. Restart Git Bash
andydavies
  • 3,081
  • 4
  • 29
  • 35