Extend $PATH variable in git bash under Windows

与世无争的帅哥 提交于 2020-01-22 13:27:06

问题


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?


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/45980107/extend-path-variable-in-git-bash-under-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!