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:
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.
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.
Go to System Properties -> Advanced -> Environment Variables
New System Variable
'Variable name': PATH
'Variable value': C\Program Files\Java\jdk-9\bin (or whatever your path is)
Restart Git Bash
(Windows 10)
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:
Go to the folder where Git Bash is installed (usually C:\Program Files\Git)
Go to usr/bin folder, i.e. C:\Program Files\Git\usr\bin
There should be a file named "java" there. Rename it to "notjava".
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
Related
I'm using Windows and Git Bash. Whenever I type a javac command in Git Bash, it comes back reading: sh.exe":javac: command not found.
I then have to type out export PATH=$PATH:"/c/Program Files/Java/jdk1.8.0_45/bin/" The javac command then works on the next line after I type the export PATH command in.
My question is, how do I get Git Bash to remember that export command so I don't have to type it out each time?
You need to add export PATH command to .bashrc for Git Bash. Refer to this
Git for Windows: .bashrc or equivalent config files for Git Bash shell
Edit: Adding code
copy > ~/.bashrc
Add the following line to the file:
export PATH=$PATH:"/c/Program Files/Java/jdk1.8.0_45/bin/"
Save the file. Restart Git Bash. Tada
Try physically adding that path to the system environment variables from the control panel.
Search for 'system environment variables' --> go into Environment Variables --> look for [Path] from System Variables --> Click to highlight [Path] and hit Edit.
Depending on your computer, you might see a list of paths added, or a long string of paths separated by semi-colons. Copy and paste your java bin location.
I have tortoiseSVN installed alongside subversion for windows (not using TortoiseSVN command client tools because of restrictive purposes).
I have a batch file that runs an svn update on certain folders which are used as environmental variables in Windows. Is it possible to svn update a folder using just the folder name?
e.g. from this:
cd C:\foo\johnsmith\testing\
svn update
to something like this?
cd testing\
svn update
I should add that environmental variables are new to me...
With regards to Alrocs comment, the path C:\foo\johnsmith\testing\ is in the system environmental variable "Path".
You can't cd to directory, which is part of your $PATH$. But you can use environment variable, which explicitly contain needed path only (after all - variable is just string)
c:\TEMP>echo "%USERPROFILE%"
"C:\Documents and Settings\Badger"
c:\TEMP>cd "%USERPROFILE%"
C:\Documents and Settings\Badger>
Never assume anything about environment variables that you haven't set via your batch file. Just because it's there today/on your computer doesn't necessarily mean it'll be there tomorrow or on another computer.
But you aren't using an environment variable in your script in the first place.
If you need to update a specific path, be explicit and update that path by specifying the whole path. Don't assume that your testing directory will be an immediate child of the directory you're running the batch file in unless you can control everything else - the whole subdirectory structure, where the batch file executes from, and how it executes.
I am starting with spring-roo, so I downloaded it and now I'm trying to export the variable.
To get it, I tried:
PATH=$PATH:/Users/myUsr/spring-roo/bin
export PATH
PATH variable
my-Name-3:~ myUsr$ echo $PATH
/sw/bin:/sw/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/X11R6/bin:/Users/myUsr/spring-roo/bin
In this path (/Users/myUsr/spring-roo/bin), there is roo.sh
But then, I can not run the command roo as it is supposed to be.
You are not supposed to be able to run a command roo (no .sh), when all you have is roo.sh. Run roo.sh instead. There is no magic dropping of extensions in Unix.
Are you in the directory where the root.sh is ? Just give a try by being in that directory to run the shell script. Also check the permissions of the file.
if my windows path looks like this:
c:\ruby\bin;c:\cygwin\bin
then when i go into cgywin and enter "ruby" it will execute the ruby from c:\ruby\bin, failing to find the ruby installed in my cygwin. I have to exclude that path so cygwin would execute the one from /usr/bin.
But i need those 2 paths, since i want to run ruby in windows too.
Anyway to have cygwin have its own path and not inherit those in windows?
thanks.
Add an entry into your .profile to set the path to whatever you want it to be in cygwin.
In cygwin run the command:
$ <favourite text editor eg vi> ~/.profile
Then set the PATH environment variable to whatever you want it to be e.g.:
export PATH=/cygdrive/c/cygwin/bin
NOTE I can't remember whether you can use the c:... version of the path, but if you issue the env command you will see what it should be.
I'm on a Mac and I'm trying to make a Vim plugin for compiling/running actionscript files.
First, I need to run mxmlc on the command line, but to do that I have to keep on typing the path to it. Where do I place it so that I don't have to retype the path?
You need to modify your "$PATH" environment variable, so that the tool is in that directory. However, if you want to make this very easy... you can download my macosx-environment-setup.tar.bz2 program. If you execute the "install.sh" script using "sudo ./install.sh", it will setup your environment in such a way that if you use "/Library/Flex4SDK" as the location for the Flex4SDK, it will automatically find it, define FLEX_HOME to point to that location, and it will also ensure that the binaries from the Flex4SDK are in your PATH.
Side Note: This is up on the web, because I use it in my Development Environment Setup How-To Guides. If you aren't too keen about running "sudo ./install.sh", you need to choose a location (I am going to assume "/Library/Flex4SDK", so that the tools are located in "/Library/Flex4SDK/bin"), and then you would simply need to edit your "~/.profile" file (using "nano ~/.profile"), adding the following to the very end:
export FLEX_HOME=/Library/Flex4SDK
export PATH="$PATH":"$FLEX_HOME/bin"
Note that these changes occur in your shell... they will not affect programs that are launched by double-clicking them in Finder. In order to affect those programs, you will need to place the environment variables in a file named ~/.MacOSX/environment.plist. See Automatically build ~/.MacOSX/environment.plist for a script that will automatically generate such a file using the current environment variables defined in your shell.
There are a few ways to answer this:
In one of your directories searched
by PATH (see the list with echo
$PATH)
Add a new directory to PATH
(e.g. in your ~/.bashrc
export PATH=$PATH:/path/to/bindir)
Add an
alias to your program (e.g. in your
~/.bashrc alias
mxmic=/path/to/mxmic)
(I'm assuming you're using bash shell, which is usually the case you can check with echo $SHELL)