I have two g++
programs located at /usr/local/bin/
and /usr/bin/
I would like to have the default g++
to be in /usr/local/bin/
. However, I do not want to change my PATH environment variable because for some other program. I would prefer the version in /usr/bin/
than that in /usr/local/bin/
. Is this possible?
To make my point clear:
I want my default for my two program to be:
g++
in /usr/local/bin/
python
in /usr/bin/
But in /usr/local/bin/
and /usr/bin/
, both programs exist, what should I do?
Best 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++
orpython
, for instance), you should edit your path. You could simply add a new folder to the beginning of your path in your~/.bashrc
:and place two symbolic links to point to the appropriate programs:
That way, once your
~/.bashrc
is properly sourced (log out, then log back in), everything should find the rightpython
and the rightg++
.Option 2: Use an
alias
for bash to followIf you are looking for a lighter weight solution, and if you only call python directly from bash, you could setup an
alias
in your~/.bashrc
:Option 3: Just change the name of
python
in /usr/local/bin/Or you could always just rename
/usr/local/bin/python
to be/usr/local/bin/python-alternate
or something. I wouldn't suggest renaming things in/usr/bin
, since at least in Debian that is controlled by a package manager. Usually/usr/local/bin
isn't.Option 4: Specify the correct compiler in the Makefile
If your workflow uses
make
, or some broader application that callsmake
(such asautotools
orcmake
), there is almost always an option to specify your compiler. For instance, your makefile could look like:or with
cmake
you might configure withDifferent programs will have different syntaxes for specifying the compiler, but you can most always specify it.