How to make an alias last forever?


I want to make an alias python=“python3”. I do this by using nano ~/.bash_profile and then typing: alias python=“python3” , and save. Then I write: source ~/.bash_profile to overwrite changes. But this alias only lasts for the terminal session that i am in. When i start a new terminal session I have to write source ~/.bash_profile for the alias python=“python3” in order for it to go into effect.

Thanks in advance!

What’s your OS and current shell? Quite a few set-ups wouldn’t automatically read your .bash_profile since you’re probably just opening an interactive shell.
Perhaps try editing .bashrc instead to see if that gets it automatically (it should). There’s quite a few details out there regarding the differences.

My current OS is macOS Catalina and I use terminal.
There was no .bashrc file in my home directory so I created one using nano ~/.bashrc and then wrote alias python=“python3”. But the alias still is not loading when starting up. Do you know how to fix this?

Ah, if it’s OSX Catalina then the default shell is now zsh. You’d need to be editing the profiles for this shell instead. The easiest would be would .zshrc since it should always be loaded (I seem to remember that that mac does some funny things with the terminal log-in shells vs. interactive shells).

You might want to spend a little time looking into the difference between z and bash if you’re interested but they’re fairly minimal unless you go looking for them.