[英]Set python 3 as default python version in CentOS
I have installed python 3.6 on my CentOS machine by following the guide at https://linuxize.com/post/how-to-install-python-3-on-centos-7/ , which installs python 3 with the following: I have installed python 3.6 on my CentOS machine by following the guide at https://linuxize.com/post/how-to-install-python-3-on-centos-7/ , which installs python 3 with the following:
sudo yum install rh-python36
The default python version, however, is still python 2. The guide mentions I can run python 3 by first running scl enable rh-python36 bash
, and then python 3 will be used. The default python version, however, is still python 2. The guide mentions I can run python 3 by first running scl enable rh-python36 bash
, and then python 3 will be used. However, this only works for that session - logging out and back in will revert back to python 2. According to How to set Python3.5.2 as default Python version on CentOS? However, this only works for that session - logging out and back in will revert back to python 2. According to How to set Python3.5.2 as default Python version on CentOS? , python 3 can be set as the default with the following: , python 3 可以设置为默认值,如下:
sudo ln -fs /usr/bin/python3 /usr/bin/python
However, this doesn't work for me as for some reason I don't have any python3 file in /usr/bin/
- I only have python
, python2
, python2.7
, python2.7-config
, python2-config
and python-config
(despite installing python 3 with yum as above).但是,这对我不起作用,因为由于某种原因,我在/usr/bin/
中没有任何 python3 文件 - 我只有python
、 python2
、 python2.7
、 python2.7-config
、 python2-config
和python-config
(尽管安装了 python 3 和 yum 如上所述)。
First, run第一次运行
$ scl enable rh-python36 bash
to switch python version.切换 python 版本。
Second, run二、运行
$ which python
to find out the exact path of python3.6 binary.找出 python3.6 二进制文件的确切路径。
Third, edit ~/.bashrc.第三,编辑~/.bashrc。
$ vim ~/.bashrc
and add below line.并添加以下行。
alias python='/opt....(the path you found by "which python")'
and save the file.并保存文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.