如何通过Vagrant/VirtualBox安装Ruby和Rails?版本不符求助
Ruby和Rails指定版本安装失败排查求助
尝试手动安装Ruby一周未果,改用Vagrant搭配VirtualBox的ubuntu/trusty64镜像,通过bootstrap.sh和Vagrantfile实现自动化安装。但明明配置了指定版本,却始终无法安装正确的Ruby和Rails版本。执行vagrant up、vagrant ssh后,在终端输入ruby -v和rails -v,结果与预期不符(附截图)。
以下是我的bootstrap.sh和Vagrantfile文件:
bootstrap.sh
#!/usr/bin/env bash # 升级系统 echo upgrading and updating the system sudo apt-get update sudo apt-get -y upgrade # 安装node.js作为Rails的JS运行时及git echo installing nodejs for ExecJS runtime and git sudo apt-get install -y nodejs sudo apt-get install -y git # 安装RVM echo installing RVM gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \curl -sSL https://get.rvm.io | bash -s stable source /home/vagrant/.rvm/scripts/rvm rvm requirements # 安装Ruby 2.3.1并设为默认版本 echo installing ruby rvm install 2.3.1 rvm use 2.3.1 --default # 安装Bundler和Rails 4.2.7 echo installing bundler and rails gem install bundler --no-ri --no-rdoc gem install rails -v 4.2.7 --no-ri --no-rdoc # 安装PostgreSQL及依赖 echo installing psql and its dependencies sudo apt-get install -y postgresql postgresql-contrib libpq-dev
Vagrantfile
Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" config.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: "127.0.0.1" config.vm.provision :shell, path: "bootstrap.sh", privileged: false config.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--memory", "2048"] vb.customize ["modifyvm", :id, "--cpus", "2"] end end
内容的提问来源于stack exchange,提问作者Keith Coye
相关产品推荐
相关产品推荐

