Extend $PATH variable in git bash under Windows - path

I'm trying to extend my $PATH variable in git bash (MinGW shell) by adding the following to the file ~/.bashrc
PATH=$PATH':/c/Program Files/maven/apache-maven-3.2.5/bin'
After I did this and restarted the bash it seems like that the $PATH variable was extended like expected:
$ echo $PATH
MANY_OTHER_PATHS:/c/Program Files/maven/apache-maven-3.2.5/bin
But I still cannot execute the programms in the given directory:
$ mvn
bash: mvn: command not found
What went wrong here? How do I extend the PATH variable correctly?

Here are two ideas.
You can have your path with double quote mark.
export PATH=$PATH:"/C/Program Files (x86)/apache-maven-3.3.3/bin"
Or, You can also make symbolic link for the directory.
ln -s "/C/Program Files (x86)/apache-maven-3.3.3/bin" ./mvnbin
export PATH=$PATH:/your-path/mvnbin
It works for me in mingw32 environment.

I needed to add something to my Git Bash path permanently each time I open it. It was Meld.exe path which can be added with:
export PATH=$PATH:"/C/Program Files (x86)/Meld/lib"
In order to execute this command each bash session, you need a ~/.bashrc file. Check if it already exists or create it using notepad ~/.bashrc or touch ~/.bashrc.
You can check where it is with:
echo ~
Open it and add the command that adds the PATH (first command in this response).
I hope you found this useful.

According to this SO post, you need to escape Program Files with quotes. git-bash $PATH cannot parse windows directory with space

Add PATH in Git Bash Permanently | Windows Only
Just in case you are still wondering how to add a path permanently in git bash here is the step-by-step process for Windows users:
Create .bashrc in user's root folder using the below command. It will open notepad and ask you to create the file, click yes.
notepad ~/.bashrc
Put the directory you want to add as below, for more than 1 items repeat the same format in next line:
export PATH=$PATH:"/c/folder/folder/"
Save the file and relaunch the bash.
Next launch will give you a warning like WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile. but git bash will handle it by creating the required files.
SOME INSIGHTS
Git Bash doesn't fetch Window's environment PATH, it maintains its PATH separately in more like a Linux way.
You can run export PATH=$PATH:"/c/folder/folder/" in cmd to add a directory to path, but it will be only for the current session once you close the bash, it will be gone.
.bashrc is a shell script file that will be executed every time you launch a new git bash window. So you can add any type of bash command here. We simply added the export command to add our desired directory to PATH.

Related

The command could not be located because '/snap/bin' is not included in the PATH environment variable

when i try to run git-all-secrets i got Dockerfile: command not found
and this is the command include correct information
here is an example of the issue
root#momo22:/home/momo/git-all-secrets# docker run -it abhartiya/tools_gitallsecrets -token=9a8b60a10cf683f238e05 -org=bugcrwod
Command 'docker' is available in '/snap/bin/docker'
The command could not be located because '/snap/bin' is not included in the PATH environment variable.
docker: command not found
root#momo22:/home/momo/git-all-secrets#
Temporary solution:
Run the command export PATH=$PATH:/snap/bin
Permanent solution:
Edit /etc/environment and add /snap/bin in the list then restart your system.
Links
answer for similar error with same fix
More info on /etc/enviroment
you can add the path into .bashrc file
$ echo 'export PATH=$PATH:/snap/bin' >> ~/.bashrc
open new terminal or execute this command
$ source ~/.bashrc
To fix this issue do the following:
Open the file /etc/environment.
Add /snap/bin to the end of the PATH Variable and concatenate using the : character.
Example lets assume we had the PATH variable in the file was: Path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
After your update this will look like: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/snap/bin
Finally to update your shell and have the PATH variable ready to use, run source /etc/environment
Done
If you come here and are just on Ubuntu rather than docker and you have just installed snapd without logging out/in again, log out then in again - you don't need to modify any files.
Open the ~/.bashrc with nano or vim => vim ~/.bashrc
add export PATH=$PATH:/snap/bin at the end of the file
log out from your user and log in again or reboot
if ~/.bashrc doesn't exist:
create ~/.bashrc file and open it => touch ~/.bashrc && vim ~/.bashrc
add PATH=$PATH:/snap/bin
logout from your user and login again or reboot
if you don't want to logout or reboot run these commands:
sudo su ${USER}
bash
open ~/.bash_profile
add export PATH=$PATH:/snap/bin and save the changes
run source ~/.bash_profile
you can open ~/.bash_profile with vi or gedit

Explain the different parts of the code needed to add $HOME/.rbenv/bin to your $PATH

