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++
.
Option 2: Use an alias
for bash to follow
If 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
:
alias python=/usr/bin/python
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 calls make
(such as autotools
or cmake
), there is almost always an option to specify your compiler. For instance, your makefile could look like:
CXX=/usr/local/bin/g++
all:
$(CXX) inputfile.cpp -o outputfile
or with cmake
you might configure with
cmake -D CMAKE_CXX_COMPILER=/usr/local/bin/g++ ..
Different programs will have different syntaxes for specifying the compiler, but you can most always specify it.
Best Answer
What you are looking for is the
PATH
environmental variable. It tells the shell, where it needs to look for programs. You can see the current value of that variable usingecho
:Now... The best practice if you want use some new program is to install it using the package management program for your distribution. But in this case, I assume you are dealing with a program that is not delivered by any available software package. For such programs, you have two options:
/usr/local/bin/
and/opt/bin/
- those should already be in yourPATH
. (Look inside these folders and if there are many files in them, then it is the wrong place to put your own program and you have to look at other folders listed in yourPATH
.)Modify your
PATH
variable. This is less secure, because it defines additional folders where programs can be kept and someone might play a trick on you, putting his own program there for you to run.You can modify the
PATH
variable either temporarily, using(mind the
$PATH
after=
), or permanently by adding the above line to your.bashrc
file (assuming you usebash
).