If I want to alias a executable file in /usr/local/bin
, Is there a correct way to make such an alias? and how can I make one? Softlink? Hardlink? Something else?
For example, when I
apt-get install vim;
Aptitude will alias /usr/local/bin/vi
as /usr/local/bin/vim
(if I recall correctly)
Technically speaking, there is a way to "alias" default apps. What you are encountering with
sudo apt-get install vim
is Debian Alternatives System.Basically , that system has list of default apps in
/etc/alternatives/
folder, which are symlinks to whatever default app you have. Before installingvim
you havevim.tiny
, sovi
gets symlinked to/etc/alternatives/vi
, which then is symlinked to/usr/bin/vim.tiny
. Once you get the actualvim
, those symlinks all get updated to ultimately point tovim
.Of course there is manual way through
sudo update-alternatives --config vi
. And there of course is nothing stopping you from creating your own symlinks there. However for programs that aren't going to have many many different implementations, likescreen
for example, you could just leave them alone. Provided that/usr/bin
is in your$PATH
variable (which it should always be), you can just type inmyappname
and it will run.Whatever you do, don't hard link.
Hard links lead to confusing issues when, for example, you try to delete the file, because if you don't remember to delete it twice it's still there.
In the case of a program, this can lead to hard-to-debug behaviour, because the program may still be found at the hard link location. Depending on the content of the
PATH
environment variable, it could be executed under different circumstances to what is the case now.Hard links are like
goto
s in programming: a hangover from an older time, now considered harmful.