I understand the code is trying to make the executable in $HOME/.rbenv/bin available in $PATH so it can be executed from the command line but I can't figure out how the code does this. The code is shown below:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $HOME/.bashrc.
I know that something is being appended to the end of the bashrc file and I know export is used to export environment variables to new shells but I don't see any new shell here. And I have seen echo used in the following way: a = 5; echo $a but I can't figure out why you need it here and what is
PATH="$HOME/.rbenv/bin:$PATH"
doing. what does 'PATH' represent. Is it a variable without the $ and what is 'bin:$PATH'.
In bash (and most other shells) you assign variables without the $, so PATH=something assigns the variable PATH to the string "something".
In Unix/ Linux, PATH is a string variable that contains a list of folders separated by colons (:). For example on my laptop this is my PATH:
> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
This means that any executable in those folders is accessible anywhere without having to type the full path. You will typically add things to the PATH in your .bashrc file, so they get added when your shell starts up. If you use the which command you can see where a command lives, it will be in one of these folders:
> which rm
/bin/rm
To add a new folder to the PATH, you re-assign PATH to be a string of the new folder, followed by a colon and the previous value of PATH.
In you example, you are adding $HOME/.rbenv/bin to the start of PATH. $HOME will be expanded to your home directory.
To understand this better we can do something like this:
> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
> export PATH="$HOME/.rbenv/bin:$PATH"
> echo $PATH
/Users/javanut13/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
As you can see the rbenv folder was added to the front of the PATH variable.
export puts the variable into the environment of the current shell, which means that other commands started in that shell (subprocesses) also get this change. For example if you don't do export and then run a bash script that uses ruby, it will fail because it doesn't have the ~/.rbenv/bin folder in its path.

Setting path in Solaris Sparc

I have one python command file, i want to set it as a PATH in Solaris Sparc so that i can easily use my command from anywhere. For example the file name is abc.py and it contains abc --version to display version of file abc. So, after opening terminal i should only give command abc --version and it should display version of abc.
The architecture (SPARC) has nothing to do with the PATH which is more a shell thing but you do not tell what shell you are using.
Anyway, if you use a bourne style shell, i.e. not csh/tcsh, and you don't mind this to affect every user account on that host, you might add the wanted path to the PATH setting in the file /etc/profile.
When abc.py is located in your homedir, you can start it with ~/abc.py.
You need to call the file abc.py with abc.py, not abc (and have a shebang line which instructs the shell where it can find python).
When you want to start the file with ./abc, you can rename the file to abc (the shebang will tell it is python, not the .py), or introduce an alias:
alias abc="~/abc.py"
Using an alias can be an alternative for adding a shebang line:
alias abc="/usr/bin/python abc.py"
When you do not want to use an alias you can make a bin dir and put abc there.
I will add the shebang for you:
mkdir ~/bin
echo "#!/usr/bin/python" > ~/bin/abc
cat abc.py >> ~/bin/abc
chmod +x ~/bin/abc
mv abc.py bin/abc.py.old
Now change your login PATH with PATH=${PATH}:$HOME/bin in your .profile or .bashrc, and login again (or source the login script).

Using the Command-line Command to launch Sublime Text 2 on OS X

I just started reading Michael Hartl's book on Rails and I've run across a problem in the setup phase. Hartl keeps referring to making a file in my home directory, but I'm not quite sure how to do this. For example, when I try to setup the command line for sublime text the instructions tell me to do this: Assuming you've placed Sublime Text 2 in the Applications folder, and that you have a ~/bin directory in your path, you can run:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
My problem is that I don't know how to put a ~/bin directory in my path. I know this is real basic but any help would be greatly appreciation.
create or edit ~/.profile (works with both bash and zsh)
add the following
export PATH=$PATH:$HOME/bin
The line above is saying, overwrite the PATH environment variable and set it to the previous path plus ~/bin
Now when you try to run a command, bash will look in all the colon separated paths in your PATH environment variable for an executable.
To see your entire PATH, type echo $PATH in a terminal. Or better yet, type env to see all environment variables.
On your terminal
$ mkdir ~/bin
$ sudo ln -s "/Applications/Sublime Text2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl
Edit ~/.base_profile
export PATH=$PATH:~/bin
usage:
open current directory:
subl .
In your ~/.bashrc file add to the end:
PATH="$HOME/bin:$PATH"

Trying to set up bash command

I was trying to set up a bash command in Terminal on a Mac.
The scripts run correctly when I execute them directly.
I set up symlinks in /usr/local/bin/ to the current location of the scripts. When I try to run it off the symlink, it doesn't work. I don't believe the issue is the $PATH, because pip, git, ipython all exist in this location. When I edit the $PATH setting, these fail.
Suggestions?
ls -l /usr/local/bin/foo and see where your symlink is actually pointing. Betcha it's broken.
If not, try running /usr/local/bin/foo. If that works, it was your PATH that's wrong, despite what you said in the OP.
The only other thing that would cause this behavior is if the script is reading $0 (its own name as executed). With a symlink, that will have a different value.
I found my own answer... The symlinks were created by an automated file which was gabbing my pwd. I was also using virtualenv, so to get it to work, I had to activate the virtualenv and be inside the folder that had the script that created the symlinks.
I install my commands in $HOME/bin instead of /usr/local/bin, but it does not matter much. As hinted in the comments, one question is whether the symlinks are set correctly.
Check which command the shell thinks you should execute: which command
Check that the link in /usr/local/bin points to the correct file (and has execute permission, etc):
ls -l /usr/local/bin/command
ls -lL /usr/local/bin/command
Check that the interpreter path in the shebang is correct:
file /usr/local/bin/command
Check that /usr/local/bin is actually on your PATH: echo $PATH
If none of that shows up a problem, show us the results of the commands above.

Resources