[英]Install pyenv on a Vagrant Ubuntu 20.04 VM
I am trying to install pyenv
on my vagrant vm.我正在尝试在我的 vagrant 虚拟机上安装
pyenv
。
My Vagrantfile
looks like this:我的
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
Where ./provision/install-pyenv.sh
is: ./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
And ./provision/install-python.sh
is: ./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
But when I run vagrant up
- I get the following error:但是当我运行
vagrant up
- 我收到以下错误:
pyenv
is not a recognised command. pyenv
不是公认的命令。 What am I doing wrong?我究竟做错了什么? Am I adding the env vars to the incorrect ~/.bashrc?
我是否将环境变量添加到不正确的 ~/.bashrc 中?
I don't really understand where I'm going wrong with this.我真的不明白我哪里出了问题。
Seems the best way to achieve this was to install the dependencies as a privileged user.似乎实现此目的的最佳方法是以特权用户身份安装依赖项。
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
Where install-pyenv-dependencies.sh
is:其中
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
And install-python.sh
, is:而
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.