{WSL2] Ubuntu Starts Ignoring .bashrc

Hello all,

Crux: How do I get WSL to recognise and use my .bashrc file?

After installing oh-my-bash, the theme and plugins worked as expected. Annoyingly it wrote over my existing .bashrc file - requiring me to re-add path variables and such.

However, after closing the terminal, and re-opening it, the theme was gone, and my path variables were were not used:

Originally, I was using the native Ubuntu20.04 terminal, but switched to the Windows Terminal in the hope it would resolve the issue. Both behave in the same way.

To fix this, I have to type source ~/.bashrc, every time I open a new terminal:

As can be seen, the theme becomes what I want, and my path variables are recognised again.

So, how can I make it so that I do not need to keep typing source ~/.bashrc every time I open a new terminal?

I tried editing the /etc/wsl.conf file to include:

command="source ~/.bashrc"

But, I think this is not quite the use of the wsl.conf file - runs at the wrong time.

I hope this is clear

Solution: Add this to ~/.bash_profile

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"

PS: Oh-My-Bash stores your previous .bashrc file in $HOME/.bashrc.pre-oh-my-bash. So, you can easily cat your original configs to .bashrc

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.