The vast majority of Linux distribution has built-in Python installed. We only need to input python in the liunx command line, but the version is a bit low, not what we want, such:
1. Download Python
To begin:
There are two types of Linux platforms,
Python 2.7 compressed source tarball (for Linux, Unix or OS X)And
Python 2.7 bzipped source tarball (for Linux, Unix or OS X, more compressed)
The second type is better compression. in Linux, Bzip2 is used to compress a large number of files. The file name is generally * .tar.bz2,
However, in the second version above.
Download and install the source code file in Linux is generally used to put in/usr/local/src/. SRC is the abbreviation of source. Enter this directory and download it with wget:
In this way, we can download the desired Linux version to the local machine.
2. Extract
Run the tar command to decompress the downloaded package, for example:
3. Compile and install
In Linux, the software installed by the user is usually installed in/usr/local/XXX/. You can compile and install the software by using the configure, make, and make install commands, -- prefix specifies the target directory to be installed, as follows:
1 , Go to Python - 2 . 6 folder
2 ,. / Configure -- Prefix =/ USR / Local / Python - 2.6
3 , Make
4 , Make install
4. Check and set Environment Variables
After the installation is complete, we enter python in the Linux Command Line. The execution is still the 2.4 version that comes with the system. This is related to the environment variables of the system.
The/usr/bin/folder contains the following files: Python, python2, and pthon2.4, for example:
If we use the absolute path to execute the version 2.6 We just installed, we will run version 2.6, for example:
Switch to this directory, and you will find that there are Python files in the same directory as/usr/bin,
Use Path = "$ path":/usr/local/Python-2.6/bin to add the directory to the Linux environment variable, for example:
Now input python in the command line, and the system still runs version 2.4, because the system first finds python in/usr/bin/, but the input of python2.6 has already executed version 2.6, for example:
Delete the python file in/usr/bin/, and then create a symbolic link of 2.6 in the directory so that the system can execute the version 2.6 we want, as shown below:
1 , CD / USR / Bin /
2 , RM - RF Python
3 , Ln - S / USR / Local / Python - 2.6 / Bin / Python. / Python
Let's take a look at the files in the/usr/bin/directory. Input python to execute the installed version, for example: