Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|improve this question
up vote 4 down vote accepted

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 installing vim you have vim.tiny, so vi gets symlinked to /etc/alternatives/vi , which then is symlinked to /usr/bin/vim.tiny. Once you get the actual vim, those symlinks all get updated to ultimately point to vim.

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, like screen 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 in myappname and it will run.

share|improve this answer
    
A good overview of the defaults mechanism. – andy256 Jan 5 at 0:22
    
interesting. a symlink it is, then. in fustration over debian's pastebinit , i wrote a clone using fedora's pastebin. now i want pastebinit to be an alias for pastebinit.php -- github.com/divinity76/pastebinit_php – hanshenrik Jan 5 at 0:33

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 gotos in programming: a hangover from an older time, now considered harmful.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.