How to Install Python 3 on Redhat Enterprise Linux 7.x ?
Python is available on most of the operating systems in the world. By default Redhat provides 2.7x version on Redhat Enterprise Linux 7.x. But the new development is mostly happening on Python 3.x version since 2.x is legacy. If you need python 3.x, then you need to install it using the Redhat software repository (if you have Redhat subscription) or you could use centos/fedora repository via epel . Let’s quickly walk through the python 3.x installation. We will also see how to make python 3.x available as default program.
Environment:
- Redhat Enterprise Linux 7.4
- Internet Connectivity.
- Exiting python version – 2.7
Enabling EPEL Repository:
1.Login to RHEL 7.x as root user .
2. Install latest epel-release package .
[root@uaans ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E '%{rhel}').noarch.rpm Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. epel-release-latest-7.noarch.rpm | 15 kB 00:00:00 Examining /var/tmp/yum-root-kpLZS_/epel-release-latest-7.noarch.rpm: epel-release-7-11.noarch Marking /var/tmp/yum-root-kpLZS_/epel-release-latest-7.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package epel-release.noarch 0:7-11 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: epel-release noarch 7-11 /epel-release-latest-7.noarch 24 k Transaction Summary =============================================================================== Install 1 Package Total size: 24 k Installed size: 24 k Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : epel-release-7-11.noarch 1/1 Verifying : epel-release-7-11.noarch 1/1 Installed: epel-release.noarch 0:7-11 Complete! [root@uaans ~]#
3. Install “ius-release” package from CentOS repository.
[root@uaans ~]# yum -y install https://repo.ius.io/ius-release-el7.rpm https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. ius-release.rpm | 8.1 kB 00:00:00 Examining /var/tmp/yum-root-kpLZS_/ius-release.rpm: ius-release-1.0-15.ius.centos7.noarch Marking /var/tmp/yum-root-kpLZS_/ius-release.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package ius-release.noarch 0:1.0-15.ius.centos7 will be installed --> Finished Dependency Resolution epel/x86_64/metalink | 5.8 kB 00:00:00 epel/x86_64 | 4.7 kB 00:00:00 epel/x86_64/group_gz | 84 kB 00:00:00 epel/x86_64/updateinfo | 924 kB 00:00:01 epel/x86_64/primary_db | 6.4 MB 00:00:03 Dependencies Resolved ================================================================================= Package Arch Version Repository Size ================================================================================= Installing: ius-release noarch 1.0-15.ius.centos7 /ius-release 8.5 k Transaction Summary ================================================================================= Install 1 Package Total size: 8.5 k Installed size: 8.5 k Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : ius-release-1.0-15.ius.centos7.noarch 1/1 Verifying : ius-release-1.0-15.ius.centos7.noarch 1/1 Installed: ius-release.noarch 0:1.0-15.ius.centos7 Complete! [root@uaans ~]#
Installing Python 3.x on RHEL 7.x :
1. Install python 3.6 version(Current Stable Release ) using yum command .
[root@uaans ~]# yum install -y python36u python36u-pip Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. ius | 2.3 kB 00:00:00 ius/x86_64/primary_db | 250 kB 00:00:03 Resolving Dependencies --> Running transaction check ---> Package python36u.x86_64 0:3.6.5-1.ius.centos7 will be installed --> Processing Dependency: python36u-libs(x86-64) = 3.6.5-1.ius.centos7 for package: python36u-3.6.5-1.ius.centos7.x86_64 --> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python36u-3.6.5-1.ius.centos7.x86_64 ---> Package python36u-pip.noarch 0:9.0.1-1.ius.centos7 will be installed --> Processing Dependency: python36u-setuptools for package: python36u-pip-9.0.1-1.ius.centos7.noarch --> Running transaction check ---> Package python36u-libs.x86_64 0:3.6.5-1.ius.centos7 will be installed ---> Package python36u-setuptools.noarch 0:39.0.1-1.ius.centos7 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================== Package Arch Version Repository Size =================================================================================== Installing: python36u x86_64 3.6.5-1.ius.centos7 ius 57 k python36u-pip noarch 9.0.1-1.ius.centos7 ius 1.8 M Installing for dependencies: python36u-libs x86_64 3.6.5-1.ius.centos7 ius 8.7 M python36u-setuptools noarch 39.0.1-1.ius.centos7 ius 642 k Transaction Summary ==================================================================================== Install 2 Packages (+2 Dependent packages) Total download size: 11 M Installed size: 52 M Downloading packages: warning: /var/cache/yum/x86_64/7Server/ius/packages/python36u-3.6.5-1.ius.centos7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 9cd4953f: NOKEYTA Public key for python36u-3.6.5-1.ius.centos7.x86_64.rpm is not installed (1/4): python36u-3.6.5-1.ius.centos7.x86_64.rpm | 57 kB 00:00:01 (2/4): python36u-setuptools-39.0.1-1.ius.centos7.noarch.rpm | 642 kB 00:00:05 (3/4): python36u-pip-9.0.1-1.ius.centos7.noarch.rpm | 1.8 MB 00:00:19 (4/4): python36u-libs-3.6.5-1.ius.centos7.x86_64.rpm | 8.7 MB 00:00:30 ----------------------------------------------------------------------------------------------------- Total 109 kB/s | 11 MB 00:01:44 Retrieving key from file:///etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY Importing GPG key 0x9CD4953F: Userid : "IUS Community Project <coredev@iuscommunity.org>" Fingerprint: 8b84 6e3a b3fe 6462 74e8 670f da22 1cdf 9cd4 953f Package : ius-release-1.0-15.ius.centos7.noarch (installed) From : /etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python36u-libs-3.6.5-1.ius.centos7.x86_64 1/4 Installing : python36u-3.6.5-1.ius.centos7.x86_64 2/4 Installing : python36u-setuptools-39.0.1-1.ius.centos7.noarch 3/4 Installing : python36u-pip-9.0.1-1.ius.centos7.noarch 4/4 Verifying : python36u-3.6.5-1.ius.centos7.x86_64 1/4 Verifying : python36u-pip-9.0.1-1.ius.centos7.noarch 2/4 Verifying : python36u-libs-3.6.5-1.ius.centos7.x86_64 3/4 Verifying : python36u-setuptools-39.0.1-1.ius.centos7.noarch 4/4 Installed: python36u.x86_64 0:3.6.5-1.ius.centos7 python36u-pip.noarch 0:9.0.1-1.ius.centos7 Dependency Installed: python36u-libs.x86_64 0:3.6.5-1.ius.centos7 python36u-setuptools.noarch 0:39.0.1-1.ius.centos7 Complete! [root@uaans ~]#
2. Identify the current python version and python path.
[root@uaans ~]# which python /usr/bin/python [root@uaans ~]# ls- lrt /usr/bin/python [root@uaans bin]# ls -lrt /usr/bin/python lrwxrwxrwx. 1 root root 7 May 5 05:28 /usr/bin/python -> python2 [root@uaans bin]# cd /usr/bin/ [root@uaans bin]# ls -lrt python* -rwxr-xr-x. 1 root root 7216 Feb 20 06:20 python2.7 -rwxr-xr-x. 2 root root 11312 Apr 10 15:11 python3.6m -rwxr-xr-x. 2 root root 11312 Apr 10 15:11 python3.6 lrwxrwxrwx. 1 root root 9 May 5 05:28 python2 -> python2.7 lrwxrwxrwx. 1 root root 7 May 5 05:28 python -> python2 [root@uaans bin]#
Here you could see that python is soft linked to python2 and python2 is soft linked to python 2.7 .
3. Let’s find out the command search path.
[root@uaans bin]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@uaans bin]#
Here you can see that “Commands” will be searched first in “/usr/local/sbin” and then it will search in “/usr/bin”.
4. Let’s create a soft link as python under “/usr/local/sbin” for python 3.6.
[root@uaans bin]# ln -s /usr/bin/python3.6 /usr/local/sbin/python
5.Execute “python” and check the version.
[root@uaans bin]# python -V Python 3.6.5 [root@uaans bin]#
We have made python 3.6 as default python program without removing or modifying the existing python’s soft link.
[root@uaans bin]# python -V Python 3.6.5 [root@uaans bin]# python2 -V Python 2.7.5 [root@uaans bin]# python3.6 -V Python 3.6.5 [root@uaans bin]#
Tidak ada komentar:
Posting Komentar