欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用vagrant创建统一的开发环境

程序员文章站 2022-03-03 19:05:13
...

一.安装vagrant和virtual box并下载ubuntu 12.04 32 bit镜像

# virtual box
https://www.virtualbox.org/wiki/Downloads
# vagrant
http://downloads.vagrantup.com/

# ubuntu 12.04 32 bit
http://files.vagrantup.com/precise32.box

 

二.初始化并安装rails环境

# 进入rails项目文件夹
# vagrant setup
vagrant box add rubywine ~/box/precise32.box
vagrant init rubywine
# edit Vagrantfile
config.vm.network :private_network, ip: "192.168.33.10"

vagrant up
vagrant ssh

# add /.vagrant and Vagrantfile to gitignore
sudo apt-get update
sudo apt-get install curl
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
source ~/.bash_profile
rvm -v
rvm install 2.1.3
rvm use 2.1.3 --default
ruby -v
gem -v
gem source -r https://rubygems.org/
gem source -a https://ruby.taobao.org

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
node -v

sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby libmysqlclient-dev

sudo apt-get install -y imagemagick
cd /vagrant/
gem install bundler
gem update --system
gem update
bundle install
rake db:create db:migrate db:seed
rails server
# visit http://192.168.33.10:3000/

exit
vagrant halt
vagrant package --vagrantfile Vagrantfile --output ~/box/rails.box

 

# 安装jdk7 via ppa
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

sudo apt-get install oracle-java7-set-default
java -version

 

# 安装 elasticsearch
# http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-repositories.html
# http://happycasts.github.io/ep/use-elasticsearch-with-rails/

wget -qO - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | sudo apt-key add -
sudo vim /etc/apt/sources.list
# deb http://packages.elasticsearch.org/elasticsearch/1.3/debian stable main

sudo apt-get update
sudo apt-get install elasticsearch
sudo service elasticsearch start
# 设置开发启动
sudo update-rc.d elasticsearch defaults 95 10

 

三.然后遇到问题了,我打包后队友怎么使用呢?

这里有两种方法

1.把 Vagrantfile加入到.gitignore,然后按照以下步骤初始化

vagrant box add rubywine ~/box/rails.box
vagrant init rubywine
# edit Vagrantfile
config.vm.network :private_network, ip: "192.168.33.10"

vagrant up
vagrant ssh

# add /.vagrant and Vagrantfile to gitignore

bundle install
rake db:create db:migrate db:seed
rails server
# visit http://192.168.33.10:3000/

 

2.不把 Vagrantfile加入到.gitignore里面,但是不使用vagrant init命令,因为vagrant init会自动生成一个

vagrant box add rubywine ~/box/rails.box
# edit Vagrantfile to set the config.vm.box = "rubywine" name to yours,here is rubymine
config.vm.box = "rubywine"

vagrant up
vagrant ssh

bundle install
rake db:create db:migrate db:seed
rails server
# visit http://192.168.33.10:3000/

 

四.其他命令

vagrant box list
vagrant box remove box_name

vagrant halt
vagrant destroy

 五.php

http://imcn.me/html/y2012/12401.html

 

 

相关标签: rails vagrant