8

On my Fedora11 machine which has python2.6 pre-installed on it, I was able to successfully install python 2.7 using the following steps:

wget http://www.python.org/ftp/python/2.7/Python-2.7.tar.bz2
tar -xvjf Python-2.7.tar.bz2
cd Python*
./configure --prefix=/opt/python27
make
make install
vi ~/.bash_profile
## replaced PATH=$PATH:$HOME/bin
## with PATH=$PATH:$HOME/bin:/opt/python27/bin

## reload .bash_profile
source ~/.bash_profile
echo "/opt/python27/lib" > /etc/ld.so.conf.d/python27.conf
ldconfig

However, when I checked the python version the system uses via terminal (python -V), it still shows python 2.6.

How will I make the system use python2.7 as its default python? Or if possible, how will I uninstall python2.6?

Thanks in advance!

jaysonpryde
  • 2,733
  • 11
  • 44
  • 61
  • 3
    It's generally a bad idea to try to remove the system python on linux machines. Just put /opt ahead of /usr/bin in your PATH and you can use 2.7 yourself without messing up anything. – Wooble May 23 '12 at 16:56

5 Answers5

11

Uninstalling the system Python is a bad idea. There are many other packages and softwares that depend on it. It'll be better that you use python2.7 by either modifying the $PATH or creating an alias e.g. python2.7 that points to the python that you installed in /opt dir.

Ramashish Baranwal
  • 7,166
  • 2
  • 18
  • 14
  • Thanks for the feedback. My knowledge in linux is not that advanced so can you tell me the steps on creating alias? I already modified the $PATH on ~/.bash_profile but still it says 2.6 as the version of python – jaysonpryde May 23 '12 at 17:17
  • apologies, but can you help me out on the alias thing you've mentioned? thanks – jaysonpryde May 24 '12 at 04:50
  • Assuming your python 2.7 executable is present in /opt/python27, you can create an alias by- $ alias python2.7="/opt/python27/python" – Ramashish Baranwal May 27 '12 at 08:04
4

Uninstalling fedora-provided python 2.6 might break many packages that depend on it. I advise you against doing it.

Now, your problem is simply that $PATH and similar variables ($MAN_PATH etc.) are searched from left to right. You appended your new /opt/python27/bin after standard locations like /usr/bin. Reverse the order, and you will get /opt/python27/bin/python as a default python binary.

Tadeusz A. Kadłubowski
  • 8,047
  • 1
  • 30
  • 37
  • Thanks for the feedback. I already reversed the order as suggested but still the version displayed is 2.6. Are there other config files aside from ~/.bash_profile that I need to edit? – jaysonpryde May 23 '12 at 17:15
  • @jaysonpryde: Did you restart your shell after modifying `.bash_profile`? – Tadeusz A. Kadłubowski May 23 '12 at 18:09
  • Yes I did.... additional information. I am logged in as a different user (not root). But when I installed python2.7, I switched to root first (i.e. su) – jaysonpryde May 23 '12 at 18:19
2

First of all - never ever try to uninstall Python on RHEL/CentOS/Fedora. yum is written in Python and there will be many problems with repairing the system.

If you want the system to use Python2.7 by default, find where the Python2.6 (use whereis python or which python commands) binary is located, backup it and replace with the binary of Python2.7

mega.venik
  • 648
  • 6
  • 13
0

Instead of uninstall older version, use specific version of python while using it

I changed symbolic link

ln -s /usr/local/bin/python2.7 /usr/local/bin/python

And used

python -m pip install pip --upgrade
Bùi Đức Khánh
  • 3,975
  • 6
  • 27
  • 43
-6

Or you can simply use Yum feature of linux & run command yum remove python it will delete python & related dependencies from the system

Vikas Gupta
  • 4,455
  • 1
  • 20
  • 40
  • 4
    yum remove python will (if you include dependencies) practically wipe your whole system since a large part system utilities is written in python. You do NOT wish to do that – Tadej Magajna Apr 15 '17 at 19:57
  • http://www.keepcalmstudio.com/gallery/poster/1BLAEVH lol, I did that once and I made money $x – AKS Mar 13 '19 at 23:06