Score:1

Suddenly, I start from the root directory not my home directory when I login. I want to start from my home directory

jp flag

From some point, suddenly (I guess after an Ubuntu update?), it starts in the root directory when I open a new terminal. I want to start from my home directory as before.

The below is my shell script(I removed all the comments). I am running Ubuntu on WSL2 on Windows 10

export ZSH="/home/myubuntu/.oh-my-zsh"
ZSH_THEME="bira"
DISABLE_LS_COLORS="true"
plugins=(git)

source $ZSH/oh-my-zsh.sh

alias tre='tree -a -C -I '\''node_modules|.git'\'' --dirsfirst'

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

#cd workspace
if [ "$PWD" = "$HOME" ]; then cd workspace; fi

# added by travis gem
[ ! -s /home/myubuntu/.travis/travis.sh ] || source /home/myubuntu/.travis/travis.sh

This is Ubuntu info

╰─$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

Anyone knows how to fix this?

cc flag
Does your home directory exist? If it doesn't (like if /home was not mounted), then the default current working directory is probably /
mchid avatar
bo flag
I don't have WSL2 up and running so I can't verify this but if you have access to your settings.json file, change the starting directory path to `/home/username` where username = your actual username. Example: `/home/taeil`
mchid avatar
bo flag
I found the answer [here](https://github.com/microsoft/terminal/issues/11812#issuecomment-977198964) and they reference another [similar answer that involves using a path with backslashes instead](https://github.com/microsoft/WSL/issues/6995#issuecomment-934115519)
Tommy avatar
jp flag
@ubfan1 it exists.
Tommy avatar
jp flag
@mchid Thank you, that is the problem I have. WOW, you have much better googling skills than me, I couldn't find it by googling for hours.
Tommy avatar
jp flag
@mchid Yap yap yap, I could fix it by replacing forward-slash to back-slash in settings.json ... "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\taeil", ...
terdon avatar
cn flag
@mchid please post an answer explaining the solution so this question can be marked as answered.
ru flag
I'm pretty sure WSL2 provides a command line to start Ubuntu as a certain user under the windows terminal, perhaps not so convenient as you have expected though.
NotTheDr01ds avatar
vn flag
@funicorn Actually, it's pretty convenient. `wsl -u <username>` will start as any user that is defined in Ubuntu. Also `wsl ~` will start in the home directory.
Score:0
vn flag

I see in the comments that you got this working, but there are several ways to do this under Windows Terminal:

  • Under Windows 10 21H2 and Windows 11, you can specify a Linux directory instead of the Windows path for startingDirectory. So now /home/taeil will work (assuming you are upgraded). See this answer on Stack Overflow for details and a link to the Microsoft Doc.

  • Under previous versions, you do need to use the Windows format \\wsl$\ path (quoted) as noted in the comments. In your case, it looks like this would be \\\\wsl$\\Ubuntu\\home\\taeil

  • Personally, for using your Linux home directory as a starting point, I recommend this technique (my answer in that same Stack Overflow question). Just start wsl with wsl ~ to start in your home directory.

  • Also, with Windows 10 21H2 and Windows 11, wsl --cd ~ works.

Tommy avatar
jp flag
Thanks, I fixed following the comment. but still good to know various ways. startingDirectory: "~" seems the best way to me.
NotTheDr01ds avatar
vn flag
@Taeil Ah, if only it worked. I just tried it, and it doesn't :-/. I would have thought that it would pass the `startDirectory` to the `wsl --cd` command, but apparently not. I usually just edit the `commandLine` property myself and force it to `wsl ~`, which I do know works, but if you want to use `startingDirectory':`/home/taeil` is probably the next best thing.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.