去年双十一阿里云活动,廉价买了台ECS一直闲着没用,实在是资源浪费。突然想装个Jupyter Notebook,方便对机器的使用,希望能调动积极性。一看python的版本信息,居然是2.7.12的,所以第一步先把Python升级到Python3再说。
1. 查看Python版本
root@iZuf6e9bjg74ll9e9hcyagZ:~# python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
2. 下载Python3代码包
root@iZuf6e9bjg74ll9e9hcyagZ:~# pwd
/root
root@iZuf6e9bjg74ll9e9hcyagZ:~# mkdir python
root@iZuf6e9bjg74ll9e9hcyagZ:~# ls
anaconda python
root@iZuf6e9bjg74ll9e9hcyagZ:~# cd python/
root@iZuf6e9bjg74ll9e9hcyagZ:~/python# ls
root@iZuf6e9bjg74ll9e9hcyagZ:~/python# wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz
3. 解压代码包
root@iZuf6e9bjg74ll9e9hcyagZ:~# ls
anaconda python scrapyd_supervisor.conf
root@iZuf6e9bjg74ll9e9hcyagZ:~# cd python/
root@iZuf6e9bjg74ll9e9hcyagZ:~/python# ls
Python-3.5.0.tar.xz
root@iZuf6e9bjg74ll9e9hcyagZ:~/python# tar -xf Python-3.5.0.tar.xz
4. 编译安装
root@iZuf6e9bjg74ll9e9hcyagZ:~/python# pwd
/root/python
root@iZuf6e9bjg74ll9e9hcyagZ:~/python# ls
Python-3.5.0 Python-3.5.0.tar.xz
root@iZuf6e9bjg74ll9e9hcyagZ:~/python# cd Python-3.5.0/
root@iZuf6e9bjg74ll9e9hcyagZ:~/python/Python-3.5.0# ./configure --prefix=/usr/local/python3
root@iZuf6e9bjg74ll9e9hcyagZ:~/python/Python-3.5.0# make && make install
5. 备份Python2
root@iZuf6e9bjg74ll9e9hcyagZ:~/python/Python-3.5.0# mv /usr/bin/python /usr/bin/python_2.7.12
6. 软链Python3
root@iZuf6e9bjg74ll9e9hcyagZ:/usr/local/python3/bin# ln -sv /usr/local/python3/bin/python3.5 /usr/bin/python
7. 验证升级
root@iZuf6e9bjg74ll9e9hcyagZ:/usr/local/python3/bin# python
Python 3.5.0 (default, Jun 9 2018, 09:16:24)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
8. 升级成功