How to change default directory with WSL/BASH on every time you launch your WSL on Windows 10. How make your user directory default directory every time your launch your BASH or WSL like Ubuntu, Debian, Apline, Arch Linux, Fedore, Suse, and other Linux distro.
To make this permanent default directory whenever you launch your WSL terminal, you’ll have to edit your .bashrc file with your favorite editor like nano or vim.
I’ll be using Micro ‘a terminal based text editor’ more like Nano but Micro is a little more feature rich.
Install WSL 2
If you have not upgraded your WSL on Windows 10 then you should upgrade your WSL to WSL2 and it’ll offer fast execution and more features.
Upgrade WSL 1 to WSL 2
Download and install WSL 2 kernal from link above, restart your system, then launch PowerShell with admin right, and run WSL upgrade command.
Replace Ubuntu-20.04 with your Distro name, 2 at the end is the WSL version number.
wsl --set-version Ubuntu-20.04 2
Check WSL version
To check WSL version, simply relaunch your CMD or PowerShell and run the following command.
wsl -l -v
Launch Your WSL Terminal
I have launched my Ubuntu WSL 2 and it opens in Ubuntu home/user directory, which your check by running this pwd command, this tells you the current directory you are in.
To Get into Windows Directory
To change into your Windows directory, you have to change many directories which is time consuming and nobody wants waste time like that.
To manually change the directory, you type the following commnad
To Make it Default WSL BASH Directory
Run the following commands, type the following commands in your WSL terminal.
The above command will take you to /home/user_folder
I’ll be using Micro text editor, you can use nano or vim
sudo nano .bashrc
Run the above command and enter your password and it should open your .bashrc file.
Type the following command to launch your BASH WSL terminal in your choice of directory.
Change /User_Name with your username; save the file and exit.
Okay, you are done. Just relaunch your WSL terminal.
To display last directory name only
sudo nano .bashrc
Enter your sudo password and type the following code in your .bashrc file and save the file and relaunch your WSL terminal.
export PS1="\[\e[32m\]\W\[\e[m\] \$ "