Ubuntu 自动安装部署 Rails 环境

你需要经常安装部署 Rails 到新的 Web 服务器吗?

你是否还在经历每次从安装 Ruby Rubygems MySQL… 再到安装 Web Server 组件… 反复烦躁的安装流程呢?

现在你可以改用这个脚本实现在 Ubuntu Server 上面部署 Ruby1.8 + Rails + Passenger + Nginx 的环境:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
echo "=== YTRIPTHIRD UBUNTU INSTALL ==="
cd /tmp

# Ruby
echo "=== Install Ruby library..."
sudo apt-get install g++ ruby1.8 rubygems rake irb ruby1.8-dev build-essential libopenssl-ruby imagemagick rmagick
echo "=== Ruby library install done."
echo ""

# MySQL Server
echo -n "Do you wan't install MySQL automatic[y/n]:"
read KEY
case $KEY in
y|Y)
  echo "=== Install MySQL server..."
  sudo apt-get install mysql-server mysql
  ;;
esac
sudo apt-get install libmysqlclient-dev
echo "=== MySQL install done."
echo ""


# Rubygems
echo -n "Do you wan't install Rubygems?[y/n]:"
read KEY
case $KEY in
y|Y)
  echo "=== Install Rubygems from source file..."
  wget http://rubyforge.org/frs/download.php/60719/rubygems-1.3.5.zip
  unzip rubygems-1.3.5.zip
  cd rubygems-1.3.5
  sudo ruby setup.rb
  sudo gem sources -a http://gems.github.com
  cd ..
  sudo rm -R /tmp/rubygems-1.3.5
  echo "=== Rubygems install done."
  ;;
esac
echo ""


# Install Rails
echo -n "Do you wan't install Rails?[y/n]"
read KEY
case $KEY in
y|Y)
  echo "=== Install Rails and some Gems..."
  sudo gem install rails passenger --no-rdoc
  echo "=== Rails install done."
  ;;
esac
echo ""

# Install Web server
echo "=== Install Web Server"
wget http://sysoev.ru/nginx/nginx-0.7.64.tar.gz
tar zxf nginx-0.7.64.tar.gz
echo ""
echo "===*** Nginx install Warring! ***==="
echo "   *** nginx source path: /tmp/nginx-0.7.64 "
echo "   *** must be install nginx in: /etc/nginx "
echo ""
sudo passenger-install-nginx-module
echo "=== Web Server install done."
echo ""

此脚本一在 Ubuntu Server 9.04 版本上面测试通过,不过可能有些时候需要对这个脚本做一些微调后方可适应你的环境,如 Ruby 的版本、Rails 的版本…

或者你不想用 Passenger + Nginx 来部署你的 Rails App,也可以修改 Install Web Server 这段。

或者还可以在 第一段批处理的地方加入更多的类库安装….

总之,本脚本是给你一个参考例子,以后部署 Rails App 别再手动安装了,把你的安装过程整理到 Shell 脚本中去,然后: `$ sh install-ubuntu.sh`

搞定所有流程,方便省事,又不用每次部署的时候反复的在 Google 上面查资料!