先创建好一个普通用户python,用于安装pyenv,pyenv仅在python用户的环境下有效,root用户下无法使用。
1、切换至普通用户
su python
2、下载离线包
#pyenv主程序包
wget https://github.com/pyenv/pyenv/archive/refs/tags/v2.1.0.tar.gz
#pyenv-virtualenv虚拟环境扩展包
wget https://github.com/pyenv/pyenv-virtualenv/archive/refs/heads/master.zip
# pyenv-update升级包
wget https://github.com/pyenv/pyenv-update/archive/refs/heads/master.zip
#pyenv-version-ext版本控制包
wget https://github.com/pyenv/pyenv-version-ext/archive/refs/heads/master.zip
#pyenv-installer安装pyenv的包
wget https://github.com/pyenv/pyenv-installer/archive/refs/heads/master.zip
#pyenv-doctor配合docker容器使用的包
https://github.com/pyenv/pyenv-doctor/archive/refs/heads/master.zip
3、主程序包解压到/home/python/.pyenv下,以pyenv2.1.0版本为例。
tar -zxf pyenv-2.1.0.tar.gz
mv pyenv-2.1.0 /home/python/.pyenv
4、扩展及升级包依次解压至主程序包的plugins目录下
unzip pyenv-doctor-master.zip
mv pyenv-doctor-master /home/python/.pyenv/plugins/
unzip pyenv-installer-master.zip
mv pyenv-installer-master /home/python/.pyenv/plugins/
unzip pyenv-update-master.zip
mv pyenv-update-master /home/python/.pyenv/plugins/
unzip pyenv-version-ext-master.zip
mv pyenv-version-ext-master /home/python/.pyenv/plugins/
unzip pyenv-virtualenv-master.zip
mv pyenv-virtualenv-master /home/python/.pyenv/plugins/
5、配置环境变量
echo 'export PYENV_ROOT="/home/python/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
source ~/.bash_profile
6、更新
cd /home/python/.pyenv
pyenv update
7、查看可安装的python版本,不支持的没法安装
pyenv install -l