Skip to content

Instantly share code, notes, and snippets.

@vadirajks
Last active October 14, 2019 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vadirajks/c816d8bdcc73e72daeb1329b21a2a4d7 to your computer and use it in GitHub Desktop.
Save vadirajks/c816d8bdcc73e72daeb1329b21a2a4d7 to your computer and use it in GitHub Desktop.
python workaround
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
installing python 2.6 in RHEL7:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Install fpm
yum install ruby-devel gcc make rpm-build rubygems
gem install --no-ri --no-rdoc fpm
# Install prerequisite to compile Python
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
# Get Python 2.6
mkdir ~/build
cd ~/build
wget https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tgz
tar zxvf Python-2.6.9.tgz
# Compile Python 2.6
cd Python-2.6.9
./configure --prefix=/opt/python26 --enable-shared
make
# Instead of installing these files that we've configured on our system
# we will install them into an empty, dummy directory that we can build a real package out of
mkdir -p /tmp/project
make DESTDIR=/tmp/project install
# Create the rpm with fpm
fpm -s dir -t rpm -C /tmp/project --name python26 --version 2.6.9 --iteration 1 --description "Python 2.6 for RHEL7"
# Check your package and install...
rpm -qpi python26-2.6.9-1.x86_64.rpm
yum localinstall python26-2.6.9-1.x86_64.rpm
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
change from default to alternative Python
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@test70-10 ~]# ls /usr/bin/python* -l
lrwxrwxrwx 1 root root 24 Oct 14 12:48 /usr/bin/python -> /etc/alternatives/python
lrwxrwxrwx 1 root root 9 Oct 13 07:09 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 7048 Sep 13 20:29 /usr/bin/python2.7
-rwxr-xr-x 1 root root 1846 Sep 13 20:28 /usr/bin/python2.7-config
lrwxrwxrwx 1 root root 16 Oct 13 07:09 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root 9 Oct 14 12:34 /usr/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 7056 Oct 2 19:35 /usr/bin/python3.7
-rwxr-xr-x 2 root root 7056 Oct 2 19:35 /usr/bin/python3.7m
lrwxrwxrwx 1 root root 14 Oct 13 07:09 /usr/bin/python-config -> python2-config
[root@test70-10 ~]# python --version
Python 2.7.16
[root@test70-10 ~]# update-alternatives --display python
[root@test70-10 ~]# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
[root@test70-10 ~]# update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
[root@test70-10 ~]# update-alternatives --display python
python - status is auto.
link currently points to /usr/bin/python3.7
/usr/bin/python2.7 - priority 1
/usr/bin/python3.7 - priority 2
Current `best' version is /usr/bin/python3.7.
[root@test70-10 ~]# python --version
Python 3.7.4
[root@test70-10 ~]# update-alternatives --config python
There are 2 programs which provide 'python'.
Selection Command
-----------------------------------------------
1 /usr/bin/python2.7
*+ 2 /usr/bin/python3.7
In case we no longer have the alternative python version installed on our system we can remove its update-alternatives listing.
For example let's remove python2.7 version:
# update-alternatives --remove python /usr/bin/python2.7
update-alternatives: removing manually selected alternative - switching python to auto mode
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment