Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Ubuntu WSL starting directory keeps it set to the defualt #2743

Closed
AlikanakelaKarwowski opened this issue Sep 13, 2019 · 78 comments · Fixed by #2813
Closed

Changing Ubuntu WSL starting directory keeps it set to the defualt #2743

AlikanakelaKarwowski opened this issue Sep 13, 2019 · 78 comments · Fixed by #2813
Assignees
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@AlikanakelaKarwowski
Copy link

When editing the the settings, I have tried to chang the default starting directory for the Ubuntu WSL Terminal profile as follows
"startingDirectory": "/mnt/D/Folder/SubFolder/",
and while it doesnt cause any issues or causes the Terminal to resort to default configuration, it does not set the default starting directory to the specified path.

Also it seems that most settings for the profile do literally nothing when changing them, from color, to acrylic or scheme settings.

Note: changing the setting for power shell, cmd, of Kali-Linux does work and change things respectively

@AlikanakelaKarwowski AlikanakelaKarwowski added the Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs label Sep 13, 2019
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 13, 2019
@zadjii-msft
Copy link
Member

startingDirectory Should be a windows path, not a *nix path. Try D:\Folder\SubFolder instead.

Could you be specific which settings don't seem to work for that profile? Maybe share the profile from the profiles.json file?

@zadjii-msft zadjii-msft added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs labels Sep 13, 2019
@bitcrazed
Copy link
Contributor

@zadjii-msft Just checked into this & verified that, yes, specifying a Windows path does work, and for WSL distros, specifying a Windows-relative path to a distro also works.

For example, \\\\wsl$\Ubuntu\home\\rich\\ opens my Ubuntu home folder! 😁

@DHowett-MSFT
Copy link
Contributor

This is a duplicate of another bug in the db somewhere. We need to clarify in the documentation that startingDirectory is a Windows path, and since Terminal doesn't actually know anything about the connected application on the other end we can't assume that it's WSL and do path translation and all that stuff.

It's gotta be a Windows path. 😄

I'm re-tagging this with Issue-Docs

@DHowett-MSFT DHowett-MSFT added Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs Area-Settings Issues related to settings and customizability, for console or terminal Product-Terminal The new Windows Terminal. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Sep 14, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Sep 16, 2019
@DHowett-MSFT DHowett-MSFT added this to the Terminal v1.0 milestone Sep 16, 2019
@MEXdave1997
Copy link
Contributor

I am working on submitting a PR to add that bit of detail, if that is alright with everyone.

@DHowett-MSFT
Copy link
Contributor

Sure!

@ghost ghost added the In-PR This issue has a related PR label Sep 19, 2019
@ghost ghost added Needs-Tag-Fix Doesn't match tag requirements Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Sep 19, 2019
@contento
Copy link

contento commented Nov 6, 2019

@zadjii-msft Just checked into this & verified that, yes, specifying a Windows path does work, and for WSL distros, specifying a Windows-relative path to a distro also works.

For example, \\\\wsl$\Ubuntu\home\\rich\\ opens my Ubuntu home folder! 😁

You may want to use wsl -l first, in order to determine which Ubuntu version you are running.
For example:
"startingDirectory": "\\\\wsl$\\Ubuntu-18.04\\home\\[linux-user]"

@jgroom33
Copy link

jgroom33 commented Feb 9, 2020

non-escaped also works:

"startingDirectory" : "//wsl$/Ubuntu-18.04/home/<user>"

@Boobies
Copy link

Boobies commented Feb 27, 2020

The problem isn't the documentation, it's the default JSON provided. That's why everyone keeps complaining about the same thing. Here's mine:

        "startingDirectory" : "\\\\wsl$\\Debian\\home\\<linuxuser>"

which instead takes me to /mnt/c/Users/<windowsuser>. So it looks like that string is entirely ignored and a default that has nothing to do with it is picked. It's not even the same username.

@MEXdave1997
Copy link
Contributor

@Boobies weirdly enough, I've used "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\[linux username]" in my config for a while now with no issue. Could there be any other setting that might be conflicting with it?

@amykapernick
Copy link

I've tried all of these and it still seems to be defaulting to c/Users/{user} as well. Any suggestions?

@mrzlanx532
Copy link

If the methods above don't work (like for me), do this:
Add to the end .bashrc file: cd ~.

From Windows environment:

  1. execute wsl
  2. execute cd ~ && echo 'cd ~' >> .bashrc

@ednl
Copy link

ednl commented Jul 2, 2021

Reading every message here FINALLY gave me the hint #2743 (comment) why it wasn't working for me: the home directory needs to have read/execute access for group/others. Strange, because the root user should have access anyway, right?

I always do chmod -R go-rwx ~ and that bit me here. It is now fixed after chmod go+rx ~ and WSL starts up in my Linux home directory again.

Another gotcha for the docs, @DHowett ?

Edit: NOPE. It seemed to have been fixed when I tried closing and reopening Windows Terminal, but when running Terminal at system boot or after a long delay between closing and reopening, it STILL starts up in /mnt/c/Users/ instead of ~. In Settings it does still say, and always has: //wsl$/Ubuntu-20.04/home/

Edit2: I found a comment #592 (comment) that says the "//wsl$/ folder is not initialized until a wsl instance is started. So the first instance wont start in ~, but the others will start in ~ because the first instance initialized the //wsl$/ folder". So there is no way to always (even the first time) start up a WSL instance in the Linux home directory??

@SGarcia710
Copy link

The problem isn't the documentation, it's the default JSON provided. That's why everyone keeps complaining about the same thing. Here's mine:

        "startingDirectory" : "\\\\wsl$\\Debian\\home\\<linuxuser>"

which instead takes me to /mnt/c/Users/<windowsuser>. So it looks like that string is entirely ignored and a default that has nothing to do with it is picked. It's not even the same username.

This one worked for me, just editing the JSON file

@ajfpay
Copy link

ajfpay commented Aug 6, 2021

non-escaped also works:

"startingDirectory" : "//wsl$/Ubuntu-18.04/home/<user>"

Yeah this work

@riolly
Copy link

riolly commented Oct 19, 2021

