如何修改MinGW的起始目录?含恢复原主目录的方法咨询
Hey there, let's get your MinGW terminal back to starting in your original home directory—here are three straightforward methods to fix this:
Method 1: Tweak the MinGW Shortcut Properties
This is the simplest fix if you launch MinGW via a desktop or Start Menu shortcut:
- Locate the MinGW terminal shortcut you use (look on your desktop or in the MinGW folder in your Start Menu)
- Right-click the shortcut and select Properties
- Switch to the Shortcut tab
- Find the Start in field: erase the current path and replace it with your original home directory (e.g.,
C:\Users\YourUsername—replace "YourUsername" with your actual Windows username) - Click Apply then OK. Next time you open the terminal, it’ll boot right into your desired directory.
Method 2: Edit the MinGW Startup Configuration File
If the shortcut fix doesn’t work, check if a startup script is overriding the directory:
- Open your MinGW terminal (even if it’s in the wrong folder)
- Type
cd ~to jump to your MinGW home directory (this should still point to your original home unless theHOMEvariable was changed) - Open the
.bashrcfile with a terminal editor—trynano .bashrc(easy for beginners) orvim .bashrcif you’re familiar with it - Scan the file for lines like
cd /some/other/directory—this is probably what’s changing your startup folder. Either delete the line or comment it out by adding a#at the start (like# cd /some/other/directory) - Save the file (for nano, press
Ctrl+OthenEnter; for vim, type:wqand pressEnter) - Close and reopen the terminal—it should now start in your original home directory.
Method 3: Reset the HOME Environment Variable
If MinGW’s home directory itself was changed, adjust the system environment variable:
- Right-click This PC (or My Computer) and select Properties
- Click Advanced system settings on the left sidebar
- Go to the Advanced tab and click Environment Variables
- Under User variables, look for a variable named
HOME - If it’s set to a non-default path, click Edit and change the value to your original home directory (e.g.,
C:\Users\YourUsername) - Click OK on all open windows, then restart your MinGW terminal to apply the change.
Quick Tip
If you can’t remember your original home directory, open a regular Command Prompt and run echo %USERPROFILE%—this will show your default Windows user folder, which is MinGW’s default starting point.
内容的提问来源于stack exchange,提问作者heheheggg
相关产品推荐
相关产品推荐

