11

I use mintty as my console emulator for MinGW/MSYS. Recently (I'm not certain exactly when), the home directory used by this combination changed from my Windows user folder (/c/Users/<me>/) to /home/<me>/, which is causing minor havoc for me.

How can I change my home directory back? I've done some searching online, but all of the information I've been able to find so far is Cygwin-specific and hasn't translated well to MinGW/MSYS.

The most likely-looking avenues I've pursued so far are /etc/passwd and /etc/nsswitch.conf, both of which are entirely absent from MSYS' root. I've tried creating an /etc/nsswitch.conf containing a db_home: windows line, but this seemed to have no effect. I've not yet tried creating an /etc/passwd file as mkpasswd isn't present in MinGW/MSYS and I don't know what its contents should be.

I'm running:

  • Windows 10 (w/ Anniversary Update)
  • the latest version of all my installed MinGW and MSYS packages
  • …including msys-mintty 1.0.3-1-msys-1.0.17
1

3 Answers 3

14

Unlike Cygwin, MSYS relies on the HOME environment variable. To set or change your HOME variable:

  1. Press Win-r on your keyboard or select "Run…" from the Start menu.
  2. Type "sysdm.cpl" and click OK.
  3. Select the Advanced tab and click Environment Variables…
  4. Click New… to create a new HOME variable or select the existing one and click Edit…
  5. When finished, keep clicking OK until all windows are closed.
2
  • I had tried just exporting the envvar in an existing terminal (it had a value that it pulled from who knows where), but MINGW still wouldn't use the new value it for some reason. Setting it through this method worked wonders though!
    – agweber
    Nov 30, 2018 at 14:19
  • 1
    In MSYS2, this worked for shell, but did not work for ssh for some reason. nsswitch.conf way worked for me. Nov 4, 2019 at 17:33
6

The solution for MSYS2 is creating/updating /etc/nsswitch.conf with a line

db_home: windows

as described in Cygwin docs: https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch-home.

After that all MSYS applications and terminals must be closed, as the configuration is only read once at MSYS DLL load time. (See https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch.)

As of Oct, 2019, it works for me in a fresh installation of MSYS2. Probably, in MSYS 1 nsswitch.conf was not supported.

Creating HOME environment variable works for shell, but does not work for ssh, which tries to access /home/User/.ssh anyway.

1
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – CaldeiraG
    Nov 5, 2019 at 10:00
0

Here's how I set my HOME (~) dir to whatever I want in the seven MSYS2 terminals:

From my MSYS2 setup answer here: Installing & setting up MSYS2 from scratch, including adding all 7 profiles to Windows Terminal:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .