简体   繁体   English

无业游民-未安装Rails

[英]Vagrant - Rails Not Installed

I recently had to destroy and recreate my Vagrant instance. 最近,我不得不销毁并重新创建我的Vagrant实例。 Now I can't run any rails command as it says Rails is not installed. 现在我无法运行任何rails命令,因为它说未安装Rails。 When I did 当我做的时候

Vagrant Up

I got the following error 我收到以下错误

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

The following SSH command responded with a non-zero exit status. 以下SSH命令以非零退出状态响应。 Vagrant assumes that this means the command failed! Vagrant认为这意味着命令失败!

My Provision.sh file contains the following: 我的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

I have seen some answers (not specific to Vagrant) suggesting that I must have installed rvm using sudo or as root and need to remove it and then get rvm again. 我已经看到一些答案(并非特定于Vagrant),提示我必须已经使用sudo或以root身份安装了rvm,并且需要将其删除然后再次获取rvm。 I have tried to do that butI'm not sure how it applies to a vagrant box and at any rate I must have done it wrong as it hasn't worked. 我已经尝试过这样做,但是我不确定它如何应用于无业游民的盒子,无论如何我肯定做错了,因为它没有用。

Is there something I need to correct/add to my provision.sh file or to my Vagrantfile? 我需要更正/添加到我的Provision.sh文件或Vagrantfile中吗?

Vagrant runs the provisioning file as root, so you would have indeed installed rvm as root unless you specified otherwise* . Vagrant以root身份运行预配文件,因此除非您另外指定*,否则您确实会以root身份安装rvm This was quite confusing for me as well (also a newbie), I would install things during provisioning and they would "disappear". 这对我(也是一个新手)也很困惑,我会在预配过程中安装东西,然后它们“消失”。 In fact, they were all being installed / set as root. 实际上,它们都是以root身份安装/设置的。

*Or, you manually installed rvm when ssh'd into the machine, which I'll touch on more below. *或者,您在将ssh插入机器时手动安装了rvm,我将在下面详细介绍。

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

What goes in the "" is any command you want to execute. “”中包含您要执行的任何命令。 In this case, we're switching to a separate shell file user-config.sh that contains all the commands that should not be run as root, such as installing RVM. 在这种情况下,我们将切换到一个单独的shell文件user-config.sh ,其中包含所有不应该以root身份运行的命令,例如安装RVM。

I also sense somewhat of a conceptual misunderstanding. 我也感觉到一些概念上的误解。 Each time you do vagrant destroy your entire virtual machine is destroyed, hard drives and all. 每次您vagrant destroy您的整个虚拟机,硬盘和所有设备时,都会被破坏。 The next time you do vagrant up , everything is rebuilt from scratch. 下次您vagrant up ,一切都会从头开始重建。 If you had ssh'd in and installed things, they'll no longer be there. 如果您已经安装并安装了东西,它们将不再在那里。

This means that all of your install and config goes into the provisioning file, and you shouldn't be installing things manually after the fact. 这意味着您所有的安装和配置都将进入预配置文件,并且事后您不应该手动进行安装。 You should be able to vagrant destroy any time you want. 您应该可以随时随地vagrant destroy

Take a read through https://coderwall.com/p/uzkokw/configure-the-vagrant-login-user-during-provisioning-using-the-shell-provider once more, I'm hoping it makes more sense this time around. 再次阅读https://coderwall.com/p/uzkokw/configure-the-vagrant-login-user-during-provisioning-using-the-shell-provider ,我希望这次更有意义周围。

May be this link helps you to install rvm using Vagrant. 可能是此链接可帮助您使用Vagrant安装rvm。

RVM_Vagrant RVM_Vagrant

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM