10

I had written procedure for myself on how to deploy a web app, and it contains a step that says to do this:

vi ~/.bash_aliases
    i
    alias python=python3
    Esc :wq

This step worked a few months ago on a different instance of Debian Jessie. Today, it wasn't working. After some searching, I found that simply running this works:

alias python=python3.6

My question is, what's the difference between these two methods, and any other possible methods of creating aliases? Do they all have the same end-result or are there any subtle differences in functionality/performance? Which method should I be using?

davidtgq
  • 1,484
  • (A) Did you update any software package recently ? Maybe you had older python and now have 3.6. (B) Did you try with alias python=python3.6 in ~/.bash_aliases. Check which python, which python3, which python3.6, & I think the output will show the problem. – Prem Feb 24 '17 at 03:01
  • I see that you were asking about moving to python 3.6 [[ http://unix.stackexchange.com/questions/332641/how-to-install-python-3-6 ]] and it makes me think that, after you did that upgrade, your alias stopped working because python3 was renamed to python3.6 ; when you again added another alias to python3.6, it worked again. – Prem Feb 24 '17 at 05:48

2 Answers2

14

.bash_aliases is only useful if it is sourced by another configuration file; bash itself doesn't know anything about it. Some OS distributions include a line like source .bash_aliases in a default configuration file, as a way of "simplifying" the default configuration.

Personally, I just put alias definitions directly in .bashrc, primarily because I don't define enough aliases to warrant a using separate file. (Most aliases should really be defined as functions.) That said, I do sometimes group my functions in other files which are sourced by my .bashrc.

In the end, the alias definitions are held in memory, so there isn't really any strong performance argument for or against defining them in .bashrc or in a file sourced by .bashrc.

chepner
  • 7,501
10

Your first method will add it to .bash_aliases, which means the alias will be loaded every time you log in.

Your second method adds the alias temporarily, but it will not persist beyond your session.

For more information see What is the .bashrc file? (.bashrc should include .bash_aliases).

cherdt
  • 1,426