#准备工作,更新源,安装依赖包等
sudo apt-get update sudo apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common git clone git://github.com/sstephenson/rbenv.git .rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc exec $SHELL
#ruby 2.3.5版本安装
最好找一个网络较快的地方,此过程要等个十几分钟
rbenv install 2.3.5
rbenv global 2.3.5
将gem源换成国内的,加快安装gem的速度
gem sources -l #查看当前gem源
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
gem sources -l
#安装rails 4.2.1版本
gem install rails -v 4.2.1
rbenv rehash
#查看rails的安装版本
rails -v
#安装mysql数据库
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
#将项目放在vagrant与本地的共享文件夹,我的电脑是rails_va,cd进入项目目录,启动项目
rails s
#可能会出现错误
/home/vagrant/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.16.3/lib/bundler/runtime.rb:84:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
#解决方式
sudo apt-get install -y nodejs
我们曾经在rails-va/Vagrantfile文件中设置过这个语句
config.vm.network "private_network", ip: "192.168.33.10"
在我们之前在本地浏览器上输入192.168.33.10:3000,就能打开虚拟机上的http://localhost:3000地址,将ruby on rails项目在本地进行调试