在vagrant中保存环境变量
Save environmental variables in vagrant
我通过 vagrant 安装了 CentOS7,当我 export $MYVAR=test
我可以成功 echo $MYVAR
。当我关闭 vagrant 会话并不得不重新登录时,问题就出现了,这个变量被擦除,我每次都必须重置它。
有解决办法吗?可能在 .vagrantfile
?
最简单的方法是在 ~/.profile
文件中添加导出行,这样当您开始新会话时它就始终可用
您可以尝试将以下内容添加到您的配置脚本中。
echo "export MYVAR=test" >> ~/.profile
在 Vagrantfile 上,它看起来像:
config.vm.provision "shell", inline: <<-SHELL
echo "export MYVAR=test" >> ~/.profile
SHELL
我通过 vagrant 安装了 CentOS7,当我 export $MYVAR=test
我可以成功 echo $MYVAR
。当我关闭 vagrant 会话并不得不重新登录时,问题就出现了,这个变量被擦除,我每次都必须重置它。
有解决办法吗?可能在 .vagrantfile
?
最简单的方法是在 ~/.profile
文件中添加导出行,这样当您开始新会话时它就始终可用
您可以尝试将以下内容添加到您的配置脚本中。
echo "export MYVAR=test" >> ~/.profile
在 Vagrantfile 上,它看起来像:
config.vm.provision "shell", inline: <<-SHELL
echo "export MYVAR=test" >> ~/.profile
SHELL