javac command not found in Git Bash - windows

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.

Related

Warning on git bash start "bash: C:/Users/RS3/Anaconda3/etc/profile.d/conda.sh: No such file or directory"

Whenever I open git bash I get the following warning:
bash: C:/Users/RS3/Anaconda3/etc/profile.d/conda.sh: No such file or directory
The problem is that I uninstalled Anaconda, because I installed independent python, which resulted in giving that error.
How to remove this Warning.
Check the content of ~/.bashrc (which was mentioned here)
Maybe that (or ~/.profile, mentioned here) includes a command for that old uni uninstalled program.
Remove those lines, and try to open again a git bash session.
To remove that warning, simply erase the file path string in the .bashrc file using nano command. Here's how:
Steps to remove that warning:
Open Git Bash and check .bashrc location by typing ~/.bashrc into git bash.
Navigate to folder where .bashrc file is located.
Type nano .bashrc
Erase the string that says C:/Users/RS3/Anaconda3/etc/profile.d/conda.sh
Press ctrl+O to save .bashrc file and then ctrl+X to exit.
When you reopen git bash nothing should appear because .bashrc doesn't have that path in it anymore. Also, if conda commands were working before it will still continue to work after erasing this.

How to install Dart to be used in the terminal? (command line)

How do you install Dart so the language can be used within the terminal? (For UNIX based systems, such as a Mac)
After installing Dart (currently located at https://www.dartlang.org/), you will need to do some additional work to use dart commands in the terminal (command line), as it needs to be added to the Bash profile PATHs (on a UNIX based system). To do this, run the following handy command to open the .bash_profile file in it’s default location and with the system’s default text editor touch ~/.bash_profile; open ~/.bash_profile.
Next find the directory that Dart was downloaded to and put the path for dart-sdk/bin inside the .bash_profile as apart of the PATH variable. I.e. a line of code should be added to this file that looks something like this (if you’ve put the dart install in the applications folder on a Mac): export PATH=$PATH:/Applications/Dart/dart-sdk/bin.
To get Bash to start using this new profile immediately without restart, enter source ~/.bash_profile in the terminal (command line), then to double check the PATHs have updated, by enter in the command echo $PATH.
1) Install Dart in your environment (if have not yet)
https://www.dartlang.org/tools/sdk#install
2) Add PATH variable for dart/bin
Example for Ubuntu
# add path example
echo 'export PATH="$PATH:/usr/lib/dart/bin"' >> ~/.bashrc
source .bashrc
or it can be .bash_profile instead of .bashrc
3) And now just run your .dart file with the main() method in the terminal and see an output
$ dart path_to_your_file/your_file_with_main.dart

How to add a directory to PATH in the file .bashrc?

After installing python(EPDFee), I want to add the /bin directory to $PATH variable. I am use bash shell. I have found that I have to add the following line in the file .bashrc
export PATH=/home/usrname/epd/bin:$PATH
I have found the file .bashrc, it reads
PATH=$PATH:/opt/bin
# Added by Canopy installer on 2014-03-29
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source /home/an/Enthought/Canopy_64bit/User/bin/activate
Could you please tell me where can I add export PATH=/home/usrname/epd/bin:$PATH to or is should be added in another file?
add the following line to your .bashrc file ...don't forget to replace your path.
export PATH="/path/directory:$PATH"
then do
source .bashrc
to let the changes make effects. I am not sure about other distributions of Linux but It will work on CentOS and RedHat.
You can do it like this :
Define a EPD_HOME var and append it to PATH
EPD_HOME=/home/usrname/epd/bin
PATH=$PATH:$EPD_HOME:$HOME/bin
export PATH
Notice that the $EPD_HOME variable is in the PATH variable and is now loaded once you open a connection to your user on the machine.

Invoking notepad++ from Git Bash

