How to change the home directory of Linux running on Windows Terminal with WSL(2)
Introduction
When imported by WSL, the directory at startup is inherited from the current directory on Windows side as follows.
PS C:\Users\jun> wsl -d ubuntu2004-1
root@zeus:/mnt/c/Users/jun#
This is so annoying.
So we want to specify the home directory.
Open the settings.
(Sorry, Japanese UI.)
Or edit the following file.
(I think the name is a little different because it’s the Preview version.)
C:\Users\xxxxx\AppData\Local\Packages\Microsoft.WindowsTerminalPreview_xxxxxxxxxxx\LocalState\settings.json
“source”: “Windows.Terminal.Azure”
Specify the directory where you want to specify the startingDirectory as shown below.
//wsl$/[distribution name]/[directory to be specified]/{
"defaults":
{
// Put settings here that you want to apply to all profiles.
},
"list":
[
・・・
{
"guid": "{61e194fe-f841-5cd8-b7dd-1480bff5b6cc}",
"hidden": false,
"name": "ubuntu2004-1",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/ubuntu2004-1/root/"
}
]
},
If I set it up as above, I could not change the installation from the store to the home directory.
It’s a bit dirty, but you can specify it by setting it as follows. This is also valid for those imported with the WSL command.
If you want to unify the description, this is a good way to use it.
"startingDirectory": "\\\\wsl$\\Ubuntu-18.04\\home\\jun"
The commandline wsl command
To use the WSL command, add ~(tilde).
{
"name": "ubuntu2004-1-cmd",
"commandline": "wsl ~ -d ubuntu2004-1",
"hidden": false
},
conclusion
That was a brief explanation.