Score:0

How to change default $PATH for root user in WSL2 (Ubuntu version)

cw flag

In the Ubuntu version running in WSL2 (on Windows 11), how do you change the default $PATH for the root user? I've tried adding the following lines to the root user's ".profile" script:

if [ -d "/mnt/c/Users/<my user>/AppData/Local/Programs/Microsoft VS Code/bin" ] ; then
PATH="/mnt/c/Users/<my user>/AppData/Local/Programs/Microsoft VS Code/bin:$PATH"
fi

And, this works if I login as root directly, but if I login as my regular user, then "su" to root, the default PATH isn't changed. So I'm guessing the .profile script isn't executed when you "su" to root, only when directly logging in as root.

How do I configure Ubuntu to change the default PATH in both cases?

Thanks!!

hr flag
Use `su -` , `su -l`, or `su --login` if you want the shell to read root's `.profile`. Otherwise, place the changes in root's `.bashrc` instead.
nobody avatar
gh flag
I have no knowledge about WSL. On my debian I created `/etc/default/su` file with content `ALWAYS_SET_PATH yes`
I sit in a Tesla and translated this thread with Ai:

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.