Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change where Bash looks for Python in Linux?

Tags:

python

linux

bash

I just updated my ReadyNas from python 2.3.5 to python 2.6.6. The upgrade placed the new version in the /usr/local/bin directory. So

  • /usr/local/bin/python is Python 2.6.6
  • /usr/bin/python is Python 2.3.5

When I type python at a bash prompt tries to run /usr/bin/python or my old version. I relocated my old version, and now I get:

bash: /usr/bin/python: No such file or directory

How can I change where bash looks for python? How is bash currently deciding that when I type python that it only looks in /usr/bin for python?

like image 317
James Scherer Avatar asked Apr 05 '11 01:04

James Scherer


People also ask

Where is Python path set in Linux?

Setting Path in Unix or Linux In the csh shell, type the following sentence: PATH “$PATH:/usr/local/bin/python” and press Enter. If you are using the standard flavour of Linux, open up the bash shell and type the following phrase, export PATH=”$PATH:/usr/local/bin/python” and press Enter.


1 Answers

Your PATH environment variable. It has a list of directories which bash searches (in the same order) when it's looking for an program to execute. Basically you want to put /usr/local/bin at the start of your PATH environment variable. Add the following to your ~/.bashrc file:

export PATH=/usr/local/bin:$PATH

You can have a look at the current setting by running the set command in bash.

Alternatively, you can simply rename /usr/bin/python to /usr/bin/python2.3 and create a symlink pointing to the new version, e.g.

ln -s /usr/local/bin/python /usr/bin/python
like image 53
bradley.ayers Avatar answered Sep 30 '22 21:09

bradley.ayers