Georgina Davenport
Georgina Davenport

Reputation: 203

How do I permanently change the MSYS2 PATH?

I want to permanently add /mingw64/bin to the MSYS2 PATH.

I have tried:

export PATH=$PATH:/mingw64/bin

It works until I exit.

After I restart MSYS2 the path has reset to what it was before.

What do I need to do to add /mingw64/bin to the PATH so the change persists after I quit and restart the MSYS2 console?

Upvotes: 1

Views: 3929

Answers (2)

exactzen
exactzen

Reputation: 1

A)A short-short answer is : in some file like

 x:\MSYS2\home\some_name\.bash_profile    , 

add these lines:

#   ----  modify :   j   is  j-Windows  drive  
tt=/j/MSYS2/mingw64/bin

PATH="${tt}:${PATH}"

B)A short answer is : in some file like

 x:\MSYS2\home\some_name\.bash_profile    , 

add these lines:

#   pathz  was defined in   Windows  using  e.g.   set pathz=%cd%    before loading  MSYS2
#   You can also set it here (in Windows-format   like  'c:\my\bin)
tt="${pathz}"

tt=\/"${tt}"
tt="${tt/:/}"
tt="${tt//\\//}"

PATH="${tt}:${PATH}"
#   ----  modify these 2 lines :
mkdir -p "${tt}"/../2WORK
cd "${tt}"/../2WORK


#some tests :
input="a\b\c\d"
echo ${input}
echo "${input/\\//}"
echo "${input//\\//}"
echo "Note that : only the last echo with '//', not '/', to begin, give us global replace !!"

C)An instructive answer is :

1)Create a dir . In this dir, create a file named qqq.cmd that contains :

rem  cd = current dir
set pathz=%cd%
set path=%pathz%;%path%
set pathzz=%path%

:: pathz and pathzz can be used in cygwin and MSYS2 , but must be translated.

if "%1" == "" (

  rem   ----  modify this line :
  I:\MSYS2\msys2_shell.cmd   -ucrt64
  exit
)


set ZZZZZZ=123aBBC1111111111111
set zZZz=123aBBC

rem   ----  modify this line :
I:\CYG\bin\mintty.exe -i /Cygwin-Terminal.ico -

exit
      

2)In this dir, create another file named ss that contains :

#ss
#in notepad++  :  click Edit , choose EOL conversion , then choose unix  for this file  ss.  (no extension).
    

ln -s /cygdrive/c /c
ln -s /cygdrive/n /n
ln -s /cygdrive/e /e
ln -s /cygdrive/f /f
ln -s /cygdrive/i /i

echo $PATH
echo $path"assss----------"
echo $ZZZZZZ
echo $zZZz
echo $ZZZZ--=====++++++
echo $zZZz
echo $PATHZ  --------
echo $pathz --====


cd /c
echo --------Note current dir :
pwd

if false; then
    # ... Code I want to skip here ...  
  fdsgfsdsgfs
  dfsdgfdsgfds
fi


exit
      

3)Do as in B) .
4)Create shortcut for qqq.cmd and move the short cut to any where.
5)Then execute qqq.cmd by double clicking the shortcut and now you have MSYS2. Type ss and check the output and note the current dir now!!

NB: if you modify qqq.cmd to load Cygwin then 3) above not needed

Upvotes: -1

HolyBlackCat
HolyBlackCat

Reputation: 96699

You shouldn't manually add /??/bin to the PATH in the MSYS2 terminal.

It happens automatically (along with other changes to environment variables) when you open the terminal for the environment you want to use.

There should be different shortcuts for different environments, the one you're looking for should be named along the lines of ... MinGW 64-bit.

The shortcuts point to executables in C:\msys64, which you can run directly (this one is mingw64.exe).

Upvotes: 3

Related Questions