Vagrant 配置命令不会将别名添加到 ~/.profile

Vagrant provisioning command does not add aliases to ~/.profile

我有一个相当普通的 Vagrant 设置 运行 trusty64。它由单个 shell 文件配置。其中,它包含 python3pythonpip3pip 的别名,分别为:

echo "Writing aliases to profile:"
echo "alias python=\"python3\"" >> ~/.profile
echo "alias pip=pip3" >> ~/.profile
. ~/.profile

出于某种神秘原因,这些行从未进入 ~/.profile。没有错误消息,也没有任何其他骚动,只是什么也没发生。现在是凌晨 2 点,我很确定我做错了什么,我只是不知道它是什么。

我很确定你正在用类似

的方式调用配置器
config.vm.provision "shell", path: "bootstrap.sh"

这很好用,但它是作为 root 用户执行的,所以所有的行都是为这个用户添加的。您要使用 privileged 选项

privileged (boolean) - Specifies whether to execute the shell script as a privileged user or not (sudo). By default this is "true".

config.vm.provision "shell", path: "bootstrap.sh", privileged: "false"

将作为您的 vagrant 用户执行并将行添加到 /home/vagrant/.profile 文件