一.安装rvm
sudo apt-get install curl curl -L https://get.rvm.io | bash -s stable source ~/.rvm/scripts/rvm rvm -v
二.安装ruby2.1.2(目前最新,也建议最新)
rvm install 2.1.2 rvm use --default 2.1.2 ruby -v gem -v
三.替换gem原为taobao
gem source -r https://rubygems.org/ gem source -a https://ruby.taobao.org
四.安装最新版rails(默认最新,建议最新)
gem install rails rails -v
五.安装nodejs最新版 via ppa
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
六.安装mysql(我的rails项目使用mysql)
netstat -tap |grep mysql#检查是否已经安装mysql sudo apt-get install mysql-server mysql-client sudo /etc/init.d/mysql start|stop|restart|reload|force-reload|status
七.安装sublime text3(编辑器)或者atom(编辑器) via ppa
#sublime text3 sudo add-apt-repository ppa:webupd8team/sublime-text-3 sudo apt-get update sudo apt-get install sublime-text-installer #remove sublime text3 sudo apt-get remove sublime-text-installer #atom /opt/atom/atom sudo add-apt-repository ppa:webupd8team/atom sudo apt-get update sudo apt-get install atom
八.安装nginx+passenger
#install passenger #参考:https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#install_on_debian_ubuntu sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7 sudo apt-get install apt-transport-https ca-certificates cd /etc/apt/sources.list.d sudo apt-get install vim sudo vim passenger.list ### to_add # Ubuntu 12.04 deb https://oss-binaries.phusionpassenger.com/apt/passenger precise main ### sudo chown root: /etc/apt/sources.list.d/passenger.list sudo chmod 600 /etc/apt/sources.list.d/passenger.list sudo apt-get update sudo apt-get install nginx-extras passenger
九.配置nginx+passenger
1.编辑/etc/nginx/nginx.conf,将
# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; # passenger_ruby /usr/bin/ruby;
改为(取消注释,修改passenger_ruby路径)
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;#默认即可 passenger_ruby /home/yang/.rvm/wrappers/default/ruby;#注意yang为你的用户名
sudo rm /etc/nginx/sites-enabled/default sudo touch /etc/nginx/sites-enabled/hackerblog.com.conf #add to /etc/nginx/sites-enabled/hackerblog.com.conf ### server { listen 80 default; server_name hackerblog.com; # 这里填写你真实域名 root /var/www/hackerblog/public; passenger_enabled on; } ### sudo service nginx restart
十.建立rails项目
rails new hackerblog --skip-bundle -d mysql
#如果遇到------程序“rails”尚未安装
#执行bash --login
cd hackerblog
bundle install
#如果遇到:An error occurred while installing mysql2,ubuntu12.04执行sudo apt-get install libmysql-ruby libmysqlclient-dev
# ubuntu14.04 sudo apt-get install libmysqlclient-dev
#rake db:create
#rake db:drop
#rake db:migrate
#rails s
#http://127.0.0.1:3000/
cp -R /home/yang/dev/ruby/rails/hackerblog /home/yang/www/hackerblog
cd /home/yang/www/hackerblog
RAILS_ENV=production rake db:create db:migrate
#注意部署环境mysql密码不能为空
rake assets:precompile
十一.修改mysql root密码(附加)