The newer windows terminal provides a UI for setting starting directory for each profile.
Using startingDirectory is not working anymore. (I'm not sure starting from which version).

Just go to setting > Profiles > Ubuntu-xx.xx > Starting directory.
You can paste the path there or just click browse and go to the directory you want.

Hope it help.

@riolly
Copy link

riolly commented Oct 19, 2021

In my case, this is the starting directory.
\\wsl.localhost\Ubuntu-20.04\home\alberto

@pedershk
Copy link

pedershk commented Oct 22, 2021

In my case, this is the starting directory. \\wsl.localhost\Ubuntu-20.04\home\alberto

Same - and I presume it changed to the \\wsl.localhost format with WSL2?

@DHowett
Copy link
Member

DHowett commented Oct 22, 2021

The newer windows terminal provides a UI for setting starting directory for each profile.
Using startingDirectory is not working anymore. (I'm not sure starting from which version).

These are the same setting.

You may be seeing the issue described in #11512 (comment) where the timing makes it seem as though whatever you did fixed something.

@gabriel8fm
Copy link

@Boobies weirdly enough, I've used "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\[linux username]" in my config for a while now with no issue. Could there be any other setting that might be conflicting with it?

@MEXdave1997 your settings worked perfectly for me, thanks!

@Rmlyy

This comment has been minimized.

@yorkshire-pudding

This comment has been minimized.

@jetersen
Copy link

jetersen commented Dec 31, 2021

Today after reinstalling Ubuntu 20.04

on Windows 10 21H2 (Build 19044.1415)
I had to use

"startingDirectory": "/home/<user>"

Which is GREAT 👏

@ray-x
Copy link

ray-x commented Jan 4, 2022

__

Today after reinstalling Ubuntu 20.04

on Windows 10 21H2 (Build 19044.1415) I had to use

"startingDirectory": "/home/<user>"

Which is GREAT 👏

Thanks!
Same here, if set to //wsl$/Ubuntu/home/<user> I will start from root folder

@riker09
Copy link

riker09 commented Jan 21, 2022

I have Windows 10 Version 20H2 - Build 19042.1415 and had to use /home/<user> where <user> needed to be replaced with the actual user name. All other solutions provided above did not work for me. I have only Ubuntu installed inside WSL.

@zadjii-msft
Copy link
Member

Okay lemme clear this up before there's more confusion. This ISN'T something that came with a Windows update, this is a Terminal change in 1.12.

In 1.12, you should be able to use /home/<user> as the startingDirectory, and the Terminal should automatically promote that to the correct path. Unfortunately, that came at a cost - there's a bug in 1.12 where //wsl$/Ubuntu/home/<user> paths will be treated as /. That's fixed in #12102. (\\wsl$\Ubuntu\home\<user> with backslashes should still work)

@wolf99
Copy link
Contributor

wolf99 commented Feb 2, 2022

My work laptop just updated from 1909 to 20H2 (upgrades are controlled by policy, thus the reason for not being on a newer version or having updated sooner).
Previously the following had worked just fine to start WT in ~ : "startingDirectory" : "/wsl$/Ubuntu/home/emoltob"
After the upgrade WT started in /, I assume it was then ignoring this setting as somehow invalid.
Changing to the following solved this: "startingDirectory" : "\\\\wsl$\\Ubuntu\\home\\emoltob"

Yes, these two seem basically equivalent. Yet the latter works while the former is apparently now ignored.

@zadjii-msft
Copy link
Member

@wolf99 what you're seeing is exactly what I've described in #2743 (comment)

@wolf99
Copy link
Contributor

wolf99 commented Feb 2, 2022

Mmm I'm not on 1.12 yet though as I do not use the pre release versions. I am still on 1.11. Are you saying this change was also present in 1.11 ?

@zadjii-msft
Copy link
Member

Yea, looks like we serviced #9223 to 1.11.2421 as well.

@morph2k
Copy link

morph2k commented Feb 3, 2022

I worked my way through this whole thread and it took me a while to realize that Windows Terminal has been updated. I added the line to the Json file and it only half worked, changing the starting directory from my Windows user folder to root.

Going into the settings under Ubuntu and setting the Starting directory option to \wsl$\Ubuntu\home\username\ works but not when using /

@AnimeshRy
Copy link

__

Today after reinstalling Ubuntu 20.04
on Windows 10 21H2 (Build 19044.1415) I had to use

"startingDirectory": "/home/<user>"

Which is GREAT 👏

Thanks! Same here, if set to //wsl$/Ubuntu/home/<user> I will start from root folder

This worked finally!

@mcandre
Copy link

mcandre commented Feb 21, 2022

Something recently changed and now WSL starts with a WSL root working directory instead of the correct WSL HOME working directory.

@barcellos-pedro
Copy link

__

Today after reinstalling Ubuntu 20.04
on Windows 10 21H2 (Build 19044.1415) I had to use

"startingDirectory": "/home/<user>"

Which is GREAT 👏

Thanks! Same here, if set to //wsl$/Ubuntu/home/<user> I will start from root folder

This worked finally!

That worked for me! Thanks! 💖

@mbowolick
Copy link

A lot of the paths here didn't work for me. \\wsl$\Ubuntu\home\<user> worked for me where <user> is the name of your Linux user.

@cjens00
Copy link

cjens00 commented Apr 23, 2022

If the methods above don't work (like for me), do this: Add to the end .bashrc file: cd ~.

From Windows environment:

  1. execute wsl
  2. execute cd ~ && echo 'cd ~' >> .bashrc

Thank you. This is what I was looking for (works well enough).

@kwint
Copy link

kwint commented Nov 25, 2022

I still can't get this to work as expected. I want the default folder to be ~/code. So my starting dir is set to: \\wsl$\Ubuntu-22.04\home\kwint\code but this just opens the home folder and not the code folder.

Afaik I don't have any cd ~ in my .bashrc or equivalent

Edit: always after you asked for help on the internet you find the solution yourself. For some reason my default wsl profile would use the executable ubuntu2204.exe. I changed this C:\Windows\system32\wsl.exe -d Ubuntu-22.04 and now the starting directory works as expected

@Easy-Cloud-in
Copy link

This is what I did in windows 10 latest terminal settings - PowerShell 7.3.4

{
                "colorScheme": "Ubuntu-22.04-ColorScheme",
                "commandline": "wsl.exe -d ubuntu",
                "font": 
                {
                    "face": "CaskaydiaCove Nerd Font"
                },
                "guid": "{51855cb2-8cce-5362-8f54-464b92b32386}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc",
                "startingDirectory": null
 }

It worked like a charm both on right click menu and direct from terminal.

@Nick-Hope
Copy link

non-escaped also works:

"startingDirectory" : "//wsl$/Ubuntu-18.04/home/<user>"

//wsl$/Ubuntu/home/<user> worked for me but I also had to change my Command line in the settings from ubuntu.exe to wsl.exe -d Ubuntu.

@kevgilmore
Copy link

kevgilmore commented Jan 9, 2024

Today after reinstalling Ubuntu 20.04

on Windows 10 21H2 (Build 19044.1415) I had to use

"startingDirectory": "/home/<user>"

Which is GREAT 👏

this gave me error

[error 2147942667 (0x8007010b) when launching `ubuntu.exe']
Could not access starting directory "/home/kev/code"

Nor do any of the above strings works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.