流浪者-未安装轨道



我最近不得不销毁并重新创建我的Vagrant实例。现在我不能运行任何rails命令,因为它说rails没有安装。当我做时

Vagrant Up

我得到以下错误

default: /tmp/vagrant-shell: line 1: /home/vagrant/.rvm/scripts/rvm: No such file or directory

以下SSH命令以非零退出状态响应。Vagrant认为这意味着命令失败了!

我的Provision.sh文件包含以下内容:

echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main "     | sudo tee -a /etc/apt/sources.list.d/pgdg.list
sudo wget --quiet -O -     https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get remove postgresql-client-9.1 postgresql-client-common         postgresql-client postgresql-common -y
sudo apt-get install postgresql-9.3 postgresql-client-9.3 libpq-dev     curl git build-essential libxslt-dev libxml2-dev -y
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
curl -sSL https://get.rvm.io | bash -s stable --ruby
cat << EOF | sudo tee -a /home/vagrant/.bashrc
cd /vagrant
EOF
echo '# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust'     | sudo tee /etc/postgresql/9.3/main/pg_hba.conf
echo 'machine api.heroku.com
  login *****
  password ****
machine code.heroku.com
  login *****
  password *****
' | tee /home/vagrant/.netrc

echo 'ssh-rsa ***** vagrant@precise32
' | tee /home/vagrant/.ssh/id_*****.pub
chmod 0600 /home/vagrant/.netrc
sudo -u postgres psql -c "create user ***** createdb createuser     password '*****';"
    sudo /etc/init.d/postgresql restart

我看到了一些答案(不是针对Vagrant的),表明我一定是使用sudo或root安装了rvm,需要删除它,然后再次获得rvm。我试过这样做,但我不确定它如何适用于流浪箱,无论如何,我一定做错了,因为它没有起作用。

我需要更正/添加到provision.sh文件或我的Vagrant文件中吗?

Vagrant以root身份运行配置文件,因此除非另有指定,否则您确实会以root身份安装rvm。*。这对我来说也很困惑(也是一个新手),我会在供应期间安装一些东西,它们会"消失"。事实上,它们都被安装/设置为root用户。

*或者,当ssh进入机器时,您手动安装了rvm,我将在下面详细介绍

您可以使用su -c "source /home/vagrant/myapp/vagrant/user-config.sh" vagrant切换用户

"中的内容是要执行的任何命令。在这种情况下,我们将切换到一个单独的shell文件user-config.sh,该文件包含所有不应以root身份运行的命令,例如安装RVM。

我也感觉到某种概念上的误解。每次执行vagrant destroy时,整个虚拟机、硬盘驱动器等都会被销毁。下次执行vagrant up时,一切都将从头开始重建。如果您已经安装了ssh,那么它们将不再存在。

这意味着所有的安装和配置都会进入到配置文件中,并且不应该在事后手动安装。您应该可以随时使用vagrant destroy

通读一遍https://coderwall.com/p/uzkokw/configure-the-vagrant-login-user-during-provisioning-using-the-shell-provider再一次,我希望这一次更有意义。

最新更新