I am using msysgit in Windows 7. How do I invoke notepad++ from Git Bash, like we do it with our default notepad?
Like for example
name#usename notepad textfile.txt
Instead I want the file to open with notepad++.
Note : I've added notepad++ to my PATH, but still unable to invoke it from commandline.
Edit
I tried this in .gitconfig -->
[alias] notepad='C:/Program Files/Notepad++/notepad++.exe'
but isn't working.
So, by default you won't have a .bashrc file so just navigate your to your home directory by typing:
cd ~
create or edit the .bashrc with vim (or whatever editor you are comfortable with):
vim .bashrc
Here is the line I had to add to mine (I am running a 64 bit OS so if you aren't don't copy this exactly)
alias notepad="/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"
If your copy of windows is 32 bit then it should look like this
alias notepad="/c/Program\ Files/Notepad++/notepad++.exe"
Finally, close and reopen your terminal/bash (or, as noted, run source ~/.bashrc), and voila!
these are the faster ways to achieve the goal
start notepad++
start notepad++ <filename>
alias np='start notepad++'
np <filename>
tried and tested, just do it!
I added this for my 64-bit machine with 32-bit Notepad++.
$ cd ~
$ vim .bash_profile
Add this to the file then save:
64-bit systems
alias npp="/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"
32-bit systems
alias npp="/c/Program\ Files/Notepad++/notepad++.exe"
Now you should be able to open any file with notepad++ by entering
$ npp [file_name]
I believe git-bash is an actual bash shell, so when it starts, it runs a .bashrc file from somewhere (most likely your home directory or the directory git-bash starts in). Look for that file, and when you find is, add an alias line somewhere for notepad++:
alias notepad="/c/Program\ Files/Notepad++/notepad++.exe"
Of course use your actual path to Notepad++ there.
#SageMage's answer is right on spot.
Just a reminder. You need to close and reopen GitBash after after you make a change in .bashrc in order for it to be activated.
PS: After two years, I hope this helped!
The below is listed on Udacity's course on Git and GitHub. It worked for me:
Run the following command in Git Bash after checking the location of
Notepad++ on your PC.
echo 'alias npp="C:/Program\ Files\ \(x86\)/Notepad\+\+/notepad\+\+.exe"' >> ~/.bashrc
Notice how I had to escape characters like the space and the brackets. You can escape any character if you're not sure whether it should be escaped or not. Also make sure to use the alias you want; I chose npp.
Close and re-open Git Bash
Type npp in Git Bash, if it opens then you're good to go. If not, try the below points:
Test .bashrc by running the command below in Git Bash
source ~/.bashrc
Retry typing npp to start Notepad++. If Notepad++ doesn't start, check the contents of the file ~/.bashrc created in step 1.
To ensure the .bashrc file contents are loaded each time you open Git Bash, edit ~/.bash_profile and add the following two lines. (Reference)
if [ -r ~/.profile ]; then . ~/.profile; fi
case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac
Close and re-open Git Bash. Type npp in Git Bash to check it starts correctly.
First of all,
if you haven't created any .bashrc profile or .bash_profile create either of the one using vim or any other editor as others have mentioned
Or
In case you did not have any such editor which can work with git bash yet make one manually by opening a notepad or notepad++ editor and saving the file at the home directory.
Note: You can check your home directory by using
cd ~
pwd
My Notepad++ path is C:\Program Files\Notepad++\notepad++.exe
So for going to any directory to notepad++ directory, I have to go to root directory and then to the required path.
So here is the line that I had to add to mine .bash_profile
alias note="//\/c/Program\ Files/Notepad++/notepad++.exe"
'//' takes it to the root directory
P.S.:
You may have to change the path depending on your target directory( notepad++ directory)
The "Program Files"directory should be written like 'Program\ Files'.
If your Notepad++ directory is in Program Files (x86) then use 'Program\ Files\ (x86)'
In your .bash profile add
alias myeditor="'C:\\Program Files (x86)\\Notepad++\\notepad++.exe'"
Give "\\" instead of "\".
Open Git Bash on your system/project and type the following command in the Git Bash
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Press Enter and if no error occurs, you have successfully set up Notepad++ as your text editor in Git Bash.
You can also check it by typing the command
git config --global core.editor
I added the Notepad++ folder to my path, so I can just type notepad++
$ which notepad++
/c/Program Files (x86)/Notepad++/notepad++
This config works for me
editor = \"/c/Program Files (x86)/Notepad++/Notepad++.exe\" -multiInst
The multiInst argument is just to make it friendlier for interactive edits where you already have notepad++ open. (If Notepad++ is already open and you run the process again, it adds the file to your existing instance and then exits immediately, which git takes to mean you've finished)
I met the cannot find the command issue.
I figured out that is because I was doing all those vim .bashrc under my working directory.
It seems I have to do that under the Git Bash home directory...
https://docs.github.com/en/get-started/getting-started-with-git/associating-text-editors-with-git
The section under "Using Notepad++ as your editor" provided the answer.
Run the following in Git Bash and you're away.
$ git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
If you want to open up the global git config file after setting up notepad++ use this:
$ git config --global -e
In your git bash just add:
alias npp='notepad++ -multiInst -nosession'
I hope this works.
An alias is used with the git command, so with the one in your OP, you should be able to run git notepad. I don't think this is quite what you want, though. If you correctly added notepad++ to your PATH variable, then you should be able to just do notepad++. You can check this by running which notepad++. If this doesn't give the full path to notepad++, then the PATH isn't set correctly.

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...
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

Resources