how do I change the HOME
directory in MSYS2?
Quick summary
Open C:\msys64\home\my_username\.bash_profile
and add this to the top:
# Change your home (`~`) dir to `C:\Users\my_username`
HOME="/c/Users/$(whoami)"
Details
I really prefer to use the seven MSYS2 terminals inside Windows Terminal, since it is a great terminal shell and allows modern features like multiple tabs.
From my MSYS2 setup answer here: Installing & setting up MSYS2 from scratch, including adding all 7 profiles to Windows Terminal:
1. Set the starting directory to your HOME
directory
First, here is how to set the starting directory to your HOME directory so that a terminal starts there when you open it up:
Open Windows Terminal.
Then, click the little drop-down arrow at the top-right of the open tab, and select "Settings" --> in the Settings tab that opens up, click "Open JSON file" in the bottom-left, as shown here:
In the JSON settings file that opens up, look for the "profiles"
section in the JSON file
Then, add an MSYS2 profile like this, setting the "startingDirectory"
value like this. Note that this is just one of seven of the MSYS2 profiles. See my full answer above for all 7 profiles:
// -ucrt64 (recommended default)
{
"commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -ucrt64 -shell bash",
"guid": "{a718a3d5-9e77-4d0d-b7b6-69ec3d190206}",
"hidden": false,
"name": "MSYS2: ucrt64 (recommended default)",
// "startingDirectory": "C:/msys64/home/%USERNAME%", // alternative
"startingDirectory": "%USERPROFILE%", // ie: C:\Users\my_username
"icon": "C:/msys64/ucrt64.ico",
"font":
{
"size": 10
}
},
2. Set your HOME
directory to whatever you want
Next, here is how I set my HOME
(~
) dir to whatever I want in the seven MSYS2 terminals:
Again, from my MSYS2 setup answer here: Installing & setting up MSYS2 from scratch, including adding all 7 profiles to Windows Terminal:
Change your HOME
(~
) dir from MSYS2's default of C:\msys64\home\my_username
to your regular Windows home dir of C:\Users\my_username
:
Open up C:\msys64\home\my_username\.bash_profile
in a text editor, such as VSCode. Modify it so that it looks like this. Note: you can just comment everything out with #
and add this to the top:
# Change your home (`~`) dir to `C:\Users\my_username`
HOME="/c/Users/$(whoami)"
# Source your `C:\Users\my_username\.profile` file, if it exists
if [ -f "$HOME/.profile" ]; then
. "$HOME/.profile"
fi
Close and re-open Windows Terminal. Run echo ~
and echo "$HOME"
and ensure they now both show /c/Users/my_username
. Run ls -a
and ensure you see the contents of your normal Windows home directory for your user. pwd
should show that you are currently in that directory too...