Vagrant - 未安装 Rails [英] Vagrant - Rails Not Installed

查看:48
本文介绍了Vagrant - 未安装 Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近不得不销毁并重新创建我的 Vagrant 实例.现在我无法运行任何 rails 命令,因为它说未安装 Rails.当我这样做

I recently had to destroy and recreate my Vagrant instance. Now I can't run any rails command as it says Rails is not installed. When I did

Vagrant Up

我收到以下错误

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

以下 SSH 命令以非零退出状态响应.Vagrant 假设这意味着命令失败!

The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed!

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

My Provision.sh file contains the following:

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.我试过这样做,但我不确定它是如何应用于流浪盒子的,无论如何我一定是做错了,因为它没有用.

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. 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.

是否需要更正/添加到我的 provision.sh 文件或 Vagrantfile 中?

Is there something I need to correct/add to my provision.sh file or to my Vagrantfile?

推荐答案

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

Vagrant runs the provisioning file as root, so you would have indeed installed rvm as root unless you specified otherwise*. 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.

*或者,您在通过 ssh 连接到机器时手动安装了 rvm,我将在下面详细介绍.

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

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

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.

我也感觉到有些概念上的误解.每次您执行vagrant destroy 时,您的整个 虚拟机都会被销毁,包括硬盘驱动器等等.下次您执行 vagrant up 时,一切都会从头开始重建.如果您使用 ssh 登录并安装了一些东西,它们将不再存在.

I also sense somewhat of a conceptual misunderstanding. Each time you do vagrant destroy your entire virtual machine is destroyed, hard drives and all. The next time you do vagrant up, everything is rebuilt from scratch. If you had ssh'd in and installed things, they'll no longer be there.

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

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.

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

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.

这篇关于Vagrant - 未安装 Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