After downloading the installation package (eg: Python-3.5.1.tgz), upload it to the server and start preparing for installation
1) Release the file:
tar -xvzf Python-3.5.1.tgz
2) Enter the directory:
cd Python-3.5.1/
3) add configuration:
./configure --prefix=/usr/python
configure your own installation directory here
4) Next, compile the source code and execute the installation:
make
The whole process of make install
takes about 5-10 minutes. After the installation is successful, the installation directory is in /usr/python
5) The original python in the system is in /usr/bin/python. You can see through ls -l that python is a soft link that links to python2.6 in this directory
We can delete this, or create a new python3 soft link, but when executing, python should be changed to python3, or the python script header declaration should be changed to #!/usr/bin/python3
For convenience, it is recommended to rename it first, and then create a soft link. The previous program header does not need to be changed:
$ mv /usr/bin/python /usr/bin/python.bak
$ ln -s /usr/python/bin/python3 /usr/bin/python
This is established, and then executing the python command directly is equivalent to calling python3, in fact python3 is also a soft link, linking to python3.5.1, this multiple link does not affect, mainly for the convenience of version upgrade, no need to change the version number
or modify it as follows
$ ln -s /usr/python/bin/python3 /usr/bin/ python3 (python should be changed to python3 during execution, or python script header declaration should be changed to #!/usr/bin/python3)
This is the installation of the new version of python3, no need to uninstall the old version, the new version is also used normally