I have two programs named abc in different directories (/dir1/ and /dir2/). Each of these directories contains other programs. In general, I would like dir1 to be searched for a command before dir2. However, in the case of abc I would like the version in dir2 to be executed by default. How can I make this happen?

I tried aliasing via alias abc="/dir2/abc" however that doesn't work if the command is invoked by another program. How can I make it be the default anytime somebody attempts to invoke abc?


This has been answered on a different stackexchange site. Here is the solution for anyone that is interested:


Here is the option that works for me (quoted from the answer):

Option 1: Make an override folder on your path

If you need these programs to be called in indirect ways (like by some application started by the window manager will call g++ or python, for instance), you should edit your path. You could simply add a new folder to the beginning of your path in your ~/.bashrc:

export PATH=/home/username/.bin:$PATH and place two symbolic links to point to the appropriate programs:

ln -s /usr/bin/python /home/username/.bin/python ln -s /usr/local/bin/g++ /home/username/.bin/g++ That way, once your ~/.bashrc is properly sourced (log out, then log back in), everything should find the right python and the right g++.

  • Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
    – DavidPostill
    Apr 10 '16 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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