在 Vagrant Ubuntu 20.04 VM 上安装 pyenv
Install pyenv on a Vagrant Ubuntu 20.04 VM
我正在尝试在我的 vagrant 虚拟机上安装 pyenv
。
我的 Vagrantfile
看起来像这样:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.box_version = "20220517.0.0"
config.vm.provision :shell, path: "./provision/install-pyenv.sh", privileged: false
config.vm.provision :shell, path: "./provision/install-python.sh", privileged: false
end
其中 ./provision/install-pyenv.sh
是:
#!/usr/bin/env bash
# Install required dependencies
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
# Run the installer
curl https://pyenv.run | bash
# Add the required variables to the ~/.bashrc file
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc
而./provision/install-python.sh
是:
#!/usr/bin/env bash
# Install the required Python version
pyenv install -v 3.10.4
# Set the global python version
pyenv global 3.10.4
但是当我 运行 vagrant up
- 我得到以下错误:
pyenv
不是可识别的命令。
我究竟做错了什么?我是否将环境变量添加到不正确的 ~/.bashrc 中?
我真的不明白我哪里错了。
似乎实现此目的的最佳方法是以特权用户身份安装依赖项。
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.box_version = "20220517.0.0"
# Python
config.vm.provision :shell, path: "./provision/install-pyenv-dependencies.sh"
config.vm.provision :shell, privileged: false, path: "./provision/install-python.sh"
end
其中 install-pyenv-dependencies.sh
是:
#!/usr/bin/env bash
# Install required dependencies
apt-get update
apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl --fix-missing
而install-python.sh
,是:
#!/usr/bin/env bash
# Run the installer
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
# Update the bashrc file
cat >> ~/.bashrc <<'EOL'
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
EOL
# Export the env vars
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
# Use pyenv to install Python
pyenv install -v 3.10.4
pyenv global 3.10.4
我正在尝试在我的 vagrant 虚拟机上安装 pyenv
。
我的 Vagrantfile
看起来像这样:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.box_version = "20220517.0.0"
config.vm.provision :shell, path: "./provision/install-pyenv.sh", privileged: false
config.vm.provision :shell, path: "./provision/install-python.sh", privileged: false
end
其中 ./provision/install-pyenv.sh
是:
#!/usr/bin/env bash
# Install required dependencies
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
# Run the installer
curl https://pyenv.run | bash
# Add the required variables to the ~/.bashrc file
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc
而./provision/install-python.sh
是:
#!/usr/bin/env bash
# Install the required Python version
pyenv install -v 3.10.4
# Set the global python version
pyenv global 3.10.4
但是当我 运行 vagrant up
- 我得到以下错误:
pyenv
不是可识别的命令。
我究竟做错了什么?我是否将环境变量添加到不正确的 ~/.bashrc 中?
我真的不明白我哪里错了。
似乎实现此目的的最佳方法是以特权用户身份安装依赖项。
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.box_version = "20220517.0.0"
# Python
config.vm.provision :shell, path: "./provision/install-pyenv-dependencies.sh"
config.vm.provision :shell, privileged: false, path: "./provision/install-python.sh"
end
其中 install-pyenv-dependencies.sh
是:
#!/usr/bin/env bash
# Install required dependencies
apt-get update
apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl --fix-missing
而install-python.sh
,是:
#!/usr/bin/env bash
# Run the installer
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
# Update the bashrc file
cat >> ~/.bashrc <<'EOL'
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
EOL
# Export the env vars
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
# Use pyenv to install Python
pyenv install -v 3.10.4
pyenv global 3.10